feat: add few more dialog migrations
This commit is contained in:
parent
3a3e6aa83d
commit
1d10932837
8 changed files with 321 additions and 25 deletions
|
@ -15,8 +15,7 @@ import androidx.compose.ui.unit.dp
|
|||
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
|
||||
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
import com.simplemobiletools.commons.dialogs.AddOrEditBlockedNumberAlertDialog
|
||||
import com.simplemobiletools.commons.dialogs.AppSideLoadedAlertDialog
|
||||
import com.simplemobiletools.commons.dialogs.*
|
||||
|
||||
class TestDialogActivity : ComponentActivity() {
|
||||
|
||||
|
@ -24,16 +23,11 @@ class TestDialogActivity : ComponentActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
AppThemeSurface {
|
||||
val appSideLoadedDialogState = rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
AppSideLoadedAlertDialog(onDownloadClick = {}, onCancelClick = {}, alertDialogState = this)
|
||||
}
|
||||
}
|
||||
val addBlockedNumberDialogState = rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
AddOrEditBlockedNumberAlertDialog(blockedNumber = null, deleteBlockedNumber = {}, addBlockedNumber = {}, alertDialogState = this)
|
||||
}
|
||||
}
|
||||
val appSideLoadedDialogState = getAppSideLoadedDialogState()
|
||||
val addBlockedNumberDialogState = getAddBlockedNumberDialogState()
|
||||
val confirmationAdvancedAlertDialogState = getConfirmationAdvancedAlertDialogState()
|
||||
val confirmationAlertDialogState = getConfirmationAlertDialogState()
|
||||
val donateAlertDialogState = getDonateAlertDialogState()
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
|
@ -44,12 +38,58 @@ class TestDialogActivity : ComponentActivity() {
|
|||
Spacer(modifier = Modifier.padding(top = 16.dp))
|
||||
ShowButton(appSideLoadedDialogState, text = "App side loaded dialog")
|
||||
ShowButton(addBlockedNumberDialogState, text = "Add blocked number")
|
||||
ShowButton(confirmationAlertDialogState, text = "Confirmation normal")
|
||||
ShowButton(confirmationAdvancedAlertDialogState, text = "Confirmation advanced")
|
||||
ShowButton(donateAlertDialogState, text = "Donate")
|
||||
Spacer(modifier = Modifier.padding(bottom = 16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun getDonateAlertDialogState() =
|
||||
rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
DonateAlertDialog(alertDialogState = this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun getConfirmationAlertDialogState() = rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
ConfirmationAlertDialog(alertDialogState = this, callback = {}, dialogTitle = "Some fancy title")
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun getAppSideLoadedDialogState() =
|
||||
rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
AppSideLoadedAlertDialog(onDownloadClick = {}, onCancelClick = {}, alertDialogState = this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun getAddBlockedNumberDialogState() =
|
||||
rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
AddOrEditBlockedNumberAlertDialog(blockedNumber = null, deleteBlockedNumber = {}, addBlockedNumber = {}, alertDialogState = this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun getConfirmationAdvancedAlertDialogState() =
|
||||
rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
ConfirmationAdvancedAlertDialog(alertDialogState = this, callback = {})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun ShowButton(appSideLoadedDialogState: AlertDialogState, text: String) {
|
||||
Button(onClick = appSideLoadedDialogState::show) {
|
||||
|
|
|
@ -2,14 +2,16 @@ package com.simplemobiletools.commons.dialogs
|
|||
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
|
||||
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
|
||||
|
@ -32,7 +34,7 @@ fun AddOrEditBlockedNumberAlertDialog(
|
|||
modifier = Modifier
|
||||
.dialogWidth
|
||||
.dialogBorder,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
||||
properties = dialogProperties,
|
||||
onDismissRequest = alertDialogState::hide,
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
|
@ -73,7 +75,7 @@ fun AddOrEditBlockedNumberAlertDialog(
|
|||
supportingText = {
|
||||
Text(
|
||||
text = stringResource(id = R.string.add_blocked_number_helper_text),
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
color = dialogTextColor
|
||||
)
|
||||
},
|
||||
label = {
|
||||
|
|
|
@ -15,7 +15,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
|
||||
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
|
||||
|
@ -77,7 +76,7 @@ fun AppSideLoadedAlertDialog(
|
|||
modifier = Modifier
|
||||
.dialogWidth
|
||||
.dialogBorder,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
||||
properties = dialogProperties,
|
||||
onDismissRequest = alertDialogState::hide,
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
|
|
|
@ -2,7 +2,18 @@ package com.simplemobiletools.commons.dialogs
|
|||
|
||||
import android.app.Activity
|
||||
import androidx.appcompat.app.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.unit.sp
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
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
|
||||
|
@ -46,3 +57,61 @@ class ConfirmationAdvancedDialog(
|
|||
callback(false)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ConfirmationAdvancedAlertDialog(
|
||||
alertDialogState: AlertDialogState,
|
||||
message: String = "",
|
||||
messageId: Int = R.string.proceed_with_deletion,
|
||||
positive: Int = R.string.yes,
|
||||
negative: Int = R.string.no,
|
||||
cancelOnTouchOutside: Boolean = true,
|
||||
callback: (result: Boolean) -> Unit
|
||||
) {
|
||||
|
||||
androidx.compose.material3.AlertDialog(
|
||||
containerColor = dialogContainerColor,
|
||||
modifier = Modifier
|
||||
.dialogWidth
|
||||
.dialogBorder,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false, dismissOnClickOutside = cancelOnTouchOutside),
|
||||
onDismissRequest = {
|
||||
alertDialogState.hide()
|
||||
callback(false)
|
||||
},
|
||||
shape = dialogShape,
|
||||
tonalElevation = dialogElevation,
|
||||
dismissButton = {
|
||||
TextButton(onClick = {
|
||||
alertDialogState.hide()
|
||||
callback(false)
|
||||
}) {
|
||||
Text(text = stringResource(id = negative))
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
alertDialogState.hide()
|
||||
callback(true)
|
||||
}) {
|
||||
Text(text = stringResource(id = positive))
|
||||
}
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = message.ifEmpty { stringResource(id = messageId) },
|
||||
fontSize = 16.sp,
|
||||
color = dialogTextColor,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@MyDevices
|
||||
private fun ConfirmationAdvancedAlertDialogPreview() {
|
||||
AppThemeSurface {
|
||||
ConfirmationAdvancedAlertDialog(alertDialogState = rememberAlertDialogState(),
|
||||
callback = {})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,19 @@ package com.simplemobiletools.commons.dialogs
|
|||
|
||||
import android.app.Activity
|
||||
import androidx.appcompat.app.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 androidx.compose.ui.window.DialogProperties
|
||||
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
|
||||
|
@ -18,8 +30,13 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
|
|||
* @param callback an anonymous function
|
||||
*/
|
||||
class ConfirmationDialog(
|
||||
activity: Activity, message: String = "", messageId: Int = R.string.proceed_with_deletion, positive: Int = R.string.yes,
|
||||
negative: Int = R.string.no, val cancelOnTouchOutside: Boolean = true, dialogTitle: String = "", val callback: () -> Unit
|
||||
activity: Activity,
|
||||
message: String = "",
|
||||
messageId: Int = R.string.proceed_with_deletion, positive: Int = R.string.yes,
|
||||
negative: Int = R.string.no,
|
||||
val cancelOnTouchOutside: Boolean = true,
|
||||
dialogTitle: String = "",
|
||||
val callback: () -> Unit
|
||||
) {
|
||||
private var dialog: AlertDialog? = null
|
||||
|
||||
|
@ -46,3 +63,72 @@ class ConfirmationDialog(
|
|||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ConfirmationAlertDialog(
|
||||
alertDialogState: AlertDialogState,
|
||||
message: String = "",
|
||||
messageId: Int = R.string.proceed_with_deletion,
|
||||
positive: Int = R.string.yes,
|
||||
negative: Int = R.string.no,
|
||||
cancelOnTouchOutside: Boolean = true,
|
||||
dialogTitle: String = "",
|
||||
callback: () -> Unit
|
||||
) {
|
||||
|
||||
androidx.compose.material3.AlertDialog(
|
||||
containerColor = dialogContainerColor,
|
||||
modifier = Modifier
|
||||
.dialogWidth
|
||||
.dialogBorder,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false, dismissOnClickOutside = cancelOnTouchOutside),
|
||||
onDismissRequest = {
|
||||
alertDialogState.hide()
|
||||
callback()
|
||||
},
|
||||
shape = dialogShape,
|
||||
tonalElevation = dialogElevation,
|
||||
dismissButton = {
|
||||
TextButton(onClick = {
|
||||
alertDialogState.hide()
|
||||
callback()
|
||||
}) {
|
||||
Text(text = stringResource(id = negative))
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
alertDialogState.hide()
|
||||
callback()
|
||||
}) {
|
||||
Text(text = stringResource(id = positive))
|
||||
}
|
||||
},
|
||||
title = {
|
||||
if (dialogTitle.isNotBlank() || dialogTitle.isNotEmpty()) {
|
||||
Text(
|
||||
text = dialogTitle,
|
||||
color = dialogTextColor,
|
||||
fontSize = 21.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
)
|
||||
}
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = message.ifEmpty { stringResource(id = messageId) },
|
||||
fontSize = 16.sp,
|
||||
color = dialogTextColor,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@MyDevices
|
||||
private fun ConfirmationAlertDialogPreview() {
|
||||
AppThemeSurface {
|
||||
ConfirmationAlertDialog(alertDialogState = rememberAlertDialogState(),
|
||||
callback = {})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import androidx.compose.ui.graphics.Color
|
|||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.platform.SoftwareKeyboardController
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.simplemobiletools.commons.compose.theme.LocalTheme
|
||||
import com.simplemobiletools.commons.compose.theme.Shapes
|
||||
import com.simplemobiletools.commons.compose.theme.light_grey_stroke
|
||||
|
@ -31,6 +32,10 @@ val dialogElevation = 0.dp
|
|||
val Modifier.dialogWidth: Modifier
|
||||
get() = then(Modifier.fillMaxWidth(0.9f))
|
||||
|
||||
val dialogProperties get() = DialogProperties(usePlatformDefaultWidth = false)
|
||||
|
||||
val dialogTextColor @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.onSurface
|
||||
|
||||
val Modifier.dialogBorder: Modifier
|
||||
@ReadOnlyComposable
|
||||
@Composable get() =
|
||||
|
|
|
@ -3,13 +3,39 @@ package com.simplemobiletools.commons.dialogs
|
|||
import android.app.Activity
|
||||
import android.text.Html
|
||||
import android.text.method.LinkMovementMethod
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Favorite
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
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.extensions.getActivity
|
||||
import com.simplemobiletools.commons.compose.extensions.rememberMutableInteractionSource
|
||||
import com.simplemobiletools.commons.compose.screens.LinkifyText
|
||||
import com.simplemobiletools.commons.compose.screens.stringFromHTML
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
import com.simplemobiletools.commons.databinding.DialogDonateBinding
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
||||
class DonateDialog(val activity: Activity) {
|
||||
init {
|
||||
val view = DialogDonateBinding.inflate(activity.layoutInflater,null, false).apply {
|
||||
val view = DialogDonateBinding.inflate(activity.layoutInflater, null, false).apply {
|
||||
dialogDonateImage.applyColorFilter(activity.getProperTextColor())
|
||||
dialogDonateText.text = Html.fromHtml(activity.getString(R.string.donate_short))
|
||||
dialogDonateText.movementMethod = LinkMovementMethod.getInstance()
|
||||
|
@ -26,3 +52,74 @@ class DonateDialog(val activity: Activity) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DonateAlertDialog(alertDialogState: AlertDialogState) {
|
||||
val localContext = LocalContext.current.getActivity()
|
||||
val donateIntent = {
|
||||
localContext.launchViewIntent(R.string.thank_you_url)
|
||||
}
|
||||
androidx.compose.material3.AlertDialog(
|
||||
containerColor = dialogContainerColor,
|
||||
modifier = Modifier
|
||||
.dialogWidth
|
||||
.dialogBorder,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false, dismissOnClickOutside = false, dismissOnBackPress = false),
|
||||
onDismissRequest = {},
|
||||
shape = dialogShape,
|
||||
tonalElevation = dialogElevation,
|
||||
dismissButton = {
|
||||
TextButton(onClick = {
|
||||
alertDialogState.hide()
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.later))
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
donateIntent()
|
||||
alertDialogState.hide()
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.purchase))
|
||||
}
|
||||
},
|
||||
title = {
|
||||
Box(
|
||||
Modifier.fillMaxWidth(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Image(
|
||||
Icons.Filled.Favorite,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.size(56.dp)
|
||||
.clickable(
|
||||
indication = null,
|
||||
interactionSource = rememberMutableInteractionSource(),
|
||||
onClick = {
|
||||
donateIntent()
|
||||
alertDialogState.hide()
|
||||
}
|
||||
),
|
||||
colorFilter = ColorFilter.tint(dialogTextColor)
|
||||
)
|
||||
}
|
||||
},
|
||||
text = {
|
||||
val source = stringResource(id = R.string.donate_short)
|
||||
LinkifyText(fontSize = 16.sp, removeUnderlines = false) {
|
||||
stringFromHTML(source)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@MyDevices
|
||||
private fun DonateAlertDialogPreview() {
|
||||
AppThemeSurface {
|
||||
DonateAlertDialog(alertDialogState = rememberAlertDialogState())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ import android.os.Bundle
|
|||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.activities.ManageBlockedNumbersActivity
|
||||
import com.simplemobiletools.commons.activities.TestDialogActivity
|
||||
import com.simplemobiletools.commons.dialogs.AppSideloadedDialog
|
||||
import com.simplemobiletools.commons.dialogs.BottomSheetChooserDialog
|
||||
import com.simplemobiletools.commons.dialogs.DonateDialog
|
||||
import com.simplemobiletools.commons.extensions.appLaunched
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.viewBinding
|
||||
|
@ -90,8 +90,6 @@ class MainActivity : BaseSimpleActivity() {
|
|||
super.onResume()
|
||||
setupToolbar(binding.mainToolbar)
|
||||
|
||||
AppSideloadedDialog(this) {
|
||||
|
||||
}
|
||||
DonateDialog(this)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue