From 187fd63a75745828d5fbb8b72ab673cb4635f583 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Fri, 21 Jun 2024 11:04:34 -0300 Subject: [PATCH] Add content for disk full alert for backups. --- .../backup/v2/ui/BackupAlertBottomSheet.kt | 57 ++++++++++++++++--- .../backup/v2/ui/status/BackupStatus.kt | 51 ++++++++++------- app/src/main/res/values/strings.xml | 16 ++++++ 3 files changed, 97 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ui/BackupAlertBottomSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ui/BackupAlertBottomSheet.kt index a0bb482a7d..16db7954e5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ui/BackupAlertBottomSheet.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ui/BackupAlertBottomSheet.kt @@ -26,6 +26,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.core.os.BundleCompat import androidx.core.os.bundleOf @@ -81,6 +82,7 @@ class BackupAlertBottomSheet : ComposeBottomSheetDialogFragment() { BackupAlert.MEDIA_WILL_BE_DELETED_TODAY -> { // TODO [message-backups] -- Download media now } + BackupAlert.DISK_FULL -> Unit } dismissAllowingStateLoss() @@ -99,6 +101,9 @@ class BackupAlertBottomSheet : ComposeBottomSheetDialogFragment() { BackupAlert.MEDIA_WILL_BE_DELETED_TODAY -> { // TODO [message-backups] - Silence forever } + BackupAlert.DISK_FULL -> { + // TODO [message-backups] - Silence forever, cancel any in-flight downloads? + } } dismissAllowingStateLoss() @@ -143,6 +148,10 @@ private fun BackupAlertSheetContent( BackupAlert.PAYMENT_PROCESSING -> PaymentProcessingBody() BackupAlert.MEDIA_BACKUPS_ARE_OFF -> MediaBackupsAreOffBody() BackupAlert.MEDIA_WILL_BE_DELETED_TODAY -> MediaWillBeDeletedTodayBody() + BackupAlert.DISK_FULL -> DiskFullBody( + requiredSpace = "12 GB", // TODO [message-backups] Where does this value come from? + daysUntilDeletion = 30 // TODO [message-backups] Where does this value come from? + ) } val secondaryActionResource = rememberSecondaryActionResource(backupAlert = backupAlert) @@ -152,7 +161,7 @@ private fun BackupAlertSheetContent( onClick = onPrimaryActionClick, modifier = Modifier .defaultMinSize(minWidth = 220.dp) - .padding(top = 60.dp, bottom = padBottom) + .padding(bottom = padBottom) ) { Text(text = stringResource(id = rememberPrimaryActionResource(backupAlert = backupAlert))) } @@ -167,29 +176,47 @@ private fun BackupAlertSheetContent( @Composable private fun GenericBody() { - Text(text = "TODO") + Text(text = "TODO", modifier = Modifier.padding(bottom = 60.dp)) } @Composable private fun PaymentProcessingBody() { - Text(text = "TODO") + Text(text = "TODO", modifier = Modifier.padding(bottom = 60.dp)) } @Composable private fun MediaBackupsAreOffBody() { - Text(text = "TODO") + Text(text = "TODO", modifier = Modifier.padding(bottom = 60.dp)) } @Composable private fun MediaWillBeDeletedTodayBody() { - Text(text = "TODO") + Text(text = "TODO", modifier = Modifier.padding(bottom = 60.dp)) +} + +@Composable +private fun DiskFullBody( + requiredSpace: String, + daysUntilDeletion: Long +) { + Text( + text = stringResource(id = R.string.BackupAlertBottomSheet__your_device_does_not_have_enough_free_space, requiredSpace), + textAlign = TextAlign.Center, + modifier = Modifier.padding(bottom = 24.dp) + ) + + Text( + text = stringResource(id = R.string.BackupAlertBottomSheet__if_you_choose_skip, daysUntilDeletion), // TODO [message-backups] Learn More link + textAlign = TextAlign.Center, + modifier = Modifier.padding(bottom = 36.dp) + ) } @Composable private fun rememberBackupsIconColors(backupAlert: BackupAlert): BackupsIconColors { return remember(backupAlert) { when (backupAlert) { - BackupAlert.GENERIC, BackupAlert.PAYMENT_PROCESSING -> BackupsIconColors.Warning + BackupAlert.GENERIC, BackupAlert.PAYMENT_PROCESSING, BackupAlert.DISK_FULL -> BackupsIconColors.Warning BackupAlert.MEDIA_BACKUPS_ARE_OFF, BackupAlert.MEDIA_WILL_BE_DELETED_TODAY -> BackupsIconColors.Error } } @@ -204,6 +231,7 @@ private fun rememberTitleResource(backupAlert: BackupAlert): Int { BackupAlert.PAYMENT_PROCESSING -> R.string.default_error_msg // TODO [message-backups] -- Finalized copy BackupAlert.MEDIA_BACKUPS_ARE_OFF -> R.string.default_error_msg // TODO [message-backups] -- Finalized copy BackupAlert.MEDIA_WILL_BE_DELETED_TODAY -> R.string.default_error_msg // TODO [message-backups] -- Finalized copy + BackupAlert.DISK_FULL -> R.string.BackupAlertBottomSheet__cant_complete_download } } } @@ -216,6 +244,7 @@ private fun rememberPrimaryActionResource(backupAlert: BackupAlert): Int { BackupAlert.PAYMENT_PROCESSING -> android.R.string.ok // TODO [message-backups] -- Finalized copy BackupAlert.MEDIA_BACKUPS_ARE_OFF -> android.R.string.ok // TODO [message-backups] -- Finalized copy BackupAlert.MEDIA_WILL_BE_DELETED_TODAY -> android.R.string.ok // TODO [message-backups] -- Finalized copy + BackupAlert.DISK_FULL -> android.R.string.ok } } } @@ -228,6 +257,7 @@ private fun rememberSecondaryActionResource(backupAlert: BackupAlert): Int { BackupAlert.PAYMENT_PROCESSING -> -1 BackupAlert.MEDIA_BACKUPS_ARE_OFF -> android.R.string.cancel // TODO [message-backups] -- Finalized copy BackupAlert.MEDIA_WILL_BE_DELETED_TODAY -> android.R.string.cancel // TODO [message-backups] -- Finalized copy + BackupAlert.DISK_FULL -> R.string.BackupAlertBottomSheet__skip } } } @@ -280,10 +310,23 @@ private fun BackupAlertSheetContentPreviewDelete() { } } +@SignalPreview +@Composable +private fun BackupAlertSheetContentPreviewDiskFull() { + Previews.BottomSheetPreview { + BackupAlertSheetContent( + backupAlert = BackupAlert.DISK_FULL, + onPrimaryActionClick = {}, + onSecondaryActionClick = {} + ) + } +} + @Parcelize enum class BackupAlert : Parcelable { GENERIC, PAYMENT_PROCESSING, MEDIA_BACKUPS_ARE_OFF, - MEDIA_WILL_BE_DELETED_TODAY + MEDIA_WILL_BE_DELETED_TODAY, + DISK_FULL } diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ui/status/BackupStatus.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ui/status/BackupStatus.kt index 023b295a46..a40b681d6a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ui/status/BackupStatus.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/ui/status/BackupStatus.kt @@ -5,7 +5,6 @@ package org.thoughtcrime.securesms.backup.v2.ui.status -import android.content.res.Configuration import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.compose.foundation.background @@ -27,11 +26,11 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.StrokeCap import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import org.signal.core.ui.Buttons import org.signal.core.ui.Icons import org.signal.core.ui.Previews +import org.signal.core.ui.SignalPreview import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.backup.v2.ui.BackupsIconColors import kotlin.math.max @@ -71,13 +70,13 @@ fun BackupStatus( .weight(1f) ) { Text( - text = stringResource(id = data.titleRes), + text = data.title, style = MaterialTheme.typography.bodyMedium ) if (data.progress >= 0f) { LinearProgressIndicator( - progress = data.progress, + progress = { data.progress }, strokeCap = StrokeCap.Round, modifier = Modifier .fillMaxWidth() @@ -105,8 +104,7 @@ fun BackupStatus( } } -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@SignalPreview @Composable fun BackupStatusPreview() { Previews.Preview { @@ -118,7 +116,7 @@ fun BackupStatusPreview() { ) BackupStatus( - data = BackupStatusData.NotEnoughFreeSpace + data = BackupStatusData.NotEnoughFreeSpace("12 GB") ) BackupStatus( @@ -138,8 +136,8 @@ sealed interface BackupStatusData { @get:DrawableRes val iconRes: Int - @get:StringRes - val titleRes: Int + @get:Composable + val title: String val iconColors: BackupsIconColors @@ -154,18 +152,28 @@ sealed interface BackupStatusData { /** * Generic failure */ - object CouldNotCompleteBackup : BackupStatusData { + data object CouldNotCompleteBackup : BackupStatusData { override val iconRes: Int = R.drawable.symbol_backup_light - override val titleRes: Int = R.string.default_error_msg + + override val title: String + @Composable + get() = stringResource(R.string.default_error_msg) + override val iconColors: BackupsIconColors = BackupsIconColors.Warning } /** * User does not have enough space on their device to complete backup restoration */ - object NotEnoughFreeSpace : BackupStatusData { + class NotEnoughFreeSpace( + private val requiredSpace: String + ) : BackupStatusData { override val iconRes: Int = R.drawable.symbol_backup_light - override val titleRes: Int = R.string.default_error_msg + + override val title: String + @Composable + get() = stringResource(R.string.BackupStatus__free_up_s_of_space_to_download_your_media, requiredSpace) + override val iconColors: BackupsIconColors = BackupsIconColors.Warning override val actionRes: Int = R.string.registration_activity__skip } @@ -181,13 +189,16 @@ sealed interface BackupStatusData { override val iconRes: Int = R.drawable.symbol_backup_light override val iconColors: BackupsIconColors = BackupsIconColors.Normal - override val titleRes: Int = when (status) { - Status.NONE -> R.string.default_error_msg - Status.LOW_BATTERY -> R.string.default_error_msg - Status.WAITING_FOR_INTERNET -> R.string.default_error_msg - Status.WAITING_FOR_WIFI -> R.string.default_error_msg - Status.FINISHED -> R.string.default_error_msg - } + override val title: String + @Composable get() = stringResource( + when (status) { + Status.NONE -> R.string.default_error_msg + Status.LOW_BATTERY -> R.string.default_error_msg + Status.WAITING_FOR_INTERNET -> R.string.default_error_msg + Status.WAITING_FOR_WIFI -> R.string.default_error_msg + Status.FINISHED -> R.string.default_error_msg + } + ) override val statusRes: Int = when (status) { Status.NONE -> R.string.default_error_msg diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bdd086c83e..1d63c4bb4e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6992,6 +6992,22 @@ Downloading backup data… + + + Can\'t complete download + + Your device does not have enough free space. Free up to %1$s of space to download the media stored in your backup. + + If you choose \"Skip\" the media in your backup will be deleted in %1$d days. + + Learn more + + Skip + + + + Free up %1$s of space to download your media. + Credit or debit card