mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 04:28:35 +00:00
Add support for downgrading backup.
This commit is contained in:
committed by
Nicholas Tinsley
parent
e6fb01a67b
commit
b1a4e889bc
@@ -243,6 +243,8 @@ class MessageBackupsFlowFragment : ComposeFragment(), InAppPaymentCheckoutDelega
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSubscriptionCancelled(inAppPaymentType: InAppPaymentType) {
|
override fun onSubscriptionCancelled(inAppPaymentType: InAppPaymentType) {
|
||||||
|
viewModel.onCancellationComplete()
|
||||||
|
|
||||||
if (!findNavController().popBackStack()) {
|
if (!findNavController().popBackStack()) {
|
||||||
requireActivity().finishAfterTransition()
|
requireActivity().finishAfterTransition()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class MessageBackupsFlowViewModel : ViewModel() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
private val internalPinState = mutableStateOf("")
|
private val internalPinState = mutableStateOf("")
|
||||||
|
private var isDowngrading = false
|
||||||
|
|
||||||
val stateFlow: StateFlow<MessageBackupsFlowState> = internalStateFlow
|
val stateFlow: StateFlow<MessageBackupsFlowState> = internalStateFlow
|
||||||
val pinState: State<String> = internalPinState
|
val pinState: State<String> = internalPinState
|
||||||
@@ -129,6 +130,15 @@ class MessageBackupsFlowViewModel : ViewModel() {
|
|||||||
internalStateFlow.update { it.copy(selectedMessageBackupTier = messageBackupTier) }
|
internalStateFlow.update { it.copy(selectedMessageBackupTier = messageBackupTier) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onCancellationComplete() {
|
||||||
|
if (isDowngrading) {
|
||||||
|
SignalStore.backup.areBackupsEnabled = true
|
||||||
|
SignalStore.backup.backupTier = MessageBackupTier.FREE
|
||||||
|
|
||||||
|
// TODO [message-backups] -- Trigger backup now?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun validatePinAndUpdateState(pin: String): MessageBackupsScreen {
|
private fun validatePinAndUpdateState(pin: String): MessageBackupsScreen {
|
||||||
val pinHash = SignalStore.svr.localPinHash
|
val pinHash = SignalStore.svr.localPinHash
|
||||||
|
|
||||||
@@ -141,15 +151,19 @@ class MessageBackupsFlowViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun validateTypeAndUpdateState(tier: MessageBackupTier): MessageBackupsScreen {
|
private fun validateTypeAndUpdateState(tier: MessageBackupTier): MessageBackupsScreen {
|
||||||
// TODO [message-backups] - Does anything need to be kicked off?
|
|
||||||
|
|
||||||
return when (tier) {
|
return when (tier) {
|
||||||
MessageBackupTier.FREE -> {
|
MessageBackupTier.FREE -> {
|
||||||
|
if (SignalStore.backup.backupTier == MessageBackupTier.PAID) {
|
||||||
|
isDowngrading = true
|
||||||
|
MessageBackupsScreen.PROCESS_CANCELLATION
|
||||||
|
} else {
|
||||||
SignalStore.backup.areBackupsEnabled = true
|
SignalStore.backup.areBackupsEnabled = true
|
||||||
SignalStore.backup.backupTier = MessageBackupTier.FREE
|
SignalStore.backup.backupTier = MessageBackupTier.FREE
|
||||||
|
|
||||||
|
// TODO [message-backups] -- Trigger backup now?
|
||||||
MessageBackupsScreen.COMPLETED
|
MessageBackupsScreen.COMPLETED
|
||||||
}
|
}
|
||||||
|
}
|
||||||
MessageBackupTier.PAID -> MessageBackupsScreen.CHECKOUT_SHEET
|
MessageBackupTier.PAID -> MessageBackupsScreen.CHECKOUT_SHEET
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,14 +148,14 @@ fun MessageBackupsTypeSelectionScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val hasSelectedBackupTier = currentBackupTier != null
|
val hasCurrentBackupTier = currentBackupTier != null
|
||||||
|
|
||||||
Buttons.LargePrimary(
|
Buttons.LargePrimary(
|
||||||
onClick = onNextClicked,
|
onClick = onNextClicked,
|
||||||
enabled = selectedBackupTier != null,
|
enabled = selectedBackupTier != currentBackupTier && hasCurrentBackupTier,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(vertical = if (hasSelectedBackupTier) 10.dp else 16.dp)
|
.padding(vertical = if (hasCurrentBackupTier) 10.dp else 16.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(
|
text = stringResource(
|
||||||
@@ -168,7 +168,7 @@ fun MessageBackupsTypeSelectionScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSelectedBackupTier) {
|
if (hasCurrentBackupTier) {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = onCancelSubscriptionClicked,
|
onClick = onCancelSubscriptionClicked,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
@@ -466,7 +466,6 @@ class InAppPaymentValues internal constructor(store: KeyValueStore) : SignalStor
|
|||||||
} else {
|
} else {
|
||||||
markBackupSubscriptionpManuallyCancelled()
|
markBackupSubscriptionpManuallyCancelled()
|
||||||
|
|
||||||
// TODO [message-backups] -- Handle downgrades?
|
|
||||||
SignalStore.backup.areBackupsEnabled = false
|
SignalStore.backup.areBackupsEnabled = false
|
||||||
SignalStore.backup.backupTier = null
|
SignalStore.backup.backupTier = null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user