mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Moved DataSources storage to SharedPreferences
This commit is contained in:
1 parent
0f4a70b204
commit
9c137ada9f
16 files changed
+108
-656
No files matched your search
@@ -31,29 +31,16 @@ import kotlin.system.measureTimeMillis
|
||||
class DefaultRepository(
|
||||
private val dataParser: DataParser,
|
||||
private val localSource: LocalDataSource,
|
||||
private val remoteSource: RemoteDataSource
|
||||
private val remoteSource: RemoteDataSource,
|
||||
private val preferences: PreferencesHandler
|
||||
) : DataRepository {
|
||||
|
||||
override val defaultSelection = listOf(43700, 25544, 25338, 28654, 33591, 40069, 27607, 24278)
|
||||
override val defaultSources = listOf(
|
||||
"https://celestrak.com/NORAD/elements/gp.php?GROUP=active&FORMAT=csv",
|
||||
"https://amsat.org/tle/current/nasabare.txt",
|
||||
"https://www.prismnet.com/~mmccants/tles/classfd.zip",
|
||||
"https://www.prismnet.com/~mmccants/tles/inttles.zip"
|
||||
)
|
||||
override val transmittersSource = "https://db.satnogs.org/api/transmitters/?format=json"
|
||||
|
||||
override fun getSatelliteItems() = localSource.getSatelliteItems()
|
||||
|
||||
override suspend fun getSelectedSatellites() = localSource.getSelectedSatellites()
|
||||
|
||||
override suspend fun getTransmitters(catnum: Int) = localSource.getTransmitters(catnum)
|
||||
|
||||
override suspend fun getWebSources() = localSource.getSources().also { sources ->
|
||||
return if (sources.isNotEmpty()) sources
|
||||
else defaultSources
|
||||
}
|
||||
|
||||
override suspend fun updateDataFromFile(stream: InputStream) {
|
||||
localSource.updateEntries(importSatellites(stream))
|
||||
}
|
||||
@@ -61,7 +48,7 @@ class DefaultRepository(
|
||||
override suspend fun updateDataFromWeb(sources: List<String>) {
|
||||
coroutineScope {
|
||||
launch {
|
||||
localSource.updateSources(sources)
|
||||
preferences.saveDataSources(sources)
|
||||
}
|
||||
launch {
|
||||
val updateTimeMillis = measureTimeMillis {
|
||||
@@ -91,7 +78,7 @@ class DefaultRepository(
|
||||
println("Update from web took $updateTimeMillis ms")
|
||||
}
|
||||
launch {
|
||||
remoteSource.fetchFileStream(transmittersSource)?.let { inputStream ->
|
||||
remoteSource.fetchFileStream(preferences.transmittersSource)?.let { inputStream ->
|
||||
val transmitters = dataParser.parseJSONStream(inputStream)
|
||||
localSource.updateTransmitters(transmitters)
|
||||
}
|
||||
|
||||
@@ -29,15 +29,11 @@ interface LocalDataSource {
|
||||
|
||||
suspend fun getSelectedSatellites(): List<Satellite>
|
||||
|
||||
suspend fun getSources(): List<String>
|
||||
|
||||
suspend fun getTransmitters(catnum: Int): List<Transmitter>
|
||||
|
||||
suspend fun updateEntries(entries: List<SatEntry>)
|
||||
|
||||
suspend fun updateEntriesSelection(catnums: List<Int>, isSelected: Boolean)
|
||||
|
||||
suspend fun updateSources(sources: List<String>)
|
||||
|
||||
suspend fun updateTransmitters(transmitters: List<Transmitter>)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Look4Sat. Amateur radio satellite tracker and pass predictor.
|
||||
* Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rtbishop.look4sat.data
|
||||
|
||||
interface PreferencesHandler {
|
||||
|
||||
val defaultSources: List<String>
|
||||
get() = listOf(
|
||||
"https://celestrak.com/NORAD/elements/gp.php?GROUP=active&FORMAT=csv",
|
||||
"https://amsat.org/tle/current/nasabare.txt",
|
||||
"https://prismnet.com/~mmccants/tles/classfd.zip",
|
||||
"https://prismnet.com/~mmccants/tles/inttles.zip"
|
||||
)
|
||||
val transmittersSource: String
|
||||
get() = "https://db.satnogs.org/api/transmitters/?format=json"
|
||||
|
||||
fun loadDataSources(): List<String>
|
||||
|
||||
fun saveDataSources(sources: List<String>)
|
||||
}
|
||||
@@ -25,21 +25,15 @@ import java.io.InputStream
|
||||
|
||||
interface DataRepository {
|
||||
|
||||
val defaultSelection: List<Int>
|
||||
val defaultSources: List<String>
|
||||
val transmittersSource: String
|
||||
|
||||
fun getSatelliteItems(): Flow<List<SatItem>>
|
||||
|
||||
suspend fun getSelectedSatellites(): List<Satellite>
|
||||
|
||||
suspend fun getTransmitters(catnum: Int): List<Transmitter>
|
||||
|
||||
suspend fun getWebSources(): List<String>
|
||||
|
||||
suspend fun updateDataFromFile(stream: InputStream)
|
||||
|
||||
suspend fun updateDataFromWeb(sources: List<String> = defaultSources)
|
||||
suspend fun updateDataFromWeb(sources: List<String>)
|
||||
|
||||
suspend fun updateSelection(catnums: List<Int> = defaultSelection, isSelected: Boolean = true)
|
||||
suspend fun updateSelection(catnums: List<Int>, isSelected: Boolean = true)
|
||||
}
|
||||
Reference in new issue
Block a user