Pass in days since last backup to alert sheet.

This commit is contained in:
Alex Hart
2024-11-06 12:46:41 -04:00
committed by Greyson Parrelli
parent c85a28af92
commit 35b80be8c8
4 changed files with 27 additions and 15 deletions

View File

@@ -5,6 +5,7 @@
package org.thoughtcrime.securesms.backup.v2.ui package org.thoughtcrime.securesms.backup.v2.ui
import android.content.DialogInterface
import android.os.Parcelable import android.os.Parcelable
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
@@ -97,7 +98,7 @@ class BackupAlertBottomSheet : ComposeBottomSheetDialogFragment() {
@Stable @Stable
private fun performPrimaryAction() { private fun performPrimaryAction() {
when (backupAlert) { when (backupAlert) {
BackupAlert.CouldNotCompleteBackup -> { is BackupAlert.CouldNotCompleteBackup -> {
BackupMessagesJob.enqueue() BackupMessagesJob.enqueue()
startActivity(AppSettingsActivity.remoteBackups(requireContext())) startActivity(AppSettingsActivity.remoteBackups(requireContext()))
} }
@@ -116,10 +117,7 @@ class BackupAlertBottomSheet : ComposeBottomSheetDialogFragment() {
@Stable @Stable
private fun performSecondaryAction() { private fun performSecondaryAction() {
when (backupAlert) { when (backupAlert) {
BackupAlert.CouldNotCompleteBackup -> { is BackupAlert.CouldNotCompleteBackup -> Unit
// TODO [backups] - Dismiss and notify later
}
BackupAlert.FailedToRenew -> Unit BackupAlert.FailedToRenew -> Unit
BackupAlert.MediaBackupsAreOff -> { BackupAlert.MediaBackupsAreOff -> {
// TODO [backups] - Silence and remind on last day // TODO [backups] - Silence and remind on last day
@@ -137,6 +135,15 @@ class BackupAlertBottomSheet : ComposeBottomSheetDialogFragment() {
dismissAllowingStateLoss() dismissAllowingStateLoss()
} }
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
when (backupAlert) {
is BackupAlert.CouldNotCompleteBackup -> BackupRepository.markBackupFailedSheetDismissed()
else -> Unit
}
}
private fun displayLastChanceDialog() { private fun displayLastChanceDialog() {
MaterialAlertDialogBuilder(requireContext()) MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.BackupAlertBottomSheet__media_will_be_deleted) .setTitle(R.string.BackupAlertBottomSheet__media_will_be_deleted)
@@ -229,8 +236,8 @@ private fun BackupAlertSheetContent(
) )
when (backupAlert) { when (backupAlert) {
BackupAlert.CouldNotCompleteBackup -> CouldNotCompleteBackup( is BackupAlert.CouldNotCompleteBackup -> CouldNotCompleteBackup(
daysSinceLastBackup = 7 // TODO [backups] daysSinceLastBackup = backupAlert.daysSinceLastBackup
) )
BackupAlert.FailedToRenew -> PaymentProcessingBody() BackupAlert.FailedToRenew -> PaymentProcessingBody()
@@ -339,7 +346,7 @@ private fun rememberBackupsIconColors(backupAlert: BackupAlert): BackupsIconColo
return remember(backupAlert) { return remember(backupAlert) {
when (backupAlert) { when (backupAlert) {
BackupAlert.FailedToRenew, BackupAlert.MediaBackupsAreOff -> error("Not icon-based options.") BackupAlert.FailedToRenew, BackupAlert.MediaBackupsAreOff -> error("Not icon-based options.")
BackupAlert.CouldNotCompleteBackup, is BackupAlert.DiskFull -> BackupsIconColors.Warning is BackupAlert.CouldNotCompleteBackup, is BackupAlert.DiskFull -> BackupsIconColors.Warning
BackupAlert.MediaWillBeDeletedToday -> BackupsIconColors.Error BackupAlert.MediaWillBeDeletedToday -> BackupsIconColors.Error
} }
} }
@@ -348,7 +355,7 @@ private fun rememberBackupsIconColors(backupAlert: BackupAlert): BackupsIconColo
@Composable @Composable
private fun titleString(backupAlert: BackupAlert): String { private fun titleString(backupAlert: BackupAlert): String {
return when (backupAlert) { return when (backupAlert) {
BackupAlert.CouldNotCompleteBackup -> stringResource(R.string.BackupAlertBottomSheet__couldnt_complete_backup) is BackupAlert.CouldNotCompleteBackup -> stringResource(R.string.BackupAlertBottomSheet__couldnt_complete_backup)
BackupAlert.FailedToRenew -> stringResource(R.string.BackupAlertBottomSheet__your_backups_subscription_failed_to_renew) BackupAlert.FailedToRenew -> stringResource(R.string.BackupAlertBottomSheet__your_backups_subscription_failed_to_renew)
BackupAlert.MediaBackupsAreOff -> stringResource(R.string.BackupAlertBottomSheet__your_backups_subscription_expired) BackupAlert.MediaBackupsAreOff -> stringResource(R.string.BackupAlertBottomSheet__your_backups_subscription_expired)
BackupAlert.MediaWillBeDeletedToday -> stringResource(R.string.BackupAlertBottomSheet__your_media_will_be_deleted_today) BackupAlert.MediaWillBeDeletedToday -> stringResource(R.string.BackupAlertBottomSheet__your_media_will_be_deleted_today)
@@ -362,7 +369,7 @@ private fun primaryActionString(
pricePerMonth: String pricePerMonth: String
): String { ): String {
return when (backupAlert) { return when (backupAlert) {
BackupAlert.CouldNotCompleteBackup -> stringResource(R.string.BackupAlertBottomSheet__back_up_now) is BackupAlert.CouldNotCompleteBackup -> stringResource(R.string.BackupAlertBottomSheet__back_up_now)
BackupAlert.FailedToRenew -> stringResource(R.string.BackupAlertBottomSheet__manage_subscription) BackupAlert.FailedToRenew -> stringResource(R.string.BackupAlertBottomSheet__manage_subscription)
BackupAlert.MediaBackupsAreOff -> stringResource(R.string.BackupAlertBottomSheet__subscribe_for_s_month, pricePerMonth) BackupAlert.MediaBackupsAreOff -> stringResource(R.string.BackupAlertBottomSheet__subscribe_for_s_month, pricePerMonth)
BackupAlert.MediaWillBeDeletedToday -> stringResource(R.string.BackupAlertBottomSheet__download_media_now) BackupAlert.MediaWillBeDeletedToday -> stringResource(R.string.BackupAlertBottomSheet__download_media_now)
@@ -374,7 +381,7 @@ private fun primaryActionString(
private fun rememberSecondaryActionResource(backupAlert: BackupAlert): Int { private fun rememberSecondaryActionResource(backupAlert: BackupAlert): Int {
return remember(backupAlert) { return remember(backupAlert) {
when (backupAlert) { when (backupAlert) {
BackupAlert.CouldNotCompleteBackup -> R.string.BackupAlertBottomSheet__try_later is BackupAlert.CouldNotCompleteBackup -> R.string.BackupAlertBottomSheet__try_later
BackupAlert.FailedToRenew -> R.string.BackupAlertBottomSheet__not_now BackupAlert.FailedToRenew -> R.string.BackupAlertBottomSheet__not_now
BackupAlert.MediaBackupsAreOff -> R.string.BackupAlertBottomSheet__not_now BackupAlert.MediaBackupsAreOff -> R.string.BackupAlertBottomSheet__not_now
BackupAlert.MediaWillBeDeletedToday -> R.string.BackupAlertBottomSheet__dont_download_media BackupAlert.MediaWillBeDeletedToday -> R.string.BackupAlertBottomSheet__dont_download_media
@@ -388,7 +395,7 @@ private fun rememberSecondaryActionResource(backupAlert: BackupAlert): Int {
private fun BackupAlertSheetContentPreviewGeneric() { private fun BackupAlertSheetContentPreviewGeneric() {
Previews.BottomSheetPreview { Previews.BottomSheetPreview {
BackupAlertSheetContent( BackupAlertSheetContent(
backupAlert = BackupAlert.CouldNotCompleteBackup backupAlert = BackupAlert.CouldNotCompleteBackup(daysSinceLastBackup = 7)
) )
} }
} }
@@ -440,7 +447,9 @@ private fun BackupAlertSheetContentPreviewDiskFull() {
@Parcelize @Parcelize
sealed class BackupAlert : Parcelable { sealed class BackupAlert : Parcelable {
data object CouldNotCompleteBackup : BackupAlert() data class CouldNotCompleteBackup(
val daysSinceLastBackup: Int
) : BackupAlert()
data object FailedToRenew : BackupAlert() data object FailedToRenew : BackupAlert()

View File

@@ -11,6 +11,7 @@ import androidx.lifecycle.coroutineScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.thoughtcrime.securesms.backup.v2.BackupRepository import org.thoughtcrime.securesms.backup.v2.BackupRepository
import org.thoughtcrime.securesms.keyvalue.SignalStore
/** /**
* Delegate that controls whether and which backup alert sheet is displayed. * Delegate that controls whether and which backup alert sheet is displayed.
@@ -21,7 +22,7 @@ object BackupAlertDelegate {
lifecycle.coroutineScope.launch { lifecycle.coroutineScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) { lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {
if (BackupRepository.shouldDisplayBackupFailedSheet()) { if (BackupRepository.shouldDisplayBackupFailedSheet()) {
BackupAlertBottomSheet.create(BackupAlert.CouldNotCompleteBackup).show(fragmentManager, null) BackupAlertBottomSheet.create(BackupAlert.CouldNotCompleteBackup(daysSinceLastBackup = SignalStore.backup.daysSinceLastBackup)).show(fragmentManager, null)
} }
// TODO [backups] // TODO [backups]

View File

@@ -134,7 +134,7 @@ class InAppPaymentsBottomSheetDelegate(
}.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeBy { inAppPayments -> }.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeBy { inAppPayments ->
for (payment in inAppPayments) { for (payment in inAppPayments) {
if (isPaymentProcessingError(payment.state, payment.data)) { if (isPaymentProcessingError(payment.state, payment.data)) {
BackupAlertBottomSheet.create(BackupAlert.CouldNotCompleteBackup).show(fragmentManager, null) BackupAlertBottomSheet.create(BackupAlert.CouldNotCompleteBackup(daysSinceLastBackup = SignalStore.backup.daysSinceLastBackup)).show(fragmentManager, null)
} else if (isUnexpectedCancellation(payment.state, payment.data)) { } else if (isUnexpectedCancellation(payment.state, payment.data)) {
BackupAlertBottomSheet.create(BackupAlert.MediaBackupsAreOff).show(fragmentManager, null) BackupAlertBottomSheet.create(BackupAlert.MediaBackupsAreOff).show(fragmentManager, null)
} }

View File

@@ -84,6 +84,8 @@ class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
clearMessageBackupFailureSheetWatermark() clearMessageBackupFailureSheetWatermark()
} }
val daysSinceLastBackup: Int get() = (System.currentTimeMillis().milliseconds - lastBackupTime.milliseconds).inWholeDays.toInt()
var lastMediaSyncTime: Long by longValue(KEY_LAST_BACKUP_MEDIA_SYNC_TIME, -1) var lastMediaSyncTime: Long by longValue(KEY_LAST_BACKUP_MEDIA_SYNC_TIME, -1)
var backupFrequency: BackupFrequency by enumValue(KEY_BACKUP_FREQUENCY, BackupFrequency.MANUAL, BackupFrequency.Serializer) var backupFrequency: BackupFrequency by enumValue(KEY_BACKUP_FREQUENCY, BackupFrequency.MANUAL, BackupFrequency.Serializer)