Implemented a temporary but functional way to show passes of the selected satellites on the WorldMap

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