Merge pull request #1864 from esensar/feature/permission-required-dialog
Add compose version of PermissionRequiredDialog
This commit is contained in:
commit
1ddcdfc95a
2 changed files with 85 additions and 0 deletions
|
@ -2,7 +2,19 @@ package com.simplemobiletools.commons.dialogs
|
|||
|
||||
import android.app.Activity
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
|
||||
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
|
||||
import com.simplemobiletools.commons.compose.extensions.MyDevices
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
import com.simplemobiletools.commons.databinding.DialogMessageBinding
|
||||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
|
@ -29,3 +41,63 @@ class PermissionRequiredDialog(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PermissionRequiredAlertDialog(
|
||||
alertDialogState: AlertDialogState,
|
||||
modifier: Modifier = Modifier,
|
||||
text: String,
|
||||
positiveActionCallback: () -> Unit,
|
||||
negativeActionCallback: (() -> Unit)? = null
|
||||
) {
|
||||
AlertDialog(
|
||||
containerColor = dialogContainerColor,
|
||||
modifier = modifier
|
||||
.dialogBorder,
|
||||
onDismissRequest = alertDialogState::hide,
|
||||
shape = dialogShape,
|
||||
tonalElevation = dialogElevation,
|
||||
dismissButton = {
|
||||
TextButton(onClick = {
|
||||
alertDialogState.hide()
|
||||
negativeActionCallback?.invoke()
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.cancel))
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
alertDialogState.hide()
|
||||
positiveActionCallback()
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.grant_permission))
|
||||
}
|
||||
},
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(id = R.string.permission_required),
|
||||
fontSize = 21.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
fontSize = 16.sp,
|
||||
text = text
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@MyDevices
|
||||
private fun PermissionRequiredAlertDialogPreview() {
|
||||
AppThemeSurface {
|
||||
PermissionRequiredAlertDialog(
|
||||
alertDialogState = rememberAlertDialogState(),
|
||||
text = "Test",
|
||||
positiveActionCallback = {},
|
||||
negativeActionCallback = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ class TestDialogActivity : ComponentActivity() {
|
|||
ShowButton(getAddBlockedNumberDialogState(), text = "Add blocked number")
|
||||
ShowButton(getConfirmationAlertDialogState(), text = "Confirmation normal")
|
||||
ShowButton(getConfirmationAdvancedAlertDialogState(), text = "Confirmation advanced")
|
||||
ShowButton(getPermissionRequiredAlertDialogState(), text = "Permission required")
|
||||
ShowButton(getDonateAlertDialogState(), text = "Donate")
|
||||
ShowButton(getFeatureLockedAlertDialogState(), text = "Feature Locked")
|
||||
ShowButton(getPurchaseThankYouAlertDialogState(), text = "Purchase thank you")
|
||||
|
@ -238,6 +239,18 @@ class TestDialogActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun getPermissionRequiredAlertDialogState() =
|
||||
rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
PermissionRequiredAlertDialog(
|
||||
alertDialogState = this,
|
||||
text = "Test permission",
|
||||
positiveActionCallback = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ShowButton(appSideLoadedDialogState: AlertDialogState, text: String) {
|
||||
Button(onClick = appSideLoadedDialogState::show) {
|
||||
|
|
Loading…
Reference in a new issue