Added type reset for satellite selection screen

develop
Arty Bishop 2023-10-01 15:47:12 +01:00
rodzic 6cf89587bb
commit a0776ddc7c
6 zmienionych plików z 13 dodań i 6 usunięć

Wyświetl plik

@ -48,6 +48,7 @@ dependencies {
implementation("androidx.compose.material3:material3:1.1.2") implementation("androidx.compose.material3:material3:1.1.2")
implementation("androidx.compose.runtime:runtime:1.5.2") implementation("androidx.compose.runtime:runtime:1.5.2")
implementation("androidx.compose.ui:ui-tooling-preview: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.lifecycle:lifecycle-viewmodel-compose:2.6.2")
implementation("androidx.navigation:navigation-compose:2.7.3") implementation("androidx.navigation:navigation-compose:2.7.3")

Wyświetl plik

@ -35,13 +35,16 @@ class MainApplication : Application() {
enableStrictMode() enableStrictMode()
super.onCreate() super.onCreate()
container = MainContainer(this) container = MainContainer(this)
// trigger automatic update every 48 hours
container.appScope.launch { checkAutoUpdate() } 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 val settingsRepo = container.settingsRepo
if (settingsRepo.otherSettings.value.stateOfAutoUpdate) { 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) { if (timeDelta > AUTO_UPDATE_DELTA_MS) {
val sdf = SimpleDateFormat("d MMM yyyy - HH:mm:ss", Locale.getDefault()) val sdf = SimpleDateFormat("d MMM yyyy - HH:mm:ss", Locale.getDefault())
println("Started periodic data update on ${sdf.format(Date())}") println("Started periodic data update on ${sdf.format(Date())}")

Wyświetl plik

@ -25,7 +25,8 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier 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.PlatformTextStyle
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight 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() } val clickableModifier = Modifier.clickable { onClick() }
ElevatedCard(modifier = Modifier.size(48.dp)) { ElevatedCard(modifier = Modifier.size(48.dp)) {
Box(modifier = clickableModifier.fillMaxSize(), contentAlignment = Alignment.Center) { Box(modifier = clickableModifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Icon(painter = painterResource(id = iconId), contentDescription = description) Icon(imageVector = ImageVector.vectorResource(iconId), contentDescription = description)
} }
} }
} }

Wyświetl plik

@ -31,12 +31,13 @@ import kotlinx.coroutines.launch
class EntriesViewModel(private val selectionRepo: ISelectionRepo) : ViewModel() { class EntriesViewModel(private val selectionRepo: ISelectionRepo) : ViewModel() {
private val defaultType = "All"
private val _uiState = mutableStateOf( private val _uiState = mutableStateOf(
EntriesState( EntriesState(
isDialogShown = false, isDialogShown = false,
isLoading = true, isLoading = true,
itemsList = emptyList(), itemsList = emptyList(),
currentType = selectionRepo.getCurrentType(), currentType = defaultType,
typesList = selectionRepo.getTypesList(), typesList = selectionRepo.getTypesList(),
takeAction = ::handleAction takeAction = ::handleAction
) )
@ -46,6 +47,7 @@ class EntriesViewModel(private val selectionRepo: ISelectionRepo) : ViewModel()
init { init {
viewModelScope.launch { viewModelScope.launch {
delay(1000) delay(1000)
selectionRepo.setType(defaultType)
selectionRepo.getEntriesFlow().collect { items -> selectionRepo.getEntriesFlow().collect { items ->
_uiState.value = _uiState.value.copy(isLoading = false, itemsList = items) _uiState.value = _uiState.value.copy(isLoading = false, itemsList = items)
} }

Wyświetl plik

@ -59,7 +59,6 @@ class PassesViewModel(
val uiState: State<PassesState> = _uiState val uiState: State<PassesState> = _uiState
init { init {
viewModelScope.launch { satelliteRepo.initRepository() }
viewModelScope.launch { viewModelScope.launch {
satelliteRepo.passes.collect { passes -> satelliteRepo.passes.collect { passes ->
processing?.cancelAndJoin() processing?.cancelAndJoin()

Wyświetl plik

@ -19,6 +19,7 @@ class SelectionRepo(
private val localSource: ILocalSource, private val localSource: ILocalSource,
private val settingsRepo: ISettingsRepo private val settingsRepo: ISettingsRepo
) : ISelectionRepo { ) : ISelectionRepo {
private val currentItems = MutableStateFlow<List<SatItem>>(emptyList()) private val currentItems = MutableStateFlow<List<SatItem>>(emptyList())
private val currentType = MutableStateFlow("All") private val currentType = MutableStateFlow("All")
private val currentQuery = MutableStateFlow("") private val currentQuery = MutableStateFlow("")