mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added dialog for satellite selection. Showing only selected passes in the recycler.
This commit is contained in:
1 parent
09c6353c33
commit
bfc0561c34
3 files changed
+52
-47
No files matched your search
+1
-1
@@ -8,7 +8,7 @@ android {
|
||||
buildToolsVersion "29.0.2"
|
||||
defaultConfig {
|
||||
applicationId "com.rtbishop.lookingsat"
|
||||
minSdkVersion 22
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "0.2"
|
||||
|
||||
@@ -55,7 +55,7 @@ class SkyFragment : Fragment() {
|
||||
recView.visibility = View.INVISIBLE
|
||||
progressBar.visibility = View.VISIBLE
|
||||
progressBar.isIndeterminate = true
|
||||
satPassList = viewModel.updateRecycler()
|
||||
satPassList = viewModel.getPassesForSelectedSatellites()
|
||||
recAdapter = SatPassAdapter(satPassList)
|
||||
recView.adapter = recAdapter
|
||||
progressBar.isIndeterminate = false
|
||||
@@ -67,41 +67,43 @@ class SkyFragment : Fragment() {
|
||||
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 tleSelectedMap = viewModel.tleSelectedMap
|
||||
val tleMainListSize = viewModel.tleMainList.size
|
||||
|
||||
val tleNameArray = arrayOfNulls<String>(tleMainListSize)
|
||||
val tleCheckedArray = BooleanArray(tleMainListSize)
|
||||
|
||||
if (tleSelectedMap.isEmpty()) {
|
||||
for ((position, tle) in viewModel.tleMainList.withIndex()) {
|
||||
tleNameArray[position] = tle.name
|
||||
tleCheckedArray[position] = false
|
||||
}
|
||||
} else {
|
||||
for ((position, tle) in viewModel.tleMainList.withIndex()) {
|
||||
tleNameArray[position] = tle.name
|
||||
tleCheckedArray[position] = viewModel.tleSelectedMap.getOrDefault(tle, false)
|
||||
}
|
||||
}
|
||||
|
||||
val selectionMap = mutableMapOf<TLE, Boolean>()
|
||||
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])
|
||||
.setMultiChoiceItems(tleNameArray, tleCheckedArray) { _, which, isChecked ->
|
||||
selectionMap[viewModel.tleMainList[which]] = isChecked
|
||||
}
|
||||
.setPositiveButton("Ok") { _, _ ->
|
||||
for ((tle, value) in selectionMap) {
|
||||
tleSelectedMap[tle] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
builder.setNegativeButton("Cancel") { dialog, _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
.setNeutralButton("Clear All") { _, _ ->
|
||||
tleSelectedMap.clear()
|
||||
}
|
||||
.setNegativeButton("Cancel") { dialog, _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
)
|
||||
val gsp: LiveData<GroundStationPosition> = _gsp
|
||||
|
||||
var tleList: List<TLE> = loadTwoLineElementFile().sortedWith(compareBy { it.name })
|
||||
var tleMainList = loadTwoLineElementFile().sortedWith(compareBy { it.name })
|
||||
var tleSelectedMap = mutableMapOf<TLE, Boolean>()
|
||||
|
||||
private fun loadTwoLineElementFile(): List<TLE> {
|
||||
return try {
|
||||
@@ -61,25 +62,27 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateRecycler(): List<SatPass> {
|
||||
suspend fun getPassesForSelectedSatellites(): List<SatPass> {
|
||||
val satPassList = mutableListOf<SatPass>()
|
||||
var sortedList = listOf<SatPass>()
|
||||
withContext(Dispatchers.Default) {
|
||||
for (tle in tleList.subList(0, 1)) {
|
||||
try {
|
||||
Log.d(tag, "Trying ${tle.name}")
|
||||
val passPredictor = PassPredictor(tle, gsp.value)
|
||||
val passes = passPredictor.getPasses(Date(), 6, false)
|
||||
for (pass in passes) {
|
||||
Log.d(tag, "Trying ${pass.maxEl}")
|
||||
satPassList.add(SatPass(tle.name, tle.catnum, pass))
|
||||
for ((tle, value) in tleSelectedMap) {
|
||||
if (value) {
|
||||
try {
|
||||
Log.d(tag, "Trying ${tle.name}")
|
||||
val passPredictor = PassPredictor(tle, gsp.value)
|
||||
val passes = passPredictor.getPasses(Date(), 6, true)
|
||||
for (pass in passes) {
|
||||
Log.d(tag, "Trying ${pass.maxEl}")
|
||||
satPassList.add(SatPass(tle.name, tle.catnum, pass))
|
||||
}
|
||||
} catch (exception: IllegalArgumentException) {
|
||||
val tleProblem = "There was a problem with TLE"
|
||||
Log.d(tag, tleProblem)
|
||||
_debugMessage.postValue(tleProblem)
|
||||
} catch (exception: SatNotFoundException) {
|
||||
Log.d(tag, "Certain satellites shall not pass")
|
||||
}
|
||||
} catch (exception: IllegalArgumentException) {
|
||||
val tleProblem = "There was a problem with TLE"
|
||||
Log.d(tag, tleProblem)
|
||||
_debugMessage.postValue(tleProblem)
|
||||
} catch (exception: SatNotFoundException) {
|
||||
Log.d(tag, "Certain satellites shall not pass")
|
||||
}
|
||||
}
|
||||
sortedList = satPassList.sortedWith(compareBy { it.pass.startTime })
|
||||
@@ -111,7 +114,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
getApplication<Application>().openFileOutput(tleFile, Context.MODE_PRIVATE).use {
|
||||
it.write(stream.readBytes())
|
||||
}
|
||||
tleList = TLE.importSat(stream)
|
||||
tleMainList = TLE.importSat(stream)
|
||||
_debugMessage.postValue("TLE file was updated")
|
||||
} catch (exception: IOException) {
|
||||
_debugMessage.postValue("Couldn't update TLE file")
|
||||
|
||||
Reference in new issue
Block a user