kopia lustrzana https://github.com/rt-bishop/Look4Sat
Added type reset for satellite selection screen
rodzic
6cf89587bb
commit
a0776ddc7c
|
@ -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")
|
||||
|
||||
|
|
|
@ -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())}")
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ class PassesViewModel(
|
|||
val uiState: State<PassesState> = _uiState
|
||||
|
||||
init {
|
||||
viewModelScope.launch { satelliteRepo.initRepository() }
|
||||
viewModelScope.launch {
|
||||
satelliteRepo.passes.collect { passes ->
|
||||
processing?.cancelAndJoin()
|
||||
|
|
|
@ -19,6 +19,7 @@ class SelectionRepo(
|
|||
private val localSource: ILocalSource,
|
||||
private val settingsRepo: ISettingsRepo
|
||||
) : ISelectionRepo {
|
||||
|
||||
private val currentItems = MutableStateFlow<List<SatItem>>(emptyList())
|
||||
private val currentType = MutableStateFlow("All")
|
||||
private val currentQuery = MutableStateFlow("")
|
||||
|
|
Ładowanie…
Reference in New Issue