Skip to content

Satellite tracker and pass predictor for Android, inspired by Gpredict

Created a dialog to select satellites to track. Trying to find a better option to retain changes. JetPack Preferences lib mb?

Arty Bishop361fe92ac165
diff --git a/app/src/main/java/com/rtbishop/lookingsat/ui/SkyFragment.kt b/app/src/main/java/com/rtbishop/lookingsat/ui/SkyFragment.kt
index a7f9c44d..eea85751 100644
--- a/app/src/main/java/com/rtbishop/lookingsat/ui/SkyFragment.kt
+++ b/app/src/main/java/com/rtbishop/lookingsat/ui/SkyFragment.kt
@@ -63,5 +63,45 @@ class SkyFragment : Fragment() {
recView.visibility = View.VISIBLE
}
}
+
+ fab.setOnClickListener { showSelectSatDialog() }
+ }
+
+ private var selectedSatList: List<TLE> = emptyList()
+
+ private fun showSelectSatDialog() {
+ val tleList = mutableListOf<TLE>()
+ val listSize = viewModel.tleList.size
+ val satList = arrayOfNulls<String>(listSize)
+ val checkedSatList = BooleanArray(listSize)
+ if (selectedSatList.isEmpty()) {
+ for ((position, tle) in viewModel.tleList.withIndex()) {
+ satList[position] = tle.name
+ checkedSatList[position] = false
+ }
+ }
+
+ val builder = AlertDialog.Builder(activity as MainActivity)
+ builder.setTitle("Select satellites to track")
+
+ builder.setMultiChoiceItems(satList, checkedSatList) { _, which, isChecked ->
+ checkedSatList[which] = isChecked
+ }
+
+ builder.setPositiveButton("Select") { _, _ ->
+ for (index in checkedSatList.indices) {
+ val checked = checkedSatList[index]
+ if (checked) {
+ tleList.add(viewModel.tleList[index])
+ }
+ }
+ }
+
+ builder.setNegativeButton("Cancel") { dialog, _ ->
+ dialog.cancel()
+ }
+
+ val dialog = builder.create()
+ dialog.show()
}
}
\ No newline at end of file