Integrate swapping backup tiers from backup settings.

This commit is contained in:
Clark
2024-05-07 17:00:05 -04:00
committed by Alex Hart
parent b6db3802d3
commit 83c34dd4cc
8 changed files with 36 additions and 32 deletions

View File

@@ -10,7 +10,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import org.thoughtcrime.securesms.backup.v2.BackupFrequency
import org.thoughtcrime.securesms.backup.v2.BackupV2Event
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.jobs.BackupMessagesJob
import org.thoughtcrime.securesms.keyvalue.SignalStore
@@ -22,15 +21,7 @@ import org.thoughtcrime.securesms.service.MessageBackupListener
class RemoteBackupsSettingsViewModel : ViewModel() {
private val internalState = mutableStateOf(
RemoteBackupsSettingsState(
messageBackupsTier = if (SignalStore.backup().areBackupsEnabled) {
if (SignalStore.backup().canReadWriteToArchiveCdn) {
MessageBackupTier.PAID
} else {
MessageBackupTier.FREE
}
} else {
null
},
messageBackupsTier = SignalStore.backup().backupTier,
lastBackupTimestamp = SignalStore.backup().lastBackupTime,
backupSize = SignalStore.backup().totalBackupSize,
backupsFrequency = SignalStore.backup().backupFrequency

View File

@@ -19,23 +19,19 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.navigation.fragment.findNavController
import kotlinx.collections.immutable.persistentListOf
import org.signal.core.ui.Previews
import org.signal.core.ui.Rows
import org.signal.core.ui.Scaffolds
import org.signal.core.ui.SignalPreview
import org.signal.core.util.money.FiatMoney
import org.signal.donations.PaymentSourceType
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsFlowActivity
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsType
import org.thoughtcrime.securesms.backup.v2.ui.subscription.getTierDetails
import org.thoughtcrime.securesms.compose.ComposeFragment
import org.thoughtcrime.securesms.payments.FiatMoneyUtil
import org.thoughtcrime.securesms.util.DateUtils
import org.thoughtcrime.securesms.util.viewModel
import java.math.BigDecimal
import java.util.Currency
import java.util.Locale
/**
@@ -87,7 +83,7 @@ private fun BackupsTypeSettingsContent(
state: BackupsTypeSettingsState,
contentCallbacks: ContentCallbacks
) {
if (state.backupsType == null) {
if (state.backupsTier == null) {
return
}
@@ -101,7 +97,7 @@ private fun BackupsTypeSettingsContent(
) {
item {
BackupsTypeRow(
backupsType = state.backupsType,
backupsTier = state.backupsTier,
nextRenewalTimestamp = state.nextRenewalTimestamp
)
}
@@ -131,12 +127,16 @@ private fun BackupsTypeSettingsContent(
@Composable
private fun BackupsTypeRow(
backupsType: MessageBackupsType,
backupsTier: MessageBackupTier,
nextRenewalTimestamp: Long
) {
val messageBackupsType = remember {
getTierDetails(backupsTier)
}
val resources = LocalContext.current.resources
val formattedAmount = remember(backupsType.pricePerMonth) {
FiatMoneyUtil.format(resources, backupsType.pricePerMonth, FiatMoneyUtil.formatOptions().trimZerosAfterDecimal())
val formattedAmount = remember(messageBackupsType.pricePerMonth) {
FiatMoneyUtil.format(resources, messageBackupsType.pricePerMonth, FiatMoneyUtil.formatOptions().trimZerosAfterDecimal())
}
val renewal = remember(nextRenewalTimestamp) {
@@ -145,7 +145,7 @@ private fun BackupsTypeRow(
Rows.TextRow(text = {
Column {
Text(text = backupsType.title)
Text(text = messageBackupsType.title)
Text(
text = "$formattedAmount/month . Renews $renewal", // TODO [message-backups] final copy
style = MaterialTheme.typography.bodyMedium,
@@ -186,12 +186,7 @@ private fun BackupsTypeSettingsContentPreview() {
Previews.Preview {
BackupsTypeSettingsContent(
state = BackupsTypeSettingsState(
backupsType = MessageBackupsType(
tier = MessageBackupTier.PAID,
pricePerMonth = FiatMoney(BigDecimal.valueOf(3), Currency.getInstance("USD")),
title = "Text + all media",
features = persistentListOf()
)
backupsTier = MessageBackupTier.PAID
),
contentCallbacks = object : ContentCallbacks {}
)

View File

@@ -7,11 +7,11 @@ package org.thoughtcrime.securesms.components.settings.app.chats.backups.type
import androidx.compose.runtime.Stable
import org.signal.donations.PaymentSourceType
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsType
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
@Stable
data class BackupsTypeSettingsState(
val backupsType: MessageBackupsType? = null,
val backupsTier: MessageBackupTier? = null,
val paymentSourceType: PaymentSourceType = PaymentSourceType.Unknown,
val nextRenewalTimestamp: Long = 0
)

View File

@@ -8,9 +8,14 @@ package org.thoughtcrime.securesms.components.settings.app.chats.backups.type
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import org.thoughtcrime.securesms.keyvalue.SignalStore
class BackupsTypeSettingsViewModel : ViewModel() {
private val internalState = mutableStateOf(BackupsTypeSettingsState())
private val internalState = mutableStateOf(
BackupsTypeSettingsState(
backupsTier = SignalStore.backup().backupTier
)
)
val state: State<BackupsTypeSettingsState> = internalState
}