Add compose version of OpenDeviceSettingsDialog

This commit is contained in:
Ensar Sarajčić 2023-10-09 17:30:38 +02:00
parent 9e60e24790
commit 967f731654
2 changed files with 59 additions and 0 deletions

View file

@ -1,7 +1,16 @@
package com.simplemobiletools.commons.dialogs package com.simplemobiletools.commons.dialogs
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.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.sp
import com.simplemobiletools.commons.R import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
import com.simplemobiletools.commons.databinding.DialogOpenDeviceSettingsBinding import com.simplemobiletools.commons.databinding.DialogOpenDeviceSettingsBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.openDeviceSettings import com.simplemobiletools.commons.extensions.openDeviceSettings
@ -23,3 +32,42 @@ class OpenDeviceSettingsDialog(val activity: BaseSimpleActivity, message: String
} }
} }
} }
@Composable
fun OpenDeviceSettingsAlertDialog(
alertDialogState: AlertDialogState,
modifier: Modifier = Modifier,
message: String
) {
val context = LocalContext.current
AlertDialog(
containerColor = dialogContainerColor,
modifier = modifier
.dialogBorder,
onDismissRequest = alertDialogState::hide,
shape = dialogShape,
tonalElevation = dialogElevation,
text = {
Text(
fontSize = 16.sp,
text = message,
)
},
dismissButton = {
TextButton(onClick = {
alertDialogState.hide()
}) {
Text(text = stringResource(id = R.string.close))
}
},
confirmButton = {
TextButton(onClick = {
context.openDeviceSettings()
alertDialogState.hide()
}) {
Text(text = stringResource(id = R.string.go_to_settings))
}
},
)
}

View file

@ -54,6 +54,7 @@ class TestDialogActivity : ComponentActivity() {
ShowButton(getFeatureLockedAlertDialogState(), text = "Feature Locked") ShowButton(getFeatureLockedAlertDialogState(), text = "Feature Locked")
ShowButton(getPurchaseThankYouAlertDialogState(), text = "Purchase thank you") ShowButton(getPurchaseThankYouAlertDialogState(), text = "Purchase thank you")
ShowButton(getLineColorPickerAlertDialogState(), text = "Line color picker") ShowButton(getLineColorPickerAlertDialogState(), text = "Line color picker")
ShowButton(getOpenDeviceSettingsAlertDialogState(), text = "Open device settings")
ShowButton(getColorPickerAlertDialogState(), text = "Color picker") ShowButton(getColorPickerAlertDialogState(), text = "Color picker")
ShowButton(getCallConfirmationAlertDialogState(), text = "Call confirmation") ShowButton(getCallConfirmationAlertDialogState(), text = "Call confirmation")
ShowButton(getChangeDateTimeFormatAlertDialogState(), text = "Change date time") ShowButton(getChangeDateTimeFormatAlertDialogState(), text = "Change date time")
@ -163,6 +164,16 @@ class TestDialogActivity : ComponentActivity() {
} }
} }
@Composable
private fun getOpenDeviceSettingsAlertDialogState() = rememberAlertDialogState().apply {
DialogMember {
OpenDeviceSettingsAlertDialog(
alertDialogState = this,
message = "Test message"
)
}
}
@Composable @Composable
private fun getColorPickerAlertDialogState() = rememberAlertDialogState().apply { private fun getColorPickerAlertDialogState() = rememberAlertDialogState().apply {
DialogMember { DialogMember {