Using default TLE sources if empty sources list passed for update

This commit is contained in:
Arty Bishop committed 2021-03-01 20:57:58 +00:00
1 parent 07db0378c5
commit 31fe18e4b5
3 files changed
+20 -11

No files matched your search

+2 -2
View File
@@ -13,8 +13,8 @@ android {
applicationId "com.rtbishop.look4sat"
minSdkVersion 21
targetSdkVersion 30
versionCode 210
versionName "2.1.0"
versionCode 211
versionName "2.1.1"
}
buildTypes {
@@ -103,11 +103,16 @@ class SharedViewModel @Inject constructor(
}
fun updateEntriesFromSources(sources: List<TleSource>) {
val sourcesList = if (sources.isEmpty()) {
prefsManager.getDefaultSources()
} else {
sources
}
postAppEvent(Event(0))
viewModelScope.launch {
try {
sourcesRepo.updateSources(sources)
entriesRepo.updateEntriesFromWeb(sources)
sourcesRepo.updateSources(sourcesList)
entriesRepo.updateEntriesFromWeb(sourcesList)
transmittersRepo.updateTransmitters()
} catch (exception: Exception) {
postAppEvent(Event(1))
@@ -150,10 +155,6 @@ class SharedViewModel @Inject constructor(
}
private fun updateDefaultSourcesAndEntries() {
val defaultTleSources = listOf(
TleSource("https://celestrak.com/NORAD/elements/active.txt"),
TleSource("https://amsat.org/tle/current/nasabare.txt")
)
updateEntriesFromSources(defaultTleSources)
updateEntriesFromSources(prefsManager.getDefaultSources())
}
}
@@ -23,6 +23,7 @@ import android.content.SharedPreferences
import android.hardware.GeomagneticField
import androidx.core.content.edit
import com.github.amsacode.predict4java.GroundStationPosition
import com.rtbishop.look4sat.data.TleSource
import javax.inject.Inject
class PrefsManager @Inject constructor(val preferences: SharedPreferences) {
@@ -84,12 +85,19 @@ class PrefsManager @Inject constructor(val preferences: SharedPreferences) {
fun shouldUseCompass(): Boolean {
return preferences.getBoolean(keyCompass, true)
}
fun isFirstLaunch(): Boolean {
return preferences.getBoolean(keyIsFirstLaunch, true)
}
fun setFirstLaunchDone() {
preferences.edit { putBoolean(keyIsFirstLaunch, false) }
}
fun getDefaultSources(): List<TleSource> {
return listOf(
TleSource("https://celestrak.com/NORAD/elements/active.txt"),
TleSource("https://amsat.org/tle/current/nasabare.txt")
)
}
}