Skip to content

Commit

Permalink
fix: buggy skip button
Browse files Browse the repository at this point in the history
  • Loading branch information
jd1378 committed Jul 4, 2024
1 parent a8add58 commit 17494ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ fun Permissions(
else -> {}
}
}
LaunchedEffect(uiState.userSettings.isSetupFinished) {
if (uiState.userSettings.isSetupFinished) {
onNavigateToRoute(MainDestinations.HOME_ROUTE)
}
}

Scaffold(
topBar = {
Expand All @@ -97,11 +102,11 @@ fun Permissions(
},
bottomBar = {
if (setupMode) {
SkipDialog(show = uiState.showSkipWarning) { viewModel.onSetupFinish(upPress) }
SkipDialog(show = uiState.showSkipWarning) { viewModel.onSetupFinish() }
Row(Modifier.navigationBarsPadding().padding(10.dp)) {
Spacer(modifier = Modifier.weight(1f))
if (uiState.hasDoneAllSteps) {
Button(onClick = { viewModel.onSetupFinish(upPress) }) {
Button(onClick = { viewModel.onSetupFinish() }) {
Text(text = stringResource(R.string.finish))
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import io.github.jd1378.otphelper.R
import io.github.jd1378.otphelper.UserSettings
import io.github.jd1378.otphelper.repository.UserSettingsRepository
import io.github.jd1378.otphelper.utils.AutostartHelper
import io.github.jd1378.otphelper.utils.SettingsHelper
Expand All @@ -34,6 +35,7 @@ data class PermissionsUiState(
val hasRestrictedSettings: Boolean = false,
val showSkipWarning: Boolean = false,
val hasDoneAllSteps: Boolean = false,
val userSettings: UserSettings = UserSettings.getDefaultInstance(),
)

@HiltViewModel
Expand All @@ -59,21 +61,25 @@ constructor(
_hasAutoStartSettings,
_hasRestrictedSettings,
_showSkipWarning,
userSettingsRepository.userSettings,
) {
hasNotifPerm,
hasNotifListenerPerm,
isIgnoringBatteryOptimizations,
hasAutostartSettings,
hasRestrictedSettings,
showSkipWarning ->
showSkipWarning,
userSettings ->
PermissionsUiState(
hasNotifPerm,
hasNotifListenerPerm,
isIgnoringBatteryOptimizations,
hasAutostartSettings,
hasRestrictedSettings,
showSkipWarning,
hasNotifPerm && hasNotifListenerPerm && isIgnoringBatteryOptimizations)
hasNotifPerm && hasNotifListenerPerm && isIgnoringBatteryOptimizations,
userSettings,
)
}
.stateIn(
scope = viewModelScope,
Expand Down Expand Up @@ -114,12 +120,9 @@ constructor(
}
}

fun onSetupFinish(upPress: () -> Unit) {
fun onSetupFinish() {
_showSkipWarning.update { false }
viewModelScope.launch {
userSettingsRepository.setIsSetupFinished(true)
upPress()
}
viewModelScope.launch { userSettingsRepository.setIsSetupFinished(true) }
}

fun onSetupSkipPressed() {
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/io/github/jd1378/otphelper/utils/Combine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package io.github.jd1378.otphelper.utils

import kotlinx.coroutines.flow.Flow

inline fun <T1, T2, T3, T4, T5, T6, R> combine(
inline fun <T1, T2, T3, T4, T5, T6, T7, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
flow3: Flow<T3>,
flow4: Flow<T4>,
flow5: Flow<T5>,
flow6: Flow<T6>,
crossinline transform: suspend (T1, T2, T3, T4, T5, T6) -> R
flow7: Flow<T7>,
crossinline transform: suspend (T1, T2, T3, T4, T5, T6, T7) -> R
): Flow<R> {
return kotlinx.coroutines.flow.combine(flow, flow2, flow3, flow4, flow5, flow6) { args: Array<*>
->
return kotlinx.coroutines.flow.combine(flow, flow2, flow3, flow4, flow5, flow6, flow7) {
args: Array<*> ->
@Suppress("UNCHECKED_CAST")
transform(
args[0] as T1,
Expand All @@ -21,6 +22,7 @@ inline fun <T1, T2, T3, T4, T5, T6, R> combine(
args[3] as T4,
args[4] as T5,
args[5] as T6,
args[6] as T7,
)
}
}

0 comments on commit 17494ec

Please sign in to comment.