From 32906028b2460aeab08ee9ed914edf80dc8b63c0 Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Tue, 10 Oct 2023 13:33:55 +0200 Subject: [PATCH] feat: - create new folder dialog - enter password - folder lock notice - bottom sheet chooser --- .../alert_dialog/AlertDialogsExtensions.kt} | 2 +- .../bottom_sheet/BottomSheetDialogState.kt | 127 +++++++++++++++++ .../BottomSheetDialogsExtensions.kt | 54 +++++++ .../components/RadioButtonDialogComponent.kt | 2 +- .../commons/dialogs/AddBlockedNumberDialog.kt | 3 +- .../commons/dialogs/AppSideloadedDialog.kt | 3 +- .../dialogs/BottomSheetChooserDialog.kt | 124 ++++++++++++++++ .../commons/dialogs/CallConfirmationDialog.kt | 3 +- .../dialogs/ChangeDateTimeFormatDialog.kt | 1 + .../commons/dialogs/ChangeViewTypeDialog.kt | 1 + .../commons/dialogs/ColorPickerDialog.kt | 2 + .../dialogs/ConfirmationAdvancedDialog.kt | 3 +- .../commons/dialogs/ConfirmationDialog.kt | 3 +- .../commons/dialogs/CreateNewFolderDialog.kt | 132 ++++++++++++++++++ .../commons/dialogs/DonateDialog.kt | 3 +- .../commons/dialogs/EnterPasswordDialog.kt | 113 +++++++++++++++ .../commons/dialogs/FeatureLockedDialog.kt | 3 +- .../dialogs/FolderLockingNoticeDialog.kt | 66 +++++++++ .../commons/dialogs/LineColorPickerDialog.kt | 2 + .../dialogs/PermissionRequiredDialog.kt | 3 +- .../commons/dialogs/PurchaseThankYouDialog.kt | 3 +- .../commons/dialogs/RadioGroupDialog.kt | 2 + .../commons/dialogs/RateStarsDialog.kt | 2 + .../commons/dialogs/UpgradeToProDialog.kt | 3 +- .../commons/dialogs/WhatsNewDialog.kt | 3 +- .../commons/dialogs/WritePermissionDialog.kt | 2 + .../commons/models/SimpleListItem.kt | 2 + .../samples/activities/MainActivity.kt | 5 +- .../samples/activities/TestDialogActivity.kt | 75 +++++++++- 29 files changed, 717 insertions(+), 30 deletions(-) rename commons/src/main/kotlin/com/simplemobiletools/commons/{dialogs/DialogsExtensions.kt => compose/alert_dialog/AlertDialogsExtensions.kt} (98%) create mode 100644 commons/src/main/kotlin/com/simplemobiletools/commons/compose/bottom_sheet/BottomSheetDialogState.kt create mode 100644 commons/src/main/kotlin/com/simplemobiletools/commons/compose/bottom_sheet/BottomSheetDialogsExtensions.kt diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/DialogsExtensions.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/compose/alert_dialog/AlertDialogsExtensions.kt similarity index 98% rename from commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/DialogsExtensions.kt rename to commons/src/main/kotlin/com/simplemobiletools/commons/compose/alert_dialog/AlertDialogsExtensions.kt index 6762f0e59..ba03b2f81 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/DialogsExtensions.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/compose/alert_dialog/AlertDialogsExtensions.kt @@ -1,4 +1,4 @@ -package com.simplemobiletools.commons.dialogs +package com.simplemobiletools.commons.compose.alert_dialog import androidx.compose.foundation.background import androidx.compose.foundation.border diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/compose/bottom_sheet/BottomSheetDialogState.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/compose/bottom_sheet/BottomSheetDialogState.kt new file mode 100644 index 000000000..a540d0066 --- /dev/null +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/compose/bottom_sheet/BottomSheetDialogState.kt @@ -0,0 +1,127 @@ +package com.simplemobiletools.commons.compose.bottom_sheet + +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.material3.BottomSheetDefaults +import androidx.compose.material3.SheetValue +import androidx.compose.material3.rememberModalBottomSheetState +import androidx.compose.runtime.* +import androidx.compose.runtime.saveable.mapSaver +import androidx.compose.runtime.saveable.rememberSaveable +import kotlinx.coroutines.launch + +@Composable +fun rememberBottomSheetDialogState( + openBottomSheet: Boolean = false, + skipPartiallyExpanded: Boolean = false, + edgeToEdgeEnabled: Boolean = false, + confirmValueChange: (SheetValue) -> Boolean = { true }, +) = remember { + BottomSheetDialogState( + openBottomSheet = openBottomSheet, + skipPartiallyExpanded = skipPartiallyExpanded, + edgeToEdgeEnabled = edgeToEdgeEnabled, + confirmValueChange = confirmValueChange + ) +} + +@Composable +fun rememberBottomSheetDialogStateSaveable( + openBottomSheet: Boolean = false, + skipPartiallyExpanded: Boolean = false, + edgeToEdgeEnabled: Boolean = false, + confirmValueChange: (SheetValue) -> Boolean = { true }, +) = rememberSaveable(stateSaver = mapSaver(save = { + mapOf( + "skipPartiallyExpanded" to skipPartiallyExpanded, + "edgeToEdgeEnabled" to edgeToEdgeEnabled, + "openBottomSheet" to openBottomSheet, + ) +}, restore = { + BottomSheetDialogState( + openBottomSheet = it["openBottomSheet"] as Boolean, + skipPartiallyExpanded = it["openBottomSheet"] as Boolean, + edgeToEdgeEnabled = it["openBottomSheet"] as Boolean, + ) +})) { + mutableStateOf( + BottomSheetDialogState( + skipPartiallyExpanded = skipPartiallyExpanded, + edgeToEdgeEnabled = edgeToEdgeEnabled, + confirmValueChange = confirmValueChange + ) + ) +} + + +@Stable +class BottomSheetDialogState( + openBottomSheet: Boolean = false, + private val skipPartiallyExpanded: Boolean = false, + private val edgeToEdgeEnabled: Boolean = false, + private val confirmValueChange: (SheetValue) -> Boolean = { true }, +) { + @Composable + fun rememberWindowInsets( + defaultInsets: WindowInsets = BottomSheetDefaults.windowInsets + ) = remember { if (edgeToEdgeEnabled) WindowInsets(0) else defaultInsets } + + @Composable + fun rememberSheetState() = rememberModalBottomSheetState( + skipPartiallyExpanded = skipPartiallyExpanded, + confirmValueChange = confirmValueChange + ) + + var isOpen by mutableStateOf(openBottomSheet) + private set + + private var closeDialog by mutableStateOf(false) + + /** + * Closes the dialog completely, calling [open] will create the dialog + * from scratch. + */ + fun close() { + if (closeDialog) { + closeDialog = false + } + closeDialog = true + } + + fun open() { + if (isOpen) { + isOpen = false + } + isOpen = true + } + + /** + * Minimises the dialog, calling [open] again will + * maximize it, keep in mind you need to call it with the + * appropriate params to avoid jumping if for example: it was fully expanded then + * you've minimised it and now you've called [open] again. + */ + fun minimise() { + isOpen = false + } + + @Composable + fun DialogMember( + content: @Composable () -> Unit + ) { + val bottomSheetState = rememberSheetState() + + LaunchedEffect(closeDialog) { + if (closeDialog) { + launch { bottomSheetState.hide() }.invokeOnCompletion { + if (!bottomSheetState.isVisible) { + minimise() + } + } + } + } + + if (isOpen) { + content() + } + } +} diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/compose/bottom_sheet/BottomSheetDialogsExtensions.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/compose/bottom_sheet/BottomSheetDialogsExtensions.kt new file mode 100644 index 000000000..2caafff4d --- /dev/null +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/compose/bottom_sheet/BottomSheetDialogsExtensions.kt @@ -0,0 +1,54 @@ +package com.simplemobiletools.commons.compose.bottom_sheet + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.CornerSize +import androidx.compose.material3.Surface +import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.simplemobiletools.commons.compose.alert_dialog.dialogContainerColor +import com.simplemobiletools.commons.compose.alert_dialog.dialogElevation +import com.simplemobiletools.commons.compose.theme.LocalTheme +import com.simplemobiletools.commons.compose.theme.Shapes +import com.simplemobiletools.commons.compose.theme.light_grey_stroke +import com.simplemobiletools.commons.compose.theme.model.Theme + +val bottomSheetDialogShape = Shapes.extraLarge.copy( + bottomEnd = CornerSize(0f), + bottomStart = CornerSize(0f) +) + +val Modifier.bottomSheetDialogBorder: Modifier + @ReadOnlyComposable + @Composable get() = + when (LocalTheme.current) { + is Theme.BlackAndWhite -> then(Modifier.border(2.dp, light_grey_stroke, bottomSheetDialogShape)) + else -> Modifier + } + +@Composable +fun BottomSheetSpacerEdgeToEdge() { + Spacer(modifier = Modifier.padding(bottom = 42.dp)) +} + +@Composable +fun BottomSheetDialogSurface( + modifier: Modifier = Modifier, + content: @Composable ColumnScope.() -> Unit +) { + Surface( + modifier = modifier + .fillMaxSize() + .bottomSheetDialogBorder, + shape = bottomSheetDialogShape, + color = dialogContainerColor, + tonalElevation = dialogElevation, + ) { + Column(modifier = Modifier.background(dialogContainerColor)) { + content() + } + } +} diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/compose/components/RadioButtonDialogComponent.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/compose/components/RadioButtonDialogComponent.kt index c32112c43..47018f594 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/compose/components/RadioButtonDialogComponent.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/compose/components/RadioButtonDialogComponent.kt @@ -10,11 +10,11 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +import com.simplemobiletools.commons.compose.alert_dialog.dialogTextColor import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.extensions.rememberMutableInteractionSource import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.SimpleTheme -import com.simplemobiletools.commons.dialogs.dialogTextColor @Composable fun RadioButtonDialogComponent( diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/AddBlockedNumberDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/AddBlockedNumberDialog.kt index a8127db6e..aa1fe2f74 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/AddBlockedNumberDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/AddBlockedNumberDialog.kt @@ -13,8 +13,7 @@ import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.KeyboardType 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.alert_dialog.* import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.models.BlockedNumber diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/AppSideloadedDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/AppSideloadedDialog.kt index e417ee514..4f629dca1 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/AppSideloadedDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/AppSideloadedDialog.kt @@ -16,8 +16,7 @@ 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.alert_dialog.* import com.simplemobiletools.commons.compose.components.LinkifyTextComponent import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.theme.AppThemeSurface diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/BottomSheetChooserDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/BottomSheetChooserDialog.kt index 1b0788fd9..59d3d3b79 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/BottomSheetChooserDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/BottomSheetChooserDialog.kt @@ -2,8 +2,36 @@ package com.simplemobiletools.commons.dialogs import android.os.Bundle import android.view.ViewGroup +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.ListItem +import androidx.compose.material3.ListItemDefaults +import androidx.compose.material3.ModalBottomSheet +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.snapshots.SnapshotStateList +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp import androidx.fragment.app.FragmentManager +import com.simplemobiletools.commons.R import com.simplemobiletools.commons.adapters.setupSimpleListItem +import com.simplemobiletools.commons.compose.alert_dialog.dialogContainerColor +import com.simplemobiletools.commons.compose.alert_dialog.dialogElevation +import com.simplemobiletools.commons.compose.alert_dialog.dialogTextColor +import com.simplemobiletools.commons.compose.bottom_sheet.BottomSheetDialogState +import com.simplemobiletools.commons.compose.bottom_sheet.BottomSheetDialogSurface +import com.simplemobiletools.commons.compose.bottom_sheet.BottomSheetSpacerEdgeToEdge +import com.simplemobiletools.commons.compose.bottom_sheet.bottomSheetDialogShape +import com.simplemobiletools.commons.compose.extensions.MyDevices +import com.simplemobiletools.commons.compose.theme.AppThemeSurface +import com.simplemobiletools.commons.compose.theme.SimpleTheme import com.simplemobiletools.commons.databinding.ItemSimpleListBinding import com.simplemobiletools.commons.fragments.BaseBottomSheetDialogFragment import com.simplemobiletools.commons.models.SimpleListItem @@ -52,3 +80,99 @@ open class BottomSheetChooserDialog : BaseBottomSheetDialogFragment() { } } } + +@Composable +fun ChooserBottomSheetDialog( + bottomSheetDialogState: BottomSheetDialogState, + modifier: Modifier = Modifier, + items: SnapshotStateList, + onItemClicked: (SimpleListItem) -> Unit +) { + val bottomSheetState = bottomSheetDialogState.rememberSheetState() + val windowInsets = bottomSheetDialogState.rememberWindowInsets() + + ModalBottomSheet( + modifier = modifier, + onDismissRequest = bottomSheetDialogState::close, + sheetState = bottomSheetState, + windowInsets = windowInsets, + dragHandle = {}, + shape = bottomSheetDialogShape, + containerColor = dialogContainerColor, + tonalElevation = dialogElevation, + ) { + ChooserScreenContent(items = items, onItemClicked = onItemClicked) + } +} + +@Composable +private fun ChooserScreenContent( + items: SnapshotStateList, + onItemClicked: (SimpleListItem) -> Unit +) { + BottomSheetDialogSurface { + Text( + text = stringResource(id = R.string.please_select_destination), + color = dialogTextColor, + fontSize = 21.sp, + fontWeight = FontWeight.Bold, + modifier = Modifier + .padding(SimpleTheme.dimens.padding.extraLarge) + .padding(top = SimpleTheme.dimens.padding.large) + ) + for (item in items) { + val color = if (item.selected) SimpleTheme.colorScheme.primary else SimpleTheme.colorScheme.onSurface + ListItem( + modifier = Modifier + .clickable { + onItemClicked(item) + }, + headlineContent = { + Text(stringResource(id = item.textRes), color = color) + }, + leadingContent = { + if (item.imageRes != null) { + Image( + painter = painterResource(id = item.imageRes), + contentDescription = stringResource(id = item.textRes), + colorFilter = ColorFilter.tint(color) + ) + } + }, + trailingContent = { + if (item.selected) { + Image( + painter = painterResource(id = R.drawable.ic_check_circle_vector), + contentDescription = null, + colorFilter = ColorFilter.tint(color) + ) + } + }, + colors = ListItemDefaults.colors(containerColor = dialogContainerColor) + ) + } + BottomSheetSpacerEdgeToEdge() + } +} + +@MyDevices +@Composable +private fun ChooserBottomSheetDialogPreview() { + AppThemeSurface { + val list = remember { + mutableStateListOf( + SimpleListItem(1, R.string.record_video, R.drawable.ic_camera_vector), + SimpleListItem(2, R.string.record_audio, R.drawable.ic_microphone_vector, selected = true), + SimpleListItem(4, R.string.choose_contact, R.drawable.ic_add_person_vector) + ) + } + ChooserScreenContent(items = list, onItemClicked = {}) + /* https://issuetracker.google.com/issues/304300690 + ChooserBottomSheetDialog( + bottomSheetDialogState = rememberBottomSheetDialogState(), + items = list, + onItemClicked = {}, + modifier = Modifier.fillMaxSize() + )*/ + } +} diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CallConfirmationDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CallConfirmationDialog.kt index bb9492c50..0da4868c4 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CallConfirmationDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CallConfirmationDialog.kt @@ -27,8 +27,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity -import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState -import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState +import com.simplemobiletools.commons.compose.alert_dialog.* import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.databinding.DialogCallConfirmationBinding diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ChangeDateTimeFormatDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ChangeDateTimeFormatDialog.kt index e19a6947e..3580f53bb 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ChangeDateTimeFormatDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ChangeDateTimeFormatDialog.kt @@ -22,6 +22,7 @@ import androidx.compose.ui.unit.LayoutDirection 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.DialogSurface import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.components.RadioGroupDialogComponent import com.simplemobiletools.commons.compose.extensions.MyDevices diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ChangeViewTypeDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ChangeViewTypeDialog.kt index ebfc555d1..309ef088c 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ChangeViewTypeDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ChangeViewTypeDialog.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.unit.dp import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState +import com.simplemobiletools.commons.compose.alert_dialog.DialogSurface import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.components.RadioGroupDialogComponent import com.simplemobiletools.commons.compose.extensions.MyDevices diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ColorPickerDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ColorPickerDialog.kt index d8e52c690..15ff2e031 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ColorPickerDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ColorPickerDialog.kt @@ -33,6 +33,8 @@ import androidx.core.view.children import androidx.core.view.updateLayoutParams import com.simplemobiletools.commons.R import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState +import com.simplemobiletools.commons.compose.alert_dialog.DialogSurface +import com.simplemobiletools.commons.compose.alert_dialog.dialogBorder import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.extensions.config diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationAdvancedDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationAdvancedDialog.kt index b243dc9b8..b1c1cbaa2 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationAdvancedDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationAdvancedDialog.kt @@ -11,8 +11,7 @@ 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.alert_dialog.* import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.databinding.DialogMessageBinding diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationDialog.kt index 9b435e44e..bd6ef2e9e 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationDialog.kt @@ -12,8 +12,7 @@ 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.alert_dialog.* import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.databinding.DialogMessageBinding diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CreateNewFolderDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CreateNewFolderDialog.kt index f653913c9..3632c1285 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CreateNewFolderDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CreateNewFolderDialog.kt @@ -2,8 +2,26 @@ package com.simplemobiletools.commons.dialogs import android.view.View import androidx.appcompat.app.AlertDialog +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.* +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.platform.LocalContext +import androidx.compose.ui.platform.LocalView +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.activities.BaseSimpleActivity +import com.simplemobiletools.commons.compose.alert_dialog.* +import com.simplemobiletools.commons.compose.extensions.MyDevices +import com.simplemobiletools.commons.compose.theme.AppThemeSurface +import com.simplemobiletools.commons.compose.theme.SimpleTheme import com.simplemobiletools.commons.databinding.DialogCreateNewFolderBinding import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.isRPlus @@ -33,6 +51,7 @@ class CreateNewFolderDialog(val activity: BaseSimpleActivity, val path: String, createFolder("$path/$name", alertDialog) } + else -> activity.toast(R.string.invalid_name) } }) @@ -49,6 +68,7 @@ class CreateNewFolderDialog(val activity: BaseSimpleActivity, val path: String, sendSuccess(alertDialog, path) } } + activity.needsStupidWritePermissions(path) -> activity.handleSAFDialog(path) { if (it) { try { @@ -64,12 +84,14 @@ class CreateNewFolderDialog(val activity: BaseSimpleActivity, val path: String, } } } + File(path).mkdirs() -> sendSuccess(alertDialog, path) isRPlus() && activity.isAStorageRootFolder(path.getParentPath()) -> activity.handleSAFCreateDocumentDialogSdk30(path) { if (it) { sendSuccess(alertDialog, path) } } + else -> activity.toast(activity.getString(R.string.could_not_create_folder, path.getFilenameFromPath())) } } catch (e: Exception) { @@ -82,3 +104,113 @@ class CreateNewFolderDialog(val activity: BaseSimpleActivity, val path: String, alertDialog.dismiss() } } + +@Composable +fun CreateNewFolderAlertDialog( + alertDialogState: AlertDialogState, + modifier: Modifier = Modifier, + path: String, + callback: (path: String) -> Unit +) { + val focusRequester = remember { FocusRequester() } + val context = LocalContext.current + val view = LocalView.current + var title by remember { mutableStateOf("") } + + AlertDialog( + modifier = modifier.dialogBorder, + shape = dialogShape, + containerColor = dialogContainerColor, + tonalElevation = dialogElevation, + onDismissRequest = alertDialogState::hide, + confirmButton = { + TextButton( + onClick = { + alertDialogState.hide() + //add callback + val name = title + when { + name.isEmpty() -> context.toast(R.string.empty_name) + name.isAValidFilename() -> { + val file = File(path, name) + if (file.exists()) { + context.toast(R.string.name_taken) + return@TextButton + } + + callback("$path/$name") + } + + else -> context.toast(R.string.invalid_name) + } + } + ) { + Text(text = stringResource(id = R.string.ok)) + } + }, + dismissButton = { + TextButton( + onClick = alertDialogState::hide + ) { + Text(text = stringResource(id = R.string.cancel)) + } + }, + title = { + Text( + text = stringResource(id = R.string.create_new_folder), + color = dialogTextColor, + fontSize = 21.sp, + fontWeight = FontWeight.Bold, + ) + }, + text = { + Column( + Modifier.fillMaxWidth(), + ) { + OutlinedTextField( + modifier = Modifier + .fillMaxWidth(), + value = if (!view.isInEditMode) "${context.humanizePath(path).trimEnd('/')}/" else path, + onValueChange = {}, + label = { + Text(text = stringResource(id = R.string.folder)) + }, + enabled = false, + colors = OutlinedTextFieldDefaults.colors( + disabledTextColor = dialogTextColor, + disabledBorderColor = SimpleTheme.colorScheme.primary, + disabledLabelColor = SimpleTheme.colorScheme.primary, + ) + ) + + Spacer(modifier = Modifier.padding(vertical = SimpleTheme.dimens.padding.medium)) + + OutlinedTextField( + modifier = Modifier + .fillMaxWidth() + .focusRequester(focusRequester), + value = title, + onValueChange = { + title = it + }, + label = { + Text(text = stringResource(id = R.string.title)) + }, + ) + } + } + ) + ShowKeyboardWhenDialogIsOpenedAndRequestFocus(focusRequester = focusRequester) +} + +@MyDevices +@Composable +private fun CreateNewFolderAlertDialogPreview() { + AppThemeSurface { + CreateNewFolderAlertDialog( + alertDialogState = rememberAlertDialogState(), + path = "Internal/", + callback = {} + ) + } +} diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/DonateDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/DonateDialog.kt index 200953496..c6fc2950d 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/DonateDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/DonateDialog.kt @@ -22,8 +22,7 @@ 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.alert_dialog.* import com.simplemobiletools.commons.compose.components.LinkifyTextComponent import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.extensions.getActivity diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/EnterPasswordDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/EnterPasswordDialog.kt index 073ddbd57..15b6a716d 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/EnterPasswordDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/EnterPasswordDialog.kt @@ -1,8 +1,29 @@ package com.simplemobiletools.commons.dialogs import androidx.appcompat.app.AlertDialog +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Visibility +import androidx.compose.material.icons.filled.VisibilityOff +import androidx.compose.material3.* +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.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.PasswordVisualTransformation +import androidx.compose.ui.text.input.VisualTransformation +import androidx.compose.ui.unit.sp import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.compose.alert_dialog.* +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.DialogEnterPasswordBinding import com.simplemobiletools.commons.extensions.* @@ -52,3 +73,95 @@ class EnterPasswordDialog( view.password.text?.clear() } } + +@Composable +fun EnterPasswordAlertDialog( + alertDialogState: AlertDialogState, + modifier: Modifier = Modifier, + callback: (password: String) -> Unit, + cancelCallback: () -> Unit +) { + val localContext = LocalContext.current + val focusRequester = remember { FocusRequester() } + var password by remember { mutableStateOf("") } + var passwordVisible by remember { mutableStateOf(false) } + val visualTransformation by remember { + derivedStateOf { + if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation() + } + } + AlertDialog( + modifier = modifier.dialogBorder, + shape = dialogShape, + containerColor = dialogContainerColor, + tonalElevation = dialogElevation, + onDismissRequest = alertDialogState::hide andThen cancelCallback, + confirmButton = { + TextButton( + onClick = { + if (password.isEmpty()) { + localContext.toast(R.string.empty_password) + } else { + alertDialogState.hide() + callback(password) + } + } + ) { + Text(text = stringResource(id = R.string.ok)) + } + }, + dismissButton = { + TextButton( + onClick = alertDialogState::hide + ) { + Text(text = stringResource(id = R.string.cancel)) + } + }, + title = { + Text( + text = stringResource(id = R.string.enter_password), + color = dialogTextColor, + fontSize = 21.sp, + fontWeight = FontWeight.Bold, + ) + }, + text = { + OutlinedTextField( + visualTransformation = visualTransformation, + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password), + trailingIcon = { + val image = passwordImageVector(passwordVisible) + IconButton(onClick = { passwordVisible = !passwordVisible }) { + Icon(imageVector = image, null) + } + }, + modifier = Modifier + .fillMaxWidth() + .focusRequester(focusRequester), + value = password, + onValueChange = { + password = it + }, + label = { + Text(text = stringResource(id = R.string.password)) + }, + singleLine = true + ) + } + ) + ShowKeyboardWhenDialogIsOpenedAndRequestFocus(focusRequester = focusRequester) +} + +private fun passwordImageVector(passwordVisible: Boolean) = if (passwordVisible) { + Icons.Filled.Visibility +} else { + Icons.Filled.VisibilityOff +} + +@MyDevices +@Composable +private fun EnterPasswordAlertDialogPreview() { + AppThemeSurface { + EnterPasswordAlertDialog(rememberAlertDialogState(), callback = {}, cancelCallback = {}) + } +} diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FeatureLockedDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FeatureLockedDialog.kt index 8a0fa2c85..5570e14f1 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FeatureLockedDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FeatureLockedDialog.kt @@ -22,8 +22,7 @@ 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.alert_dialog.* import com.simplemobiletools.commons.compose.components.LinkifyTextComponent import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.extensions.composeDonateIntent diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FolderLockingNoticeDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FolderLockingNoticeDialog.kt index c5a6b85e3..52536cbd8 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FolderLockingNoticeDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FolderLockingNoticeDialog.kt @@ -1,7 +1,19 @@ package com.simplemobiletools.commons.dialogs import android.app.Activity +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.* +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.DialogTextviewBinding import com.simplemobiletools.commons.extensions.baseConfig import com.simplemobiletools.commons.extensions.getAlertDialogBuilder @@ -26,3 +38,57 @@ class FolderLockingNoticeDialog(val activity: Activity, val callback: () -> Unit callback() } } + +@Composable +fun FolderLockingNoticeAlertDialog( + alertDialogState: AlertDialogState, + modifier: Modifier = Modifier, + callback: () -> Unit +) { + AlertDialog( + modifier = modifier.dialogBorder, + shape = dialogShape, + containerColor = dialogContainerColor, + tonalElevation = dialogElevation, + onDismissRequest = alertDialogState::hide, + confirmButton = { + TextButton( + onClick = alertDialogState::hide andThen callback + ) { + Text(text = stringResource(id = R.string.ok)) + } + }, + dismissButton = { + TextButton( + onClick = alertDialogState::hide + ) { + Text(text = stringResource(id = R.string.cancel)) + } + }, + title = { + Text( + text = stringResource(id = R.string.disclaimer), + color = dialogTextColor, + fontSize = 21.sp, + fontWeight = FontWeight.Bold, + ) + }, + text = { + Text( + text = stringResource(id = R.string.lock_folder_notice), + color = dialogTextColor, + ) + } + ) +} + +@Composable +@MyDevices +private fun FolderLockingNoticeAlertDialogPreview() { + AppThemeSurface { + FolderLockingNoticeAlertDialog( + alertDialogState = rememberAlertDialogState(), + callback = {}, + ) + } +} diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/LineColorPickerDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/LineColorPickerDialog.kt index 34bebddc9..5746cfe8d 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/LineColorPickerDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/LineColorPickerDialog.kt @@ -25,6 +25,8 @@ import com.google.android.material.appbar.MaterialToolbar import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState +import com.simplemobiletools.commons.compose.alert_dialog.DialogSurface +import com.simplemobiletools.commons.compose.alert_dialog.dialogTextColor import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.theme.AppThemeSurface diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PermissionRequiredDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PermissionRequiredDialog.kt index d4c0acf11..e96e48a53 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PermissionRequiredDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PermissionRequiredDialog.kt @@ -11,8 +11,7 @@ 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.alert_dialog.* import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.databinding.DialogMessageBinding diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PurchaseThankYouDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PurchaseThankYouDialog.kt index 0d94d5e71..f36b58225 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PurchaseThankYouDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PurchaseThankYouDialog.kt @@ -14,8 +14,7 @@ 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.alert_dialog.* import com.simplemobiletools.commons.compose.components.LinkifyTextComponent import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.extensions.composeDonateIntent diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RadioGroupDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RadioGroupDialog.kt index 9bb74a5fd..7cd00f984 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RadioGroupDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RadioGroupDialog.kt @@ -24,6 +24,8 @@ 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.DialogSurface +import com.simplemobiletools.commons.compose.alert_dialog.dialogTextColor import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.components.RadioGroupDialogComponent import com.simplemobiletools.commons.compose.extensions.BooleanPreviewParameterProvider diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RateStarsDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RateStarsDialog.kt index d02e3bd37..c76c5c95e 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RateStarsDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RateStarsDialog.kt @@ -26,6 +26,8 @@ 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.DialogSurface +import com.simplemobiletools.commons.compose.alert_dialog.dialogTextColor import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.theme.AppThemeSurface diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/UpgradeToProDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/UpgradeToProDialog.kt index 79d6a185c..7f57eef55 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/UpgradeToProDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/UpgradeToProDialog.kt @@ -17,8 +17,7 @@ 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.alert_dialog.* import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.extensions.andThen import com.simplemobiletools.commons.compose.theme.AppThemeSurface diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WhatsNewDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WhatsNewDialog.kt index b1cfbc65f..813ca62ca 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WhatsNewDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WhatsNewDialog.kt @@ -16,8 +16,7 @@ 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.alert_dialog.* import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.settings.SettingsHorizontalDivider import com.simplemobiletools.commons.compose.theme.AppThemeSurface diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WritePermissionDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WritePermissionDialog.kt index 40a5c5ab8..3eb3763c3 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WritePermissionDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WritePermissionDialog.kt @@ -32,6 +32,8 @@ import com.bumptech.glide.request.transition.DrawableCrossFadeFactory import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState +import com.simplemobiletools.commons.compose.alert_dialog.DialogSurface +import com.simplemobiletools.commons.compose.alert_dialog.dialogTextColor import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.components.LinkifyTextComponent import com.simplemobiletools.commons.compose.extensions.MyDevices diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/models/SimpleListItem.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/models/SimpleListItem.kt index 5568b971a..fc4e48103 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/models/SimpleListItem.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/models/SimpleListItem.kt @@ -1,9 +1,11 @@ package com.simplemobiletools.commons.models import android.os.Parcelable +import androidx.compose.runtime.Immutable import kotlinx.parcelize.Parcelize @Parcelize +@Immutable data class SimpleListItem(val id: Int, val textRes: Int, val imageRes: Int? = null, val selected: Boolean = false) : Parcelable { companion object { diff --git a/samples/src/main/kotlin/com/simplemobiletools/commons/samples/activities/MainActivity.kt b/samples/src/main/kotlin/com/simplemobiletools/commons/samples/activities/MainActivity.kt index 976e8cae2..1ca8f47e5 100644 --- a/samples/src/main/kotlin/com/simplemobiletools/commons/samples/activities/MainActivity.kt +++ b/samples/src/main/kotlin/com/simplemobiletools/commons/samples/activities/MainActivity.kt @@ -5,7 +5,6 @@ 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.WritePermissionDialog import com.simplemobiletools.commons.extensions.appLaunched import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.viewBinding @@ -48,9 +47,7 @@ class MainActivity : BaseSimpleActivity() { startActivity(Intent(this, TestDialogActivity::class.java)) } binding.testButton.setOnClickListener { - WritePermissionDialog(this, writePermissionDialogMode = WritePermissionDialog.WritePermissionDialogMode.OpenDocumentTreeSDK30(".")){ - - } + launchBottomSheetDemo() } } diff --git a/samples/src/main/kotlin/com/simplemobiletools/commons/samples/activities/TestDialogActivity.kt b/samples/src/main/kotlin/com/simplemobiletools/commons/samples/activities/TestDialogActivity.kt index 9828de43f..f1890365c 100644 --- a/samples/src/main/kotlin/com/simplemobiletools/commons/samples/activities/TestDialogActivity.kt +++ b/samples/src/main/kotlin/com/simplemobiletools/commons/samples/activities/TestDialogActivity.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.commons.samples.activities import android.os.Bundle +import android.os.Environment import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent @@ -11,6 +12,7 @@ import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign @@ -18,6 +20,8 @@ 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.bottom_sheet.BottomSheetDialogState +import com.simplemobiletools.commons.compose.bottom_sheet.rememberBottomSheetDialogState import com.simplemobiletools.commons.compose.extensions.config import com.simplemobiletools.commons.compose.extensions.rateStarsRedirectAndThankYou import com.simplemobiletools.commons.compose.theme.AppThemeSurface @@ -28,6 +32,7 @@ import com.simplemobiletools.commons.extensions.launchViewIntent import com.simplemobiletools.commons.extensions.toHex import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.Release +import com.simplemobiletools.commons.models.SimpleListItem import kotlinx.collections.immutable.toImmutableList class TestDialogActivity : ComponentActivity() { @@ -63,12 +68,64 @@ class TestDialogActivity : ComponentActivity() { ShowButton(getWhatsNewAlertDialogState(), text = "What's new") ShowButton(getChangeViewTypeAlertDialogState(), text = "Change view type") ShowButton(getWritePermissionAlertDialogState(), text = "Write permission dialog") + ShowButton(getCreateNewFolderAlertDialogState(), text = "Create new folder") + ShowButton(getEnterPasswordAlertDialogState(), text = "Enter password") + ShowButton(getFolderLockingNoticeAlertDialogState(), text = "Folder locking notice") + ShowButton(getChooserBottomSheetDialogState(), text = "Bottom sheet chooser") Spacer(modifier = Modifier.padding(bottom = 16.dp)) } } } } + @Composable + private fun getChooserBottomSheetDialogState() = rememberBottomSheetDialogState().apply { + DialogMember { + val list = remember { + mutableStateListOf( + SimpleListItem(1, R.string.record_video, R.drawable.ic_camera_vector), + SimpleListItem(2, R.string.record_audio, R.drawable.ic_microphone_vector, selected = true), + SimpleListItem(4, R.string.choose_contact, R.drawable.ic_add_person_vector) + ) + } + ChooserBottomSheetDialog(bottomSheetDialogState = this, items = list, onItemClicked = { + val indexToUpdate = list.indexOf(it) + list.forEachIndexed { index, simpleListItem -> + if (indexToUpdate == index) { + list[index] = it.copy(selected = true) + } else { + list[index] = simpleListItem.copy(selected = false) + } + } + }) + } + } + + @Composable + private fun getFolderLockingNoticeAlertDialogState() = rememberAlertDialogState().apply { + DialogMember { + FolderLockingNoticeAlertDialog(alertDialogState = this) { + + } + } + } + + @Composable + private fun getEnterPasswordAlertDialogState() = rememberAlertDialogState().apply { + DialogMember { + EnterPasswordAlertDialog(alertDialogState = this, callback = {}, cancelCallback = {}) + } + } + + @Composable + private fun getCreateNewFolderAlertDialogState() = rememberAlertDialogState().apply { + DialogMember { + CreateNewFolderAlertDialog(this, path = Environment.getExternalStorageDirectory().toString()) { + //todo create helper for private fun createFolder(path: String, alertDialog: AlertDialog) to extract bundled logic + } + } + } + @Composable private fun getWritePermissionAlertDialogState() = rememberAlertDialogState().apply { DialogMember { @@ -265,8 +322,8 @@ class TestDialogActivity : ComponentActivity() { } @Composable - private fun ShowButton(appSideLoadedDialogState: AlertDialogState, text: String) { - Button(onClick = appSideLoadedDialogState::show) { + private fun ShowButton(alertDialogState: AlertDialogState, text: String) { + Button(onClick = alertDialogState::show) { Text( text = text, modifier = Modifier @@ -275,4 +332,18 @@ class TestDialogActivity : ComponentActivity() { ) } } + + @Composable + private fun ShowButton(appSideLoadedDialogState: BottomSheetDialogState, text: String) { + Button(onClick = appSideLoadedDialogState::open) { + Text( + text = text, + modifier = Modifier + .fillMaxWidth(), + textAlign = TextAlign.Center + ) + } + } + + }