From a8f3c5eb7771507fab487fe82f07cc9c2a84d550 Mon Sep 17 00:00:00 2001 From: Arty Bishop Date: Fri, 26 Feb 2021 19:06:13 +0000 Subject: [PATCH] Using liveData builder for appTimer, hilt update --- .../com/rtbishop/look4sat/SharedViewModel.kt | 19 +++++++------------ build.gradle | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/rtbishop/look4sat/SharedViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/SharedViewModel.kt index 72dfa8c9..e6e77c8f 100644 --- a/app/src/main/java/com/rtbishop/look4sat/SharedViewModel.kt +++ b/app/src/main/java/com/rtbishop/look4sat/SharedViewModel.kt @@ -42,7 +42,6 @@ class SharedViewModel @Inject constructor( private val transmittersRepo: TransmittersRepo ) : ViewModel() { - private val _appTimer = MutableLiveData(System.currentTimeMillis()) private val _passes = MutableLiveData>>() private val _appEvent = MutableLiveData>() private var selectedEntries = emptyList() @@ -53,11 +52,16 @@ class SharedViewModel @Inject constructor( updateDefaultSourcesAndEntries() prefsManager.setFirstLaunchDone() } - startApplicationTimer() } fun getAppEvent(): LiveData> = _appEvent - fun getAppTimer(): LiveData = _appTimer + fun getAppTimer() = liveData { + while (true) { + emit(System.currentTimeMillis()) + delay(1000) + } + } + fun getSources() = sourcesRepo.getSources().asLiveData() fun getEntries() = entriesRepo.getEntries().asLiveData() fun getPasses(): LiveData>> = _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 { val gsp = prefsManager.getStationPosition() val predictor = PassPredictor(entry.tle, gsp) diff --git a/build.gradle b/build.gradle index 510e74af..c9df13c5 100644 --- a/build.gradle +++ b/build.gradle @@ -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'