mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-07 13:07:22 +00:00
Fixed TLE list update logic. It now also triggers satellite passes recalculation.
This commit is contained in:
1 parent
cd83cb6109
commit
e219d42a9b
2 files changed
+28
-28
No files matched your search
@@ -48,16 +48,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
private val _debugMessage = MutableLiveData("")
|
private val _debugMessage = MutableLiveData("")
|
||||||
val debugMessage: LiveData<String> = _debugMessage
|
val debugMessage: LiveData<String> = _debugMessage
|
||||||
|
|
||||||
private val _tleMainList = MutableLiveData<List<TLE>>(
|
private val _tleMainList = MutableLiveData<List<TLE>>(loadTwoLineElementFile())
|
||||||
try {
|
|
||||||
TLE.importSat(getApplication<Application>().openFileInput(tleFile))
|
|
||||||
.sortedWith(compareBy { it.name })
|
|
||||||
} catch (exception: FileNotFoundException) {
|
|
||||||
_debugMessage.postValue("TLE file wasn't found")
|
|
||||||
emptyList<TLE>()
|
|
||||||
}
|
|
||||||
|
|
||||||
)
|
|
||||||
val tleMainList: LiveData<List<TLE>> = _tleMainList
|
val tleMainList: LiveData<List<TLE>> = _tleMainList
|
||||||
|
|
||||||
private val _tleSelectedMap = MutableLiveData<MutableMap<TLE, Boolean>>(mutableMapOf())
|
private val _tleSelectedMap = MutableLiveData<MutableMap<TLE, Boolean>>(mutableMapOf())
|
||||||
@@ -80,6 +71,16 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
)
|
)
|
||||||
val gsp: LiveData<GroundStationPosition> = _gsp
|
val gsp: LiveData<GroundStationPosition> = _gsp
|
||||||
|
|
||||||
|
private fun loadTwoLineElementFile(): List<TLE> {
|
||||||
|
return try {
|
||||||
|
TLE.importSat(getApplication<Application>().openFileInput(tleFile))
|
||||||
|
.sortedWith(compareBy { it.name })
|
||||||
|
} catch (exception: FileNotFoundException) {
|
||||||
|
_debugMessage.postValue("TLE file wasn't found")
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getPasses(satMap: Map<TLE, Boolean>, hours: Int, maxEl: Double): List<SatPass> {
|
suspend fun getPasses(satMap: Map<TLE, Boolean>, hours: Int, maxEl: Double): List<SatPass> {
|
||||||
val satPassList = mutableListOf<SatPass>()
|
val satPassList = mutableListOf<SatPass>()
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
@@ -139,7 +140,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
getApplication<Application>().openFileOutput(tleFile, Context.MODE_PRIVATE).use {
|
getApplication<Application>().openFileOutput(tleFile, Context.MODE_PRIVATE).use {
|
||||||
it.write(stream.readBytes())
|
it.write(stream.readBytes())
|
||||||
}
|
}
|
||||||
_tleMainList.postValue(TLE.importSat(stream))
|
_tleMainList.postValue(loadTwoLineElementFile())
|
||||||
_debugMessage.postValue("TLE file was updated")
|
_debugMessage.postValue("TLE file was updated")
|
||||||
} catch (exception: IOException) {
|
} catch (exception: IOException) {
|
||||||
_debugMessage.postValue("Couldn't update TLE file")
|
_debugMessage.postValue("Couldn't update TLE file")
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class SkyFragment : Fragment() {
|
|||||||
private lateinit var progressBar: ProgressBar
|
private lateinit var progressBar: ProgressBar
|
||||||
private lateinit var fab: FloatingActionButton
|
private lateinit var fab: FloatingActionButton
|
||||||
private lateinit var tleMainList: List<TLE>
|
private lateinit var tleMainList: List<TLE>
|
||||||
private lateinit var selectedSatMap: MutableMap<TLE, Boolean>
|
private var selectedSatMap: MutableMap<TLE, Boolean> = mutableMapOf()
|
||||||
private lateinit var satPassPrefs: SatPassPrefs
|
private lateinit var satPassPrefs: SatPassPrefs
|
||||||
private lateinit var aosTimer: CountDownTimer
|
private lateinit var aosTimer: CountDownTimer
|
||||||
private var isTimerSet: Boolean = false
|
private var isTimerSet: Boolean = false
|
||||||
@@ -72,6 +72,8 @@ class SkyFragment : Fragment() {
|
|||||||
private fun setupObservers() {
|
private fun setupObservers() {
|
||||||
viewModel.tleMainList.observe(this, Observer {
|
viewModel.tleMainList.observe(this, Observer {
|
||||||
tleMainList = it
|
tleMainList = it
|
||||||
|
selectedSatMap.clear()
|
||||||
|
viewModel.updateSelectedSatMap(selectedSatMap)
|
||||||
})
|
})
|
||||||
|
|
||||||
viewModel.tleSelectedMap.observe(this, Observer {
|
viewModel.tleSelectedMap.observe(this, Observer {
|
||||||
@@ -113,42 +115,39 @@ class SkyFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showSelectSatDialog() {
|
private fun showSelectSatDialog() {
|
||||||
val tleList = tleMainList
|
val tleNameArray = arrayOfNulls<String>(tleMainList.size)
|
||||||
val tleSelectedMap = selectedSatMap
|
val tleCheckedArray = BooleanArray(tleMainList.size)
|
||||||
val tleMainListSize = tleList.size
|
val builder = AlertDialog.Builder(activity as MainActivity)
|
||||||
val tleNameArray = arrayOfNulls<String>(tleMainListSize)
|
val selectionMap = mutableMapOf<TLE, Boolean>()
|
||||||
val tleCheckedArray = BooleanArray(tleMainListSize)
|
|
||||||
|
|
||||||
if (tleSelectedMap.isEmpty()) {
|
if (selectedSatMap.isEmpty()) {
|
||||||
tleList.withIndex().forEach { (position, tle) ->
|
tleMainList.withIndex().forEach { (position, tle) ->
|
||||||
tleNameArray[position] = tle.name
|
tleNameArray[position] = tle.name
|
||||||
tleCheckedArray[position] = false
|
tleCheckedArray[position] = false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tleList.withIndex().forEach { (position, tle) ->
|
tleMainList.withIndex().forEach { (position, tle) ->
|
||||||
tleNameArray[position] = tle.name
|
tleNameArray[position] = tle.name
|
||||||
tleCheckedArray[position] = tleSelectedMap.getOrDefault(tle, false)
|
tleCheckedArray[position] = selectedSatMap.getOrDefault(tle, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val selectionMap = mutableMapOf<TLE, Boolean>()
|
|
||||||
val builder = AlertDialog.Builder(activity as MainActivity)
|
|
||||||
builder.setTitle(getString(R.string.title_select_sat))
|
builder.setTitle(getString(R.string.title_select_sat))
|
||||||
.setMultiChoiceItems(tleNameArray, tleCheckedArray) { _, which, isChecked ->
|
.setMultiChoiceItems(tleNameArray, tleCheckedArray) { _, which, isChecked ->
|
||||||
selectionMap[tleList[which]] = isChecked
|
selectionMap[tleMainList[which]] = isChecked
|
||||||
}
|
}
|
||||||
.setPositiveButton(getString(R.string.btn_ok)) { _, _ ->
|
.setPositiveButton(getString(R.string.btn_ok)) { _, _ ->
|
||||||
for ((tle, value) in selectionMap) {
|
for ((tle, value) in selectionMap) {
|
||||||
tleSelectedMap[tle] = value
|
selectedSatMap[tle] = value
|
||||||
viewModel.updateSelectedSatMap(tleSelectedMap)
|
viewModel.updateSelectedSatMap(selectedSatMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.setNegativeButton(getString(R.string.btn_cancel)) { dialog, _ ->
|
.setNegativeButton(getString(R.string.btn_cancel)) { dialog, _ ->
|
||||||
dialog.cancel()
|
dialog.cancel()
|
||||||
}
|
}
|
||||||
.setNeutralButton(getString(R.string.btn_clear)) { _, _ ->
|
.setNeutralButton(getString(R.string.btn_clear)) { _, _ ->
|
||||||
tleSelectedMap.clear()
|
selectedSatMap.clear()
|
||||||
viewModel.updateSelectedSatMap(tleSelectedMap)
|
viewModel.updateSelectedSatMap(selectedSatMap)
|
||||||
}
|
}
|
||||||
.create()
|
.create()
|
||||||
.show()
|
.show()
|
||||||
|
|||||||
Reference in new issue
Block a user