mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Implemented a temporary but functional way to show passes of the selected satellites on the WorldMap
This commit is contained in:
1 parent
beda26ac99
commit
d0c7dd62e8
2 files changed
+64
-57
No files matched your search
@@ -43,7 +43,8 @@ class RadarFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
|
mainActivity = activity as MainActivity
|
||||||
|
viewModel = ViewModelProvider(mainActivity).get(MainViewModel::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@@ -58,7 +59,6 @@ class RadarFragment : Fragment() {
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val delay = viewModel.updateFreq
|
val delay = viewModel.updateFreq
|
||||||
satPass = arguments?.get("satPass") as SatPass
|
satPass = arguments?.get("satPass") as SatPass
|
||||||
mainActivity = activity as MainActivity
|
|
||||||
mainActivity.supportActionBar?.title = satPass.tle.name
|
mainActivity.supportActionBar?.title = satPass.tle.name
|
||||||
|
|
||||||
radarSkyFrame = view.findViewById(R.id.radar_sky_frame)
|
radarSkyFrame = view.findViewById(R.id.radar_sky_frame)
|
||||||
@@ -71,7 +71,7 @@ class RadarFragment : Fragment() {
|
|||||||
|
|
||||||
radarView = RadarView(mainActivity, delay)
|
radarView = RadarView(mainActivity, delay)
|
||||||
radarSkyFrame.addView(radarView)
|
radarSkyFrame.addView(radarView)
|
||||||
service.scheduleAtFixedRate({ radarView.invalidate() }, 0, delay, TimeUnit.MILLISECONDS)
|
service.scheduleAtFixedRate({ radarView.invalidate() }, delay, delay, TimeUnit.MILLISECONDS)
|
||||||
|
|
||||||
setupTransRecycler()
|
setupTransRecycler()
|
||||||
}
|
}
|
||||||
@@ -116,24 +116,24 @@ class RadarFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
private val radarPaint = Paint().apply {
|
private val radarPaint = Paint().apply {
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
color = resources.getColor(R.color.lightOnDark, (activity as MainActivity).theme)
|
color = resources.getColor(R.color.lightOnDark, mainActivity.theme)
|
||||||
style = Paint.Style.STROKE
|
style = Paint.Style.STROKE
|
||||||
strokeWidth = scale
|
strokeWidth = scale
|
||||||
}
|
}
|
||||||
private val txtPaint = Paint().apply {
|
private val txtPaint = Paint().apply {
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
color = resources.getColor(R.color.themeAccent, (activity as MainActivity).theme)
|
color = resources.getColor(R.color.themeAccent, mainActivity.theme)
|
||||||
textSize = txtSize
|
textSize = txtSize
|
||||||
}
|
}
|
||||||
private val trackPaint = Paint().apply {
|
private val trackPaint = Paint().apply {
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
color = resources.getColor(R.color.satTrack, (activity as MainActivity).theme)
|
color = resources.getColor(R.color.satTrack, mainActivity.theme)
|
||||||
style = Paint.Style.STROKE
|
style = Paint.Style.STROKE
|
||||||
strokeWidth = scale
|
strokeWidth = scale
|
||||||
}
|
}
|
||||||
private val satPaint = Paint().apply {
|
private val satPaint = Paint().apply {
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
color = resources.getColor(R.color.themeAccent, (activity as MainActivity).theme)
|
color = resources.getColor(R.color.themeAccent, mainActivity.theme)
|
||||||
style = Paint.Style.FILL
|
style = Paint.Style.FILL
|
||||||
}
|
}
|
||||||
private val path: Path = Path()
|
private val path: Path = Path()
|
||||||
|
|||||||
@@ -10,12 +10,15 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.github.amsacode.predict4java.PassPredictor
|
import com.github.amsacode.predict4java.PassPredictor
|
||||||
import com.github.amsacode.predict4java.Position
|
import com.github.amsacode.predict4java.Position
|
||||||
import com.github.amsacode.predict4java.SatPos
|
import com.github.amsacode.predict4java.SatPos
|
||||||
import com.github.amsacode.predict4java.TLE
|
import com.github.amsacode.predict4java.TLE
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import com.rtbishop.lookingsat.MainViewModel
|
import com.rtbishop.lookingsat.MainViewModel
|
||||||
import com.rtbishop.lookingsat.R
|
import com.rtbishop.lookingsat.R
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -31,13 +34,16 @@ class WorldMapFragment : Fragment() {
|
|||||||
private lateinit var viewModel: MainViewModel
|
private lateinit var viewModel: MainViewModel
|
||||||
private lateinit var trackView: TrackView
|
private lateinit var trackView: TrackView
|
||||||
private lateinit var mapFrame: FrameLayout
|
private lateinit var mapFrame: FrameLayout
|
||||||
// private lateinit var fab: FloatingActionButton
|
private lateinit var fab: FloatingActionButton
|
||||||
private lateinit var selectedSat: TLE
|
|
||||||
private lateinit var predictor: PassPredictor
|
private lateinit var predictor: PassPredictor
|
||||||
|
private lateinit var mainActivity: MainActivity
|
||||||
|
private lateinit var selectedSat: TLE
|
||||||
|
private var checkedItem = 0
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
|
mainActivity = activity as MainActivity
|
||||||
|
viewModel = ViewModelProvider(mainActivity).get(MainViewModel::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@@ -50,70 +56,71 @@ class WorldMapFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
mapFrame = view.findViewById(R.id.worldmap_frame)
|
|
||||||
// fab = view.findViewById(R.id.worldmap_fab)
|
|
||||||
// fab.setOnClickListener { showSelectSatDialog() }
|
|
||||||
|
|
||||||
val delay = viewModel.updateFreq
|
val delay = viewModel.updateFreq
|
||||||
val tleString = arrayOf(
|
val tleMainList = viewModel.tleMainList
|
||||||
"METEOR-M2 2",
|
val selectionList = viewModel.selectionList
|
||||||
"1 44387U 19038A 19336.45319619 -.00000025 00000-0 80323-5 0 9996",
|
mapFrame = view.findViewById(R.id.worldmap_frame)
|
||||||
"2 44387 98.5920 295.7459 0002200 37.8724 322.2609 14.23335951 21369"
|
fab = view.findViewById(R.id.worldmap_fab)
|
||||||
)
|
|
||||||
|
|
||||||
selectedSat = TLE(tleString)
|
if (tleMainList.isNotEmpty() && selectionList.isNotEmpty()) {
|
||||||
predictor = PassPredictor(selectedSat, viewModel.gsp.value)
|
fab.setOnClickListener { showSelectSatDialog(tleMainList, selectionList) }
|
||||||
|
selectedSat = tleMainList[selectionList[0]]
|
||||||
// selectedSat = viewModel.selectedSingleSat
|
predictor = PassPredictor(selectedSat, viewModel.gsp.value)
|
||||||
// lifecycleScope.launch {
|
trackView = TrackView(mainActivity)
|
||||||
// predictor = PassPredictor(selectedSat, viewModel.gsp.value)
|
mapFrame.addView(trackView)
|
||||||
// }
|
service.scheduleAtFixedRate(
|
||||||
|
{ trackView.invalidate() },
|
||||||
trackView = TrackView(activity as MainActivity)
|
delay,
|
||||||
mapFrame.addView(trackView)
|
delay,
|
||||||
service.scheduleAtFixedRate({ trackView.invalidate() }, 0, delay, TimeUnit.MILLISECONDS)
|
TimeUnit.MILLISECONDS
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
fab.setOnClickListener {
|
||||||
|
Toast.makeText(mainActivity, "No satellites were shortlisted", Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun showSelectSatDialog() {
|
private fun showSelectSatDialog(tleMainList: List<TLE>, selectionList: MutableList<Int>) {
|
||||||
// val tleMainList = viewModel.tleMainList
|
val tleNameArray = arrayOfNulls<String>(selectionList.size).apply {
|
||||||
// val tleNameArray = arrayOfNulls<String>(tleMainList.size)
|
selectionList.withIndex().forEach { (index, selection) ->
|
||||||
// var selection = viewModel.selectedSingleSat
|
this[index] = tleMainList[selection].name
|
||||||
//
|
}
|
||||||
// tleMainList.withIndex().forEach { (position, tle) ->
|
}
|
||||||
// tleNameArray[position] = tle.name
|
|
||||||
// }
|
val builder = AlertDialog.Builder(mainActivity)
|
||||||
//
|
builder.setTitle("Select Sat to track")
|
||||||
// val builder = AlertDialog.Builder(activity as MainActivity)
|
.setSingleChoiceItems(tleNameArray, checkedItem) { _, which ->
|
||||||
// builder.setTitle("Select Sat to track")
|
checkedItem = which
|
||||||
// .setSingleChoiceItems(tleNameArray, -1) { _, which ->
|
}
|
||||||
// selection = tleMainList[which]
|
.setPositiveButton("Ok") { _, _ ->
|
||||||
// }
|
selectedSat = tleMainList[selectionList[checkedItem]]
|
||||||
// .setPositiveButton("Ok") { _, _ ->
|
predictor = PassPredictor(selectedSat, viewModel.gsp.value)
|
||||||
// viewModel.updateSelectedSingleSat(selection)
|
}
|
||||||
// }
|
.setNegativeButton("Cancel") { dialog, _ ->
|
||||||
// .setNegativeButton("Cancel") { dialog, _ ->
|
dialog.cancel()
|
||||||
// dialog.cancel()
|
}
|
||||||
// }
|
.create()
|
||||||
// .create()
|
.show()
|
||||||
// .show()
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
inner class TrackView(context: Context) : View(context) {
|
inner class TrackView(context: Context) : View(context) {
|
||||||
private val groundTrackPaint = Paint().apply {
|
private val groundTrackPaint = Paint().apply {
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
color = resources.getColor(R.color.satTrack, (activity as MainActivity).theme)
|
color = resources.getColor(R.color.satTrack, mainActivity.theme)
|
||||||
style = Paint.Style.STROKE
|
style = Paint.Style.STROKE
|
||||||
strokeWidth = scale
|
strokeWidth = scale
|
||||||
}
|
}
|
||||||
private val footprintPaint = Paint().apply {
|
private val footprintPaint = Paint().apply {
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
color = resources.getColor(R.color.satFootprint, (activity as MainActivity).theme)
|
color = resources.getColor(R.color.satFootprint, mainActivity.theme)
|
||||||
style = Paint.Style.STROKE
|
style = Paint.Style.STROKE
|
||||||
strokeWidth = scale
|
strokeWidth = scale
|
||||||
}
|
}
|
||||||
private val homeLocPaint = Paint().apply {
|
private val homeLocPaint = Paint().apply {
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
color = resources.getColor(R.color.satFootprint, (activity as MainActivity).theme)
|
color = resources.getColor(R.color.satFootprint, mainActivity.theme)
|
||||||
style = Paint.Style.FILL
|
style = Paint.Style.FILL
|
||||||
strokeWidth = scale
|
strokeWidth = scale
|
||||||
}
|
}
|
||||||
@@ -128,7 +135,7 @@ class WorldMapFragment : Fragment() {
|
|||||||
val orbitalPeriod = (24 * 60 / selectedSat.meanmo).toInt()
|
val orbitalPeriod = (24 * 60 / selectedSat.meanmo).toInt()
|
||||||
val satPos = predictor.getSatPos(currentTime)
|
val satPos = predictor.getSatPos(currentTime)
|
||||||
val footprintPositions = satPos.rangeCircle
|
val footprintPositions = satPos.rangeCircle
|
||||||
val positions = predictor.getPositions(currentTime, 60, 0, orbitalPeriod * 3)
|
val positions = predictor.getPositions(currentTime, 60, 15, orbitalPeriod * 3)
|
||||||
drawGroundTrack(canvas, frameWidth, frameHeight, positions)
|
drawGroundTrack(canvas, frameWidth, frameHeight, positions)
|
||||||
drawFootprint(canvas, frameWidth, frameHeight, footprintPositions)
|
drawFootprint(canvas, frameWidth, frameHeight, footprintPositions)
|
||||||
var longitude = rad2Deg(satPos.longitude)
|
var longitude = rad2Deg(satPos.longitude)
|
||||||
|
|||||||
Reference in new issue
Block a user