mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-15 07:28:30 +00:00
Integrate swapping backup tiers from backup settings.
This commit is contained in:
@@ -57,7 +57,7 @@ class MessageBackupsFlowActivity : PassphraseRequiredActivity() {
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = MessageBackupsScreen.EDUCATION.name,
|
||||
startDestination = if (state.currentMessageBackupTier == null) MessageBackupsScreen.EDUCATION.name else MessageBackupsScreen.TYPE_SELECTION.name,
|
||||
enterTransition = { slideInHorizontally(initialOffsetX = { it }) },
|
||||
exitTransition = { slideOutHorizontally(targetOffsetX = { -it }) },
|
||||
popEnterTransition = { slideInHorizontally(initialOffsetX = { -it }) },
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.lock.v2.PinKeyboardType
|
||||
|
||||
data class MessageBackupsFlowState(
|
||||
val selectedMessageBackupTier: MessageBackupTier? = null,
|
||||
val currentMessageBackupTier: MessageBackupTier? = null,
|
||||
val availableBackupTiers: List<MessageBackupTier> = emptyList(),
|
||||
val selectedPaymentGateway: GatewayResponse.Gateway? = null,
|
||||
val availablePaymentGateways: List<GatewayResponse.Gateway> = emptyList(),
|
||||
|
||||
@@ -24,7 +24,8 @@ class MessageBackupsFlowViewModel : ViewModel() {
|
||||
emptyList()
|
||||
} else {
|
||||
listOf(MessageBackupTier.FREE, MessageBackupTier.PAID)
|
||||
}
|
||||
},
|
||||
selectedMessageBackupTier = SignalStore.backup().backupTier
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {}
|
||||
)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.backup.RestoreState
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupFrequency
|
||||
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
|
||||
import org.whispersystems.signalservice.api.archive.ArchiveServiceCredential
|
||||
import org.whispersystems.signalservice.api.archive.GetArchiveCdnCredentialsResponse
|
||||
import org.whispersystems.signalservice.internal.util.JsonUtil
|
||||
@@ -74,6 +75,16 @@ internal class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
|
||||
.apply()
|
||||
}
|
||||
|
||||
val backupTier: MessageBackupTier? = if (areBackupsEnabled) {
|
||||
if (canReadWriteToArchiveCdn) {
|
||||
MessageBackupTier.PAID
|
||||
} else {
|
||||
MessageBackupTier.FREE
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
var backupsInitialized: Boolean by booleanValue(KEY_BACKUPS_INITIALIZED, false)
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user