Add content for disk full alert for backups.

This commit is contained in:
Alex Hart
2024-06-21 11:04:34 -03:00
committed by Greyson Parrelli
parent 362cdfc463
commit 187fd63a75
3 changed files with 97 additions and 27 deletions

View File

@@ -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
}

View File

@@ -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

View File

@@ -6992,6 +6992,22 @@
<!-- Notification title shown while downloading backup restore data -->
<string name="BackupProgressService_title_downloading">Downloading backup data…</string>
<!-- BackupAlertBottomSheet -->
<!-- Sheet title when user does not have enough space to download their backup -->
<string name="BackupAlertBottomSheet__cant_complete_download">Can\'t complete download</string>
<!-- Sheet body part 1 when user does not have enough space to download their backup. Placeholder is the amount of space needed. -->
<string name="BackupAlertBottomSheet__your_device_does_not_have_enough_free_space">Your device does not have enough free space. Free up to %1$s of space to download the media stored in your backup.</string>
<!-- Sheet body part 2 when user does not have enough space to download their backup. Placeholder is the number of days until deletion -->
<string name="BackupAlertBottomSheet__if_you_choose_skip">If you choose \"Skip\" the media in your backup will be deleted in %1$d days.</string>
<!-- Clickable text to learn more about the content of this bottom sheet -->
<string name="BackupAlertBottomSheet__learn_more">Learn more</string>
<!-- Secondary action button text when user does not have enough free space to download their backup. -->
<string name="BackupAlertBottomSheet__skip">Skip</string>
<!-- BackupStatus -->
<!-- Status title when user does not have enough free space to download their media. Placeholder is required disk space. -->
<string name="BackupStatus__free_up_s_of_space_to_download_your_media">Free up %1$s of space to download your media.</string>
<!-- BackupsTypeSettingsFragment -->
<!-- Displayed as the user\'s payment method as a label in a preference row -->
<string name="BackupsTypeSettingsFragment__credit_or_debit_card">Credit or debit card</string>