Skip to content

Satellite tracker and pass predictor for Android, inspired by Gpredict

Added satellite selection buttons to MapFragment.kt

Arty Bishop19a0649cb3da
diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/mainScreen/MapFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/mainScreen/MapFragment.kt
index ba0c024c..70f608ba 100644
--- a/app/src/main/java/com/rtbishop/look4sat/ui/mainScreen/MapFragment.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/ui/mainScreen/MapFragment.kt
@@ -46,6 +46,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
private lateinit var trackPaint: Paint
private lateinit var footprintPaint: Paint
private lateinit var selectedPass: SatPass
+ private lateinit var allPasses: List<SatPass>
private val dateNow = Date()
private val viewModel: SharedViewModel by activityViewModels()
private var iconPos: Drawable? = null
@@ -122,9 +123,11 @@ class MapFragment : Fragment(R.layout.fragment_map) {
viewModel.getPasses().observe(viewLifecycleOwner, { satPasses ->
if (satPasses is Result.Success) {
if (satPasses.data.isNotEmpty()) {
- val filteredPasses = satPasses.data.distinctBy { it.tle }
- selectedPass = filteredPasses[0]
- setupSatOverlay(filteredPasses)
+ allPasses = satPasses.data.distinctBy { it.tle }
+ selectedPass = allPasses[0]
+ binding.fabPrev.setOnClickListener { changeSelection(true) }
+ binding.fabNext.setOnClickListener { changeSelection(false) }
+ setupSatOverlay(allPasses)
}
}
})
@@ -134,15 +137,27 @@ class MapFragment : Fragment(R.layout.fragment_map) {
lifecycleScope.launch {
while (true) {
dateNow.time = System.currentTimeMillis()
+ setSatDetails(selectedPass)
binding.mapView.overlays[3] = getSatMarkers(passList)
- binding.mapView.overlays[2] = getSatFootprint(selectedPass)
- setSatInfo(selectedPass)
binding.mapView.invalidate()
delay(2000)
}
}
}
+ private fun changeSelection(decrement: Boolean) {
+ val index = allPasses.indexOf(selectedPass)
+ selectedPass = if (decrement) {
+ if (index > 0) allPasses[index - 1] else allPasses[allPasses.size - 1]
+ } else {
+ if (index < allPasses.size - 1) allPasses[index + 1] else allPasses[0]
+ }
+ val satPos = selectedPass.predictor.getSatPos(dateNow)
+ val osmPos = getOsmPosition(satPos.latitude, satPos.longitude, true)
+ setSatDetails(selectedPass)
+ binding.mapView.controller.animateTo(GeoPoint(osmPos.lat, osmPos.lon))
+ }
+
private suspend fun getSatMarkers(passList: List<SatPass>): Overlay =
withContext(Dispatchers.Default) {
val items = FolderOverlay()
@@ -169,7 +184,6 @@ class MapFragment : Fragment(R.layout.fragment_map) {
setSatInfo(satPass)
binding.mapView.overlays[1] = getSatTrack(satPass)
binding.mapView.overlays[2] = getSatFootprint(satPass)
- binding.mapView.invalidate()
}
private fun setSatInfo(satPass: SatPass) {
diff --git a/app/src/main/res/layout/activity_splash.xml b/app/src/main/res/layout/activity_splash.xml
index 2aab13c9..a625ce91 100644
--- a/app/src/main/res/layout/activity_splash.xml
+++ b/app/src/main/res/layout/activity_splash.xml
@@ -19,7 +19,7 @@
android:id="@+id/splashNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginBottom="48dp"
+ android:layout_marginBottom="@dimen/fab_padding"
android:contentDescription="@string/placeholder"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
diff --git a/app/src/main/res/layout/fragment_entries.xml b/app/src/main/res/layout/fragment_entries.xml
index c2a9f12f..dd96e8d1 100644
--- a/app/src/main/res/layout/fragment_entries.xml
+++ b/app/src/main/res/layout/fragment_entries.xml
@@ -130,7 +130,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
- android:layout_margin="32dp"
+ android:layout_margin="@dimen/fab_padding"
android:contentDescription="@string/placeholder"
android:src="@drawable/ic_arrow"
app:fabSize="mini" />
diff --git a/app/src/main/res/layout/fragment_map.xml b/app/src/main/res/layout/fragment_map.xml
index 46ca34cf..ec28b590 100644
--- a/app/src/main/res/layout/fragment_map.xml
+++ b/app/src/main/res/layout/fragment_map.xml
@@ -94,6 +94,31 @@
</androidx.constraintlayout.widget.ConstraintLayout>
+ <com.google.android.material.floatingactionbutton.FloatingActionButton
+ android:id="@+id/fabPrev"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/fab_padding"
+ android:layout_marginBottom="@dimen/fab_padding"
+ android:contentDescription="@string/placeholder"
+ android:rotation="180"
+ app:fabSize="mini"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:srcCompat="@drawable/ic_arrow" />
+
+ <com.google.android.material.floatingactionbutton.FloatingActionButton
+ android:id="@+id/fabNext"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="@dimen/fab_padding"
+ android:layout_marginBottom="@dimen/fab_padding"
+ android:contentDescription="@string/placeholder"
+ app:fabSize="mini"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:srcCompat="@drawable/ic_arrow" />
+
<com.google.android.material.textview.MaterialTextView
android:id="@+id/copyright"
android:layout_width="wrap_content"
diff --git a/app/src/main/res/layout/fragment_passes.xml b/app/src/main/res/layout/fragment_passes.xml
index 2e36b3ab..c327b5bb 100644
--- a/app/src/main/res/layout/fragment_passes.xml
+++ b/app/src/main/res/layout/fragment_passes.xml
@@ -117,7 +117,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
- android:layout_marginBottom="32dp"
+ android:layout_marginBottom="@dimen/fab_padding"
android:contentDescription="@string/placeholder"
android:src="@drawable/ic_refresh"
app:fabSize="mini" />
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
new file mode 100644
index 00000000..7dcaae24
--- /dev/null
+++ b/app/src/main/res/values/dimens.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <dimen name="fab_padding">48dp</dimen>
+</resources>
\ No newline at end of file