Using liveData builder for appTimer, hilt update

This commit is contained in:
Arty Bishop committed 2021-02-26 19:15:47 +00:00
1 parent c929e94d0e
commit a8f3c5eb77
2 files changed
+9 -14

No files matched your search

@@ -42,7 +42,6 @@ class SharedViewModel @Inject constructor(
private val transmittersRepo: TransmittersRepo
) : ViewModel() {
private val _appTimer = MutableLiveData(System.currentTimeMillis())
private val _passes = MutableLiveData<Result<MutableList<SatPass>>>()
private val _appEvent = MutableLiveData<Event<Int>>()
private var selectedEntries = emptyList<SatEntry>()
@@ -53,11 +52,16 @@ class SharedViewModel @Inject constructor(
updateDefaultSourcesAndEntries()
prefsManager.setFirstLaunchDone()
}
startApplicationTimer()
}
fun getAppEvent(): LiveData<Event<Int>> = _appEvent
fun getAppTimer(): LiveData<Long> = _appTimer
fun getAppTimer() = liveData {
while (true) {
emit(System.currentTimeMillis())
delay(1000)
}
}
fun getSources() = sourcesRepo.getSources().asLiveData()
fun getEntries() = entriesRepo.getEntries().asLiveData()
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
@@ -122,15 +126,6 @@ class SharedViewModel @Inject constructor(
_appEvent.value = event
}
private fun startApplicationTimer(tickMillis: Long = 1000L) {
viewModelScope.launch(Dispatchers.IO) {
while (true) {
delay(tickMillis)
_appTimer.postValue(System.currentTimeMillis())
}
}
}
private fun getPasses(entry: SatEntry, dateNow: Date): MutableList<SatPass> {
val gsp = prefsManager.getStationPosition()
val predictor = PassPredictor(entry.tle, gsp)
+2 -2
View File
@@ -1,7 +1,7 @@
buildscript {
ext {
gradle_version = '4.1.2'
gradle_plugin_version = '1.4.30'
gradle_plugin_version = '1.4.31'
material_version = '1.3.0'
constraint_layout_version = '2.0.4'
lifecycle_version = '2.3.0'
@@ -9,7 +9,7 @@ buildscript {
preference_version = '1.1.1'
view_pager2_version = '1.0.0'
room_version = '2.2.6'
hilt_version = '2.32-alpha'
hilt_version = '2.33-beta'
hilt_viewmodel_version = '1.0.0-alpha03'
retrofit_version = '2.9.0'
osmdroid_version = '6.1.10'