Add confirmation dialog before logging out
This commit is contained in:
parent
b6606c1530
commit
99db47a16c
|
@ -2,6 +2,7 @@ package org.unifiedpush.distributor.nextpush.activities.ui
|
|||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
|
@ -9,6 +10,7 @@ import androidx.compose.material3.Icon
|
|||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
|
@ -28,6 +30,8 @@ import org.unifiedpush.distributor.nextpush.activities.publishAction
|
|||
fun AppBarUi(viewModel: ViewModel) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
var showNotificationDialog by remember { mutableStateOf(false) }
|
||||
var showLogoutDialog by remember { mutableStateOf(false) }
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults
|
||||
.topAppBarColors(
|
||||
|
@ -52,7 +56,14 @@ fun AppBarUi(viewModel: ViewModel) {
|
|||
}
|
||||
Dropdown(
|
||||
expanded,
|
||||
actionHandler = { a -> viewModel.publishAction(a) },
|
||||
onRestart = {
|
||||
viewModel.publishAction(AppAction(AppAction.Type.RestartService, null))
|
||||
expanded = false
|
||||
},
|
||||
onLogout = {
|
||||
showLogoutDialog = true
|
||||
expanded = false
|
||||
},
|
||||
onDismiss = {
|
||||
expanded = false
|
||||
},
|
||||
|
@ -78,30 +89,41 @@ fun AppBarUi(viewModel: ViewModel) {
|
|||
}
|
||||
)
|
||||
}
|
||||
if (showLogoutDialog) {
|
||||
LogoutConfirmationDialog(
|
||||
onDismissRequest = {
|
||||
showLogoutDialog = false
|
||||
},
|
||||
onConfirmation = {
|
||||
viewModel.publishAction(AppAction(AppAction.Type.Logout, null))
|
||||
showLogoutDialog = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Dropdown(expanded: Boolean, actionHandler: (AppAction) -> Unit, onDismiss: () -> Unit, onNewChannel: () -> Unit) {
|
||||
fun Dropdown(
|
||||
expanded: Boolean,
|
||||
onRestart: () -> Unit,
|
||||
onLogout: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
onNewChannel: () -> Unit
|
||||
) {
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = onDismiss
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
actionHandler(AppAction(AppAction.Type.RestartService, null))
|
||||
onDismiss()
|
||||
},
|
||||
onClick = onRestart,
|
||||
text = {
|
||||
Text(stringResource(R.string.app_dropdown_restart))
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
actionHandler(AppAction(AppAction.Type.Logout, null))
|
||||
onDismiss()
|
||||
},
|
||||
onClick = onLogout,
|
||||
text = {
|
||||
Text(
|
||||
stringResource(R.string.app_dropdown_logout)
|
||||
|
@ -122,6 +144,41 @@ fun Dropdown(expanded: Boolean, actionHandler: (AppAction) -> Unit, onDismiss: (
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun LogoutConfirmationDialog(onDismissRequest: () -> Unit = {}, onConfirmation: () -> Unit = {}) {
|
||||
AlertDialog(
|
||||
title = {
|
||||
Text(stringResource(R.string.dialog_logout_title))
|
||||
},
|
||||
text = { Text(stringResource(R.string.dialog_logout_content)) },
|
||||
onDismissRequest = {
|
||||
onDismissRequest()
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
onConfirmation()
|
||||
}
|
||||
) {
|
||||
Text(stringResource(android.R.string.ok))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
onDismissRequest()
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
stringResource(android.R.string.cancel)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun AppBarPreview() {
|
||||
|
|
|
@ -51,4 +51,6 @@
|
|||
<string name="bar_unregister_delete_description">Unregister selection</string>
|
||||
<string name="dialog_permissions_title">Permissions</string>
|
||||
<string name="dialog_permissions_content">This application requires notifications permission to work.</string>
|
||||
<string name="dialog_logout_title">Logout</string>
|
||||
<string name="dialog_logout_content">Are you sure you want to log out?</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue