mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-03 03:27:24 +00:00
Moved and renamed various classes to simplify structure
This commit is contained in:
1 parent
c91c58ac69
commit
fdb5752408
33 files changed
+224
-214
No files matched your search
+1
-1
@@ -2,7 +2,7 @@ package com.rtbishop.look4sat.data
|
||||
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.StationPosition
|
||||
|
||||
interface PreferenceSource {
|
||||
interface PreferencesSource {
|
||||
|
||||
fun positionToQTH(lat: Double, lon: Double): String?
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import com.rtbishop.look4sat.domain.model.SatTrans
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.Satellite
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface LocalDataSource {
|
||||
interface SatDataLocalSource {
|
||||
|
||||
fun getSatItems(): Flow<List<SatItem>>
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package com.rtbishop.look4sat.data
|
||||
import com.rtbishop.look4sat.domain.model.SatTrans
|
||||
import java.io.InputStream
|
||||
|
||||
interface RemoteDataSource {
|
||||
interface SatDataRemoteSource {
|
||||
|
||||
suspend fun fetchDataStream(url: String): InputStream?
|
||||
|
||||
+33
-12
@@ -12,9 +12,10 @@ import kotlinx.coroutines.withContext
|
||||
import java.io.InputStream
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
class SatelliteRepo(
|
||||
private val localSource: LocalDataSource,
|
||||
private val remoteSource: RemoteDataSource,
|
||||
class SatDataRepository(
|
||||
private val preferencesSource: PreferencesSource,
|
||||
private val satLocalSource: SatDataLocalSource,
|
||||
private val satRemoteSource: SatDataRemoteSource,
|
||||
private val ioDispatcher: CoroutineDispatcher
|
||||
) {
|
||||
private val defaultSources = listOf(
|
||||
@@ -24,20 +25,40 @@ class SatelliteRepo(
|
||||
"https://www.prismnet.com/~mmccants/tles/inttles.zip"
|
||||
)
|
||||
|
||||
private val transmittersModes = arrayOf(
|
||||
"AFSK", "AFSK S-Net", "AFSK SALSAT", "AHRPT", "AM", "APT", "BPSK", "BPSK PMT-A3",
|
||||
"CERTO", "CW", "DQPSK", "DSTAR", "DUV", "FFSK", "FM", "FMN", "FSK", "FSK AX.100 Mode 5",
|
||||
"FSK AX.100 Mode 6", "FSK AX.25 G3RUH", "GFSK", "GFSK Rktr", "GMSK", "HRPT", "LoRa",
|
||||
"LRPT", "LSB", "MFSK", "MSK", "MSK AX.100 Mode 5", "MSK AX.100 Mode 6", "OFDM", "OQPSK",
|
||||
"PSK", "PSK31", "PSK63", "QPSK", "QPSK31", "QPSK63", "SSTV", "USB", "WSJT"
|
||||
)
|
||||
|
||||
fun getAllModes(): Array<String> {
|
||||
return transmittersModes
|
||||
}
|
||||
|
||||
fun saveModesSelection(modes: List<String>) {
|
||||
preferencesSource.saveModesSelection(modes)
|
||||
}
|
||||
|
||||
fun loadModesSelection(): List<String> {
|
||||
return preferencesSource.loadModesSelection()
|
||||
}
|
||||
|
||||
fun getSatItems(): Flow<List<SatItem>> {
|
||||
return localSource.getSatItems()
|
||||
return satLocalSource.getSatItems()
|
||||
}
|
||||
|
||||
fun getSatTransmitters(catNum: Int): Flow<List<SatTrans>> {
|
||||
return localSource.getSatTransmitters(catNum)
|
||||
return satLocalSource.getSatTransmitters(catNum)
|
||||
}
|
||||
|
||||
suspend fun getSelectedSatellites(): List<Satellite> {
|
||||
return localSource.getSelectedSatellites()
|
||||
return satLocalSource.getSelectedSatellites()
|
||||
}
|
||||
|
||||
suspend fun updateEntriesFromFile(stream: InputStream) = withContext(ioDispatcher) {
|
||||
localSource.updateEntries(importSatEntries(stream))
|
||||
satLocalSource.updateEntries(importSatEntries(stream))
|
||||
}
|
||||
|
||||
suspend fun updateEntriesFromWeb(sources: List<String> = defaultSources) {
|
||||
@@ -46,7 +67,7 @@ class SatelliteRepo(
|
||||
val streams = mutableListOf<InputStream>()
|
||||
val entries = mutableListOf<SatEntry>()
|
||||
sources.forEach { source ->
|
||||
remoteSource.fetchDataStream(source)?.let { stream ->
|
||||
satRemoteSource.fetchDataStream(source)?.let { stream ->
|
||||
if (source.contains(".zip", true)) {
|
||||
val zipStream = ZipInputStream(stream).apply { nextEntry }
|
||||
streams.add(zipStream)
|
||||
@@ -56,17 +77,17 @@ class SatelliteRepo(
|
||||
}
|
||||
}
|
||||
streams.forEach { stream -> entries.addAll(importSatEntries(stream)) }
|
||||
localSource.updateEntries(entries)
|
||||
satLocalSource.updateEntries(entries)
|
||||
}
|
||||
launch(ioDispatcher) {
|
||||
val transmitters = remoteSource.fetchTransmitters().filter { it.isAlive }
|
||||
localSource.updateTransmitters(transmitters)
|
||||
val transmitters = satRemoteSource.fetchTransmitters().filter { it.isAlive }
|
||||
satLocalSource.updateTransmitters(transmitters)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean) {
|
||||
localSource.updateEntriesSelection(catNums, isSelected)
|
||||
satLocalSource.updateEntriesSelection(catNums, isSelected)
|
||||
}
|
||||
|
||||
private fun importSatEntries(stream: InputStream): List<SatEntry> {
|
||||
+6
-6
@@ -25,8 +25,8 @@ import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.*
|
||||
|
||||
class PassesRepo(
|
||||
private val preferenceSource: PreferenceSource,
|
||||
class SatPassRepository(
|
||||
private val preferencesSource: PreferencesSource,
|
||||
private val defaultDispatcher: CoroutineDispatcher
|
||||
) {
|
||||
private val _passes = MutableSharedFlow<List<SatPass>>(replay = 1)
|
||||
@@ -57,15 +57,15 @@ class PassesRepo(
|
||||
}
|
||||
|
||||
private fun getPasses(satellite: Satellite, refDate: Date): List<SatPass> {
|
||||
val predictor = satellite.getPredictor(preferenceSource.loadStationPosition())
|
||||
return predictor.getPasses(refDate, preferenceSource.getHoursAhead(), true)
|
||||
val predictor = satellite.getPredictor(preferencesSource.loadStationPosition())
|
||||
return predictor.getPasses(refDate, preferencesSource.getHoursAhead(), true)
|
||||
}
|
||||
|
||||
private fun filterPasses(passes: List<SatPass>, refDate: Date): List<SatPass> {
|
||||
val timeFuture = Date(refDate.time + (preferenceSource.getHoursAhead() * 3600 * 1000))
|
||||
val timeFuture = Date(refDate.time + (preferencesSource.getHoursAhead() * 3600 * 1000))
|
||||
return passes.filter { it.losDate.after(refDate) }
|
||||
.filter { it.aosDate.before(timeFuture) }
|
||||
.filter { it.maxElevation > preferenceSource.getMinElevation() }
|
||||
.filter { it.maxElevation > preferencesSource.getMinElevation() }
|
||||
.sortedBy { it.aosDate }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user