From a0776ddc7c1eb1b445c1747ef2aeddbba530a7ec Mon Sep 17 00:00:00 2001 From: Arty Bishop Date: Sun, 1 Oct 2023 15:47:12 +0100 Subject: [PATCH] Added type reset for satellite selection screen --- app/build.gradle.kts | 1 + app/src/main/java/com/rtbishop/look4sat/MainApplication.kt | 7 +++++-- .../rtbishop/look4sat/presentation/components/Common.kt | 5 +++-- .../look4sat/presentation/entries/EntriesViewModel.kt | 4 +++- .../look4sat/presentation/passes/PassesViewModel.kt | 1 - .../com/rtbishop/look4sat/data/repository/SelectionRepo.kt | 1 + 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7c8f9081..784745e5 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -48,6 +48,7 @@ dependencies { implementation("androidx.compose.material3:material3:1.1.2") implementation("androidx.compose.runtime:runtime:1.5.2") implementation("androidx.compose.ui:ui-tooling-preview:1.5.2") + implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.2") implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2") implementation("androidx.navigation:navigation-compose:2.7.3") diff --git a/app/src/main/java/com/rtbishop/look4sat/MainApplication.kt b/app/src/main/java/com/rtbishop/look4sat/MainApplication.kt index b3457a89..9b37cb76 100644 --- a/app/src/main/java/com/rtbishop/look4sat/MainApplication.kt +++ b/app/src/main/java/com/rtbishop/look4sat/MainApplication.kt @@ -35,13 +35,16 @@ class MainApplication : Application() { enableStrictMode() super.onCreate() container = MainContainer(this) + // trigger automatic update every 48 hours container.appScope.launch { checkAutoUpdate() } + // load satellite data on every app start + container.appScope.launch { container.satelliteRepo.initRepository() } } - private suspend fun checkAutoUpdate() { + private suspend fun checkAutoUpdate(timeNow: Long = System.currentTimeMillis()) { val settingsRepo = container.settingsRepo if (settingsRepo.otherSettings.value.stateOfAutoUpdate) { - val timeDelta = System.currentTimeMillis() - settingsRepo.databaseState.value.updateTimestamp + val timeDelta = timeNow - settingsRepo.databaseState.value.updateTimestamp if (timeDelta > AUTO_UPDATE_DELTA_MS) { val sdf = SimpleDateFormat("d MMM yyyy - HH:mm:ss", Locale.getDefault()) println("Started periodic data update on ${sdf.format(Date())}") diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/components/Common.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/components/Common.kt index 63b23010..f3689f92 100644 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/components/Common.kt +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/components/Common.kt @@ -25,7 +25,8 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.vectorResource import androidx.compose.ui.text.PlatformTextStyle import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight @@ -98,7 +99,7 @@ fun CardIcon(onClick: () -> Unit, iconId: Int, description: String? = null) { val clickableModifier = Modifier.clickable { onClick() } ElevatedCard(modifier = Modifier.size(48.dp)) { Box(modifier = clickableModifier.fillMaxSize(), contentAlignment = Alignment.Center) { - Icon(painter = painterResource(id = iconId), contentDescription = description) + Icon(imageVector = ImageVector.vectorResource(iconId), contentDescription = description) } } } diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesViewModel.kt index 014b89e6..70ca2949 100644 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesViewModel.kt +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/entries/EntriesViewModel.kt @@ -31,12 +31,13 @@ import kotlinx.coroutines.launch class EntriesViewModel(private val selectionRepo: ISelectionRepo) : ViewModel() { + private val defaultType = "All" private val _uiState = mutableStateOf( EntriesState( isDialogShown = false, isLoading = true, itemsList = emptyList(), - currentType = selectionRepo.getCurrentType(), + currentType = defaultType, typesList = selectionRepo.getTypesList(), takeAction = ::handleAction ) @@ -46,6 +47,7 @@ class EntriesViewModel(private val selectionRepo: ISelectionRepo) : ViewModel() init { viewModelScope.launch { delay(1000) + selectionRepo.setType(defaultType) selectionRepo.getEntriesFlow().collect { items -> _uiState.value = _uiState.value.copy(isLoading = false, itemsList = items) } diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/passes/PassesViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/passes/PassesViewModel.kt index 90535c28..f43509f9 100644 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/passes/PassesViewModel.kt +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/passes/PassesViewModel.kt @@ -59,7 +59,6 @@ class PassesViewModel( val uiState: State = _uiState init { - viewModelScope.launch { satelliteRepo.initRepository() } viewModelScope.launch { satelliteRepo.passes.collect { passes -> processing?.cancelAndJoin() diff --git a/data/src/main/java/com/rtbishop/look4sat/data/repository/SelectionRepo.kt b/data/src/main/java/com/rtbishop/look4sat/data/repository/SelectionRepo.kt index 692a01aa..4ee5d9a6 100644 --- a/data/src/main/java/com/rtbishop/look4sat/data/repository/SelectionRepo.kt +++ b/data/src/main/java/com/rtbishop/look4sat/data/repository/SelectionRepo.kt @@ -19,6 +19,7 @@ class SelectionRepo( private val localSource: ILocalSource, private val settingsRepo: ISettingsRepo ) : ISelectionRepo { + private val currentItems = MutableStateFlow>(emptyList()) private val currentType = MutableStateFlow("All") private val currentQuery = MutableStateFlow("")