feat: upgrade to pro dialog and radio group dialog
This commit is contained in:
parent
b7dd6ad428
commit
7fe8192c34
8 changed files with 309 additions and 33 deletions
|
@ -21,7 +21,7 @@ fun RadioButtonDialogComponent(
|
|||
modifier: Modifier = Modifier,
|
||||
setSelected: (selected: String) -> Unit,
|
||||
item: String,
|
||||
selected: String
|
||||
selected: String?
|
||||
) {
|
||||
val interactionSource = rememberMutableInteractionSource()
|
||||
val indication = LocalIndication.current
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package com.simplemobiletools.commons.compose.components
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.simplemobiletools.commons.compose.extensions.MyDevices
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
|
||||
@Composable
|
||||
fun RadioGroupDialogComponent(
|
||||
modifier: Modifier = Modifier,
|
||||
items: List<String>,
|
||||
selected: String?,
|
||||
setSelected: (selected: String) -> Unit,
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
items.forEach { item ->
|
||||
RadioButtonDialogComponent(
|
||||
setSelected = setSelected,
|
||||
item = item,
|
||||
selected = selected,
|
||||
modifier = Modifier.padding(vertical = 10.dp, horizontal = 20.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@MyDevices
|
||||
private fun RadioGroupDialogComponentPreview() {
|
||||
AppThemeSurface {
|
||||
RadioGroupDialogComponent(items = listOf(
|
||||
"Test 1",
|
||||
"Test 2",
|
||||
"Test 3",
|
||||
"Test 4",
|
||||
"Test 5",
|
||||
"Test 6",
|
||||
), selected = null, setSelected = {})
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ import androidx.compose.ui.unit.dp
|
|||
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.components.RadioButtonDialogComponent
|
||||
import com.simplemobiletools.commons.compose.components.RadioGroupDialogComponent
|
||||
import com.simplemobiletools.commons.compose.extensions.MyDevices
|
||||
import com.simplemobiletools.commons.compose.extensions.NoRippleTheme
|
||||
import com.simplemobiletools.commons.compose.extensions.rememberMutableInteractionSource
|
||||
|
@ -144,7 +144,7 @@ fun ChangeDateTimeFormatAlertDialog(
|
|||
.padding(bottom = 64.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
RadioGroup(
|
||||
RadioGroupDialogComponent(
|
||||
items = kinds, selected = selected,
|
||||
setSelected = setSelected,
|
||||
modifier = Modifier.padding(
|
||||
|
@ -188,27 +188,7 @@ fun ChangeDateTimeFormatAlertDialog(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RadioGroup(
|
||||
modifier: Modifier = Modifier,
|
||||
items: List<String>,
|
||||
selected: String,
|
||||
setSelected: (selected: String) -> Unit,
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
items.forEach { item ->
|
||||
RadioButtonDialogComponent(
|
||||
setSelected = setSelected,
|
||||
item = item,
|
||||
selected = selected,
|
||||
modifier = Modifier.padding(vertical = 10.dp, horizontal = 20.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private const val timeSample = 1676419200000 // February 15, 2023
|
||||
private fun formatDateSample(format: String): String {
|
||||
|
|
|
@ -6,12 +6,38 @@ import android.view.ViewGroup
|
|||
import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
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.components.RadioGroupDialogComponent
|
||||
import com.simplemobiletools.commons.compose.extensions.BooleanPreviewParameterProvider
|
||||
import com.simplemobiletools.commons.compose.extensions.MyDevices
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
import com.simplemobiletools.commons.databinding.DialogRadioGroupBinding
|
||||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
||||
import com.simplemobiletools.commons.extensions.onGlobalLayout
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
class RadioGroupDialog(
|
||||
val activity: Activity, val items: ArrayList<RadioItem>, val checkedItemId: Int = -1, val titleId: Int = 0,
|
||||
|
@ -71,3 +97,100 @@ class RadioGroupDialog(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun RadioGroupDialogAlertDialog(
|
||||
alertDialogState: AlertDialogState,
|
||||
modifier: Modifier = Modifier,
|
||||
items: ImmutableList<RadioItem>,
|
||||
selectedItemId: Int = -1,
|
||||
titleId: Int = 0,
|
||||
showOKButton: Boolean = false,
|
||||
cancelCallback: (() -> Unit)? = null,
|
||||
callback: (newValue: Any) -> Unit
|
||||
) {
|
||||
val groupTitles = remember { items.map { it.title } }
|
||||
val (selected, setSelected) = remember { mutableStateOf(items.firstOrNull { it.id == selectedItemId }?.title) }
|
||||
val shouldShowOkButton = selectedItemId != -1 && showOKButton
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
cancelCallback?.invoke()
|
||||
alertDialogState.hide()
|
||||
},
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.dialogBackgroundAndShape
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.padding(bottom = if (shouldShowOkButton) 64.dp else 18.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
if (titleId != 0) {
|
||||
Text(
|
||||
text = stringResource(id = titleId),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 24.dp, bottom = 8.dp)
|
||||
.padding(horizontal = 24.dp),
|
||||
color = dialogTextColor,
|
||||
fontSize = 21.sp
|
||||
)
|
||||
}
|
||||
RadioGroupDialogComponent(
|
||||
items = groupTitles,
|
||||
selected = selected,
|
||||
setSelected = { selectedTitle ->
|
||||
setSelected(selectedTitle)
|
||||
callback(getSelectedValue(items, selectedTitle))
|
||||
alertDialogState.hide()
|
||||
},
|
||||
modifier = Modifier.padding(
|
||||
vertical = 16.dp,
|
||||
)
|
||||
)
|
||||
}
|
||||
if (shouldShowOkButton) {
|
||||
TextButton(
|
||||
onClick = {
|
||||
callback(getSelectedValue(items, selected))
|
||||
alertDialogState.hide()
|
||||
},
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomEnd)
|
||||
.padding(top = 16.dp, bottom = 16.dp, end = 16.dp)
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.ok))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun getSelectedValue(
|
||||
items: ImmutableList<RadioItem>,
|
||||
selected: String?
|
||||
) = items.first { it.title == selected }.value
|
||||
|
||||
@Composable
|
||||
@MyDevices
|
||||
private fun RadioGroupDialogAlertDialogPreview(@PreviewParameter(BooleanPreviewParameterProvider::class) showOKButton: Boolean) {
|
||||
AppThemeSurface {
|
||||
RadioGroupDialogAlertDialog(
|
||||
alertDialogState = rememberAlertDialogState(),
|
||||
items = listOf(
|
||||
RadioItem(1, "Test"),
|
||||
RadioItem(2, "Test 2"),
|
||||
RadioItem(3, "Test 3"),
|
||||
).toImmutableList(),
|
||||
callback = {},
|
||||
cancelCallback = {},
|
||||
showOKButton = showOKButton,
|
||||
titleId = R.string.title,
|
||||
selectedItemId = 1
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,27 @@ package com.simplemobiletools.commons.dialogs
|
|||
|
||||
import android.app.Activity
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.AlertDialog
|
||||
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.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
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.andThen
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
import com.simplemobiletools.commons.databinding.DialogUpgradeToProBinding
|
||||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
||||
import com.simplemobiletools.commons.extensions.launchUpgradeToProIntent
|
||||
|
@ -37,3 +57,72 @@ class UpgradeToProDialog(val activity: Activity) {
|
|||
activity.launchViewIntent("https://simplemobiletools.com/upgrade_to_pro")
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun UpgradeToProAlertDialog(
|
||||
alertDialogState: AlertDialogState,
|
||||
modifier: Modifier = Modifier,
|
||||
onMoreInfoClick: () -> Unit,
|
||||
onUpgradeClick: () -> Unit
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {},
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(id = R.string.upgrade_to_pro_long),
|
||||
color = dialogTextColor,
|
||||
fontSize = 16.sp,
|
||||
)
|
||||
},
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(id = R.string.upgrade_to_pro),
|
||||
color = dialogTextColor,
|
||||
fontSize = 21.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
)
|
||||
},
|
||||
tonalElevation = dialogElevation,
|
||||
shape = dialogShape,
|
||||
containerColor = dialogContainerColor,
|
||||
confirmButton = {
|
||||
Row(
|
||||
Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.End
|
||||
) {
|
||||
TextButton(
|
||||
onClick = onMoreInfoClick, // do not dismiss the dialog on pressing More Info
|
||||
modifier = Modifier.weight(0.2f)
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.more_info))
|
||||
}
|
||||
TextButton(
|
||||
onClick = alertDialogState::hide,
|
||||
modifier = Modifier.padding(horizontal = 8.dp)
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.later))
|
||||
}
|
||||
TextButton(
|
||||
onClick = onUpgradeClick andThen alertDialogState::hide,
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.upgrade))
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = modifier,
|
||||
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)
|
||||
)
|
||||
}
|
||||
|
||||
@MyDevices
|
||||
@Composable
|
||||
private fun UpgradeToProAlertDialogPreview() {
|
||||
AppThemeSurface {
|
||||
UpgradeToProAlertDialog(
|
||||
alertDialogState = rememberAlertDialogState(),
|
||||
onMoreInfoClick = {},
|
||||
onUpgradeClick = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
package com.simplemobiletools.commons.models
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
|
||||
@Immutable
|
||||
data class RadioItem(val id: Int, val title: String, val value: Any = id)
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.os.Bundle
|
|||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.activities.ManageBlockedNumbersActivity
|
||||
import com.simplemobiletools.commons.dialogs.BottomSheetChooserDialog
|
||||
import com.simplemobiletools.commons.dialogs.RateStarsDialog
|
||||
import com.simplemobiletools.commons.dialogs.UpgradeToProDialog
|
||||
import com.simplemobiletools.commons.extensions.appLaunched
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.viewBinding
|
||||
|
@ -48,7 +48,7 @@ class MainActivity : BaseSimpleActivity() {
|
|||
startActivity(Intent(this, TestDialogActivity::class.java))
|
||||
}
|
||||
binding.testButton.setOnClickListener {
|
||||
RateStarsDialog(this)
|
||||
UpgradeToProDialog(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,9 @@ 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.*
|
||||
import com.simplemobiletools.commons.extensions.baseConfig
|
||||
import com.simplemobiletools.commons.extensions.redirectToRateUs
|
||||
import com.simplemobiletools.commons.extensions.toHex
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
class TestDialogActivity : ComponentActivity() {
|
||||
|
||||
|
@ -48,12 +47,50 @@ class TestDialogActivity : ComponentActivity() {
|
|||
ShowButton(getCallConfirmationAlertDialogState(), text = "Call confirmation")
|
||||
ShowButton(getChangeDateTimeFormatAlertDialogState(), text = "Change date time")
|
||||
ShowButton(getRateStarsAlertDialogState(), text = "Rate us")
|
||||
ShowButton(getRadioGroupDialogAlertDialogState(), text = "Radio group")
|
||||
ShowButton(getUpgradeToProAlertDialogState(), text = "Upgrade to pro")
|
||||
Spacer(modifier = Modifier.padding(bottom = 16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun getUpgradeToProAlertDialogState() = rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
UpgradeToProAlertDialog(alertDialogState = this, onMoreInfoClick = {
|
||||
launchViewIntent("https://simplemobiletools.com/upgrade_to_pro")
|
||||
}, onUpgradeClick = ::launchUpgradeToProIntent)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun getRadioGroupDialogAlertDialogState() = rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
RadioGroupDialogAlertDialog(
|
||||
alertDialogState = this,
|
||||
items = listOf(
|
||||
RadioItem(1, "Test"),
|
||||
RadioItem(2, "Test 2"),
|
||||
RadioItem(3, "Test 3"),
|
||||
RadioItem(4, "Test 4"),
|
||||
RadioItem(5, "Test 5"),
|
||||
RadioItem(6, "Test 6"),
|
||||
RadioItem(6, "Test 7"),
|
||||
).toImmutableList(),
|
||||
showOKButton = true,
|
||||
selectedItemId = 2,
|
||||
cancelCallback = {
|
||||
Log.d("getRadioGroupDialogAlertDialogState", "cancelCallback")
|
||||
},
|
||||
callback = {
|
||||
Log.d("getRadioGroupDialogAlertDialogState", "Selected $it")
|
||||
},
|
||||
titleId = R.string.title
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun getRateStarsAlertDialogState() = rememberAlertDialogState().apply {
|
||||
DialogMember {
|
||||
|
@ -137,7 +174,6 @@ class TestDialogActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun getAddBlockedNumberDialogState() =
|
||||
rememberAlertDialogState().apply {
|
||||
|
@ -146,7 +182,6 @@ class TestDialogActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun getConfirmationAdvancedAlertDialogState() =
|
||||
rememberAlertDialogState().apply {
|
||||
|
@ -155,7 +190,6 @@ class TestDialogActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun ShowButton(appSideLoadedDialogState: AlertDialogState, text: String) {
|
||||
Button(onClick = appSideLoadedDialogState::show) {
|
||||
|
|
Loading…
Reference in a new issue