Added passes filtering by modes to PassesScreen

This commit is contained in:
Arty Bishop committed 2025-12-27 15:01:45 +00:00
1 parent a088a7a0a2
commit 269d48d250
6 files changed
+19 -11

No files matched your search

@@ -89,14 +89,14 @@ class PassesViewModel(
processing?.cancelAndJoin() processing?.cancelAndJoin()
settingsRepo.setPassesSettings(PassesSettings(hoursAhead, minElevation, modes)) settingsRepo.setPassesSettings(PassesSettings(hoursAhead, minElevation, modes))
_uiState.value = _uiState.value.copy(hours = hoursAhead, elevation = minElevation, modes = modes) _uiState.value = _uiState.value.copy(hours = hoursAhead, elevation = minElevation, modes = modes)
satelliteRepo.calculatePasses(System.currentTimeMillis(), hoursAhead, minElevation) satelliteRepo.calculatePasses(System.currentTimeMillis(), hoursAhead, minElevation, modes)
} }
private fun refreshPasses() = viewModelScope.launch { private fun refreshPasses() = viewModelScope.launch {
_uiState.value = _uiState.value.copy(isRefreshing = true) _uiState.value = _uiState.value.copy(isRefreshing = true)
processing?.cancelAndJoin() processing?.cancelAndJoin()
val (hoursAhead, minElevation) = settingsRepo.passesSettings.value val (hoursAhead, minElevation, modes) = settingsRepo.passesSettings.value
satelliteRepo.calculatePasses(System.currentTimeMillis(), hoursAhead, minElevation) satelliteRepo.calculatePasses(System.currentTimeMillis(), hoursAhead, minElevation, modes)
} }
private fun setPassInfo(passes: List<SatPass>, timeNow: Long) { private fun setPassInfo(passes: List<SatPass>, timeNow: Long) {
@@ -46,6 +46,9 @@ interface StorageDao {
@Query("DELETE FROM entries") @Query("DELETE FROM entries")
suspend fun deleteEntries() suspend fun deleteEntries()
@Query("SELECT catnum FROM radios WHERE mode IN (:modes)")
suspend fun getIdsWithModes(modes: List<String>): List<Int>
@Query("SELECT COUNT(*) FROM radios") @Query("SELECT COUNT(*) FROM radios")
suspend fun getRadiosTotal(): Int suspend fun getRadiosTotal(): Int
@@ -50,8 +50,8 @@ class SatelliteRepo(
override suspend fun initRepository() = withContext(dispatcher) { override suspend fun initRepository() = withContext(dispatcher) {
settingsRepo.selectedIds.collect { selectedIds -> settingsRepo.selectedIds.collect { selectedIds ->
_satellites.update { localStorage.getEntriesWithIds(selectedIds) } _satellites.update { localStorage.getEntriesWithIds(selectedIds) }
val (hoursAhead, minElevation) = settingsRepo.passesSettings.value val (hoursAhead, minElevation, modes) = settingsRepo.passesSettings.value
calculatePasses(System.currentTimeMillis(), hoursAhead, minElevation) calculatePasses(System.currentTimeMillis(), hoursAhead, minElevation, modes)
} }
} }
@@ -99,15 +99,17 @@ class SatelliteRepo(
} }
} }
override suspend fun calculatePasses(time: Long, hoursAhead: Int, minElevation: Double) { override suspend fun calculatePasses(time: Long, hoursAhead: Int, minElevation: Double, modes: List<String>) {
if (_satellites.value.isNotEmpty()) { if (_satellites.value.isNotEmpty()) {
withContext(dispatcher) { withContext(dispatcher) {
val allPasses = mutableListOf<SatPass>() val newPasses = mutableListOf<SatPass>()
val stationPos = settingsRepo.stationPosition.value val idsWithModes = localStorage.getIdsWithModes(modes)
_satellites.value.forEach { satellite -> _satellites.value.forEach { satellite ->
allPasses.addAll(satellite.getPasses(stationPos, time, hoursAhead)) if (idsWithModes.isEmpty() || satellite.data.catnum in idsWithModes) {
newPasses.addAll(satellite.getPasses(settingsRepo.stationPosition.value, time, hoursAhead))
} }
_passes.update { allPasses.filter(time, hoursAhead, minElevation) } }
_passes.update { newPasses.filter(time, hoursAhead, minElevation) }
} }
} else { } else {
_passes.update { emptyList() } _passes.update { emptyList() }
@@ -53,6 +53,8 @@ class LocalSource(private val storageDao: StorageDao) : ILocalSource {
override suspend fun deleteEntries() = storageDao.deleteEntries() override suspend fun deleteEntries() = storageDao.deleteEntries()
override suspend fun getIdsWithModes(modes: List<String>) = storageDao.getIdsWithModes(modes)
private fun DomainEntry.toFramework() = FrameworkEntry(this.data, this.comment) private fun DomainEntry.toFramework() = FrameworkEntry(this.data, this.comment)
private fun FrameworkItem.toDomain() = DomainItem(this.catnum, this.name, false) private fun FrameworkItem.toDomain() = DomainItem(this.catnum, this.name, false)
@@ -16,5 +16,5 @@ interface ISatelliteRepo {
suspend fun getTrack(sat: Satellite, pos: GeoPos, start: Long, end: Long): List<SatPos> suspend fun getTrack(sat: Satellite, pos: GeoPos, start: Long, end: Long): List<SatPos>
suspend fun getRadios(sat: Satellite, pos: GeoPos, radios: List<SatRadio>, time: Long): List<SatRadio> suspend fun getRadios(sat: Satellite, pos: GeoPos, radios: List<SatRadio>, time: Long): List<SatRadio>
suspend fun processPasses(passList: List<SatPass>, time: Long): List<SatPass> suspend fun processPasses(passList: List<SatPass>, time: Long): List<SatPass>
suspend fun calculatePasses(time: Long, hoursAhead: Int = 8, minElevation: Double = 16.0) suspend fun calculatePasses(time: Long, hoursAhead: Int, minElevation: Double, modes: List<String>)
} }
@@ -28,6 +28,7 @@ interface ILocalSource {
suspend fun getEntriesWithIds(ids: List<Int>): List<Satellite> suspend fun getEntriesWithIds(ids: List<Int>): List<Satellite>
suspend fun insertEntries(entries: List<SatEntry>) suspend fun insertEntries(entries: List<SatEntry>)
suspend fun deleteEntries() suspend fun deleteEntries()
suspend fun getIdsWithModes(modes: List<String>): List<Int>
suspend fun getRadiosTotal(): Int suspend fun getRadiosTotal(): Int
suspend fun getRadiosWithId(id: Int): List<SatRadio> suspend fun getRadiosWithId(id: Int): List<SatRadio>
suspend fun insertRadios(radios: List<SatRadio>) suspend fun insertRadios(radios: List<SatRadio>)