Skip to content

Commit db53e84

Browse files
committed
refactor: show log out dialog
1 parent 2ea3f4c commit db53e84

3 files changed

Lines changed: 8 additions & 16 deletions

File tree

app/src/main/java/io/simplelogin/android/root/AppRoot.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ fun AppRoot(
9595
onOpenDrawer: () -> Unit
9696
) = with(viewModel) {
9797
val backStack by navBackStack.collectAsState()
98-
val dialogStack by dialogStack.collectAsState()
99-
val activeDialog = dialogStack.lastOrNull()
98+
val showLogOutDialog by showLogOutDialog.collectAsState()
10099
val configuration = LocalConfiguration.current
101100
val screenWidth = configuration.screenWidthDp.dp
102101

@@ -235,8 +234,8 @@ fun AppRoot(
235234
}
236235
)
237236

238-
when (activeDialog) {
239-
AppRootDialog.LogOut -> AlertDialog(
237+
if (showLogOutDialog) {
238+
AlertDialog(
240239
onDismissRequest = ::dismissActiveDialog,
241240
title = { Text(stringResource(R.string.sign_out)) },
242241
text = { Text(stringResource(R.string.sign_out_message)) },
@@ -251,8 +250,6 @@ fun AppRoot(
251250
}
252251
}
253252
)
254-
255-
null -> Unit
256253
}
257254
}
258255

app/src/main/java/io/simplelogin/android/root/AppRootDialog.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

app/src/main/java/io/simplelogin/android/root/AppRootViewModel.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class AppRootViewModel @Inject constructor(
4444
private val _createdAlias = Channel<Alias>(Channel.BUFFERED)
4545
val createdAlias = _createdAlias.receiveAsFlow()
4646

47-
private val _dialogStack = MutableStateFlow<List<AppRootDialog>>(emptyList())
48-
val dialogStack = _dialogStack.asStateFlow()
47+
private val _showLogOutDialog = MutableStateFlow(false)
48+
val showLogOutDialog = _showLogOutDialog
4949

5050
val stateFlow: StateFlow<AppRootState> = observeSessionSettings().map {
5151
AppRootState(isReady = true, apiKey = it.apiKey)
@@ -81,15 +81,15 @@ class AppRootViewModel @Inject constructor(
8181

8282
//region Drawer
8383
fun showLogOutDialog() {
84-
_dialogStack.value = listOf(AppRootDialog.LogOut)
84+
_showLogOutDialog.value = true
8585
}
8686

8787
fun dismissActiveDialog() {
88-
_dialogStack.value = _dialogStack.value.dropLast(1)
88+
_showLogOutDialog.value = false
8989
}
9090

9191
fun logOut() {
92-
_dialogStack.value = emptyList()
92+
_showLogOutDialog.value = false
9393
viewModelScope.launch {
9494
logOutUseCase()
9595
}

0 commit comments

Comments
 (0)