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.Icons
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
@ -9,6 +10,7 @@ import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
@ -28,6 +30,8 @@ import org.unifiedpush.distributor.nextpush.activities.publishAction
|
||||||
fun AppBarUi(viewModel: ViewModel) {
|
fun AppBarUi(viewModel: ViewModel) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
var showNotificationDialog by remember { mutableStateOf(false) }
|
var showNotificationDialog by remember { mutableStateOf(false) }
|
||||||
|
var showLogoutDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
colors = TopAppBarDefaults
|
colors = TopAppBarDefaults
|
||||||
.topAppBarColors(
|
.topAppBarColors(
|
||||||
|
@ -52,7 +56,14 @@ fun AppBarUi(viewModel: ViewModel) {
|
||||||
}
|
}
|
||||||
Dropdown(
|
Dropdown(
|
||||||
expanded,
|
expanded,
|
||||||
actionHandler = { a -> viewModel.publishAction(a) },
|
onRestart = {
|
||||||
|
viewModel.publishAction(AppAction(AppAction.Type.RestartService, null))
|
||||||
|
expanded = false
|
||||||
|
},
|
||||||
|
onLogout = {
|
||||||
|
showLogoutDialog = true
|
||||||
|
expanded = false
|
||||||
|
},
|
||||||
onDismiss = {
|
onDismiss = {
|
||||||
expanded = false
|
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
|
@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(
|
DropdownMenu(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
onDismissRequest = onDismiss
|
onDismissRequest = onDismiss
|
||||||
) {
|
) {
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
onClick = {
|
onClick = onRestart,
|
||||||
actionHandler(AppAction(AppAction.Type.RestartService, null))
|
|
||||||
onDismiss()
|
|
||||||
},
|
|
||||||
text = {
|
text = {
|
||||||
Text(stringResource(R.string.app_dropdown_restart))
|
Text(stringResource(R.string.app_dropdown_restart))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
onClick = {
|
onClick = onLogout,
|
||||||
actionHandler(AppAction(AppAction.Type.Logout, null))
|
|
||||||
onDismiss()
|
|
||||||
},
|
|
||||||
text = {
|
text = {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.app_dropdown_logout)
|
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
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun AppBarPreview() {
|
fun AppBarPreview() {
|
||||||
|
|
|
@ -51,4 +51,6 @@
|
||||||
<string name="bar_unregister_delete_description">Unregister selection</string>
|
<string name="bar_unregister_delete_description">Unregister selection</string>
|
||||||
<string name="dialog_permissions_title">Permissions</string>
|
<string name="dialog_permissions_title">Permissions</string>
|
||||||
<string name="dialog_permissions_content">This application requires notifications permission to work.</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>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue