mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 19:29:54 +01:00
Setup infra for better archive upload progress tracking.
This commit is contained in:
@@ -49,9 +49,6 @@ import androidx.compose.ui.window.DialogProperties
|
||||
import androidx.fragment.app.setFragmentResultListener
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import org.signal.core.ui.Buttons
|
||||
import org.signal.core.ui.Dialogs
|
||||
import org.signal.core.ui.Dividers
|
||||
@@ -63,15 +60,15 @@ import org.signal.core.ui.Snackbars
|
||||
import org.signal.core.ui.Texts
|
||||
import org.signal.core.util.money.FiatMoney
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.backup.ArchiveUploadProgress
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupFrequency
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupV2Event
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsType
|
||||
import org.thoughtcrime.securesms.components.settings.app.chats.backups.type.BackupsTypeSettingsFragment
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.MessageBackupsCheckoutLauncher.createBackupsCheckoutLauncher
|
||||
import org.thoughtcrime.securesms.compose.ComposeFragment
|
||||
import org.thoughtcrime.securesms.conversation.v2.registerForLifecycle
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.keyvalue.protos.ArchiveUploadProgressState
|
||||
import org.thoughtcrime.securesms.payments.FiatMoneyUtil
|
||||
import org.thoughtcrime.securesms.util.DateUtils
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
@@ -96,6 +93,7 @@ class RemoteBackupsSettingsFragment : ComposeFragment() {
|
||||
@Composable
|
||||
override fun FragmentContent() {
|
||||
val state by viewModel.state.collectAsState()
|
||||
val backupProgress by ArchiveUploadProgress.progress.collectAsState(initial = null)
|
||||
val callbacks = remember { Callbacks() }
|
||||
|
||||
RemoteBackupsSettingsContent(
|
||||
@@ -106,7 +104,7 @@ class RemoteBackupsSettingsFragment : ComposeFragment() {
|
||||
requestedDialog = state.dialog,
|
||||
requestedSnackbar = state.snackbar,
|
||||
contentCallbacks = callbacks,
|
||||
backupProgress = state.backupProgress,
|
||||
backupProgress = backupProgress,
|
||||
backupSize = state.backupSize
|
||||
)
|
||||
}
|
||||
@@ -162,14 +160,8 @@ class RemoteBackupsSettingsFragment : ComposeFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun onEvent(backupEvent: BackupV2Event) {
|
||||
viewModel.updateBackupProgress(backupEvent)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
EventBus.getDefault().registerForLifecycle(subscriber = this, lifecycleOwner = viewLifecycleOwner)
|
||||
checkoutLauncher = createBackupsCheckoutLauncher { backUpLater ->
|
||||
if (backUpLater) {
|
||||
viewModel.requestSnackbar(RemoteBackupsSettingsState.Snackbar.BACKUP_WILL_BE_CREATED_OVERNIGHT)
|
||||
@@ -221,7 +213,7 @@ private fun RemoteBackupsSettingsContent(
|
||||
requestedDialog: RemoteBackupsSettingsState.Dialog,
|
||||
requestedSnackbar: RemoteBackupsSettingsState.Snackbar,
|
||||
contentCallbacks: ContentCallbacks,
|
||||
backupProgress: BackupV2Event?,
|
||||
backupProgress: ArchiveUploadProgressState?,
|
||||
backupSize: Long
|
||||
) {
|
||||
val snackbarHostState = remember {
|
||||
@@ -264,7 +256,7 @@ private fun RemoteBackupsSettingsContent(
|
||||
Texts.SectionHeader(text = stringResource(id = R.string.RemoteBackupsSettingsFragment__backup_details))
|
||||
}
|
||||
|
||||
if (backupProgress == null || backupProgress.type == BackupV2Event.Type.FINISHED) {
|
||||
if (backupProgress == null || backupProgress.state == ArchiveUploadProgressState.State.None) {
|
||||
item {
|
||||
LastBackupRow(
|
||||
lastBackupTimestamp = lastBackupTimestamp,
|
||||
@@ -273,7 +265,7 @@ private fun RemoteBackupsSettingsContent(
|
||||
}
|
||||
} else {
|
||||
item {
|
||||
InProgressBackupRow(progress = backupProgress.count.toInt(), totalProgress = backupProgress.estimatedTotalCount.toInt())
|
||||
InProgressBackupRow(progress = backupProgress.completedAttachments.toInt(), totalProgress = backupProgress.totalAttachments.toInt())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.chats.backups
|
||||
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupFrequency
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupV2Event
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsType
|
||||
|
||||
data class RemoteBackupsSettingsState(
|
||||
@@ -16,8 +15,7 @@ data class RemoteBackupsSettingsState(
|
||||
val backupsFrequency: BackupFrequency = BackupFrequency.DAILY,
|
||||
val lastBackupTimestamp: Long = 0,
|
||||
val dialog: Dialog = Dialog.NONE,
|
||||
val snackbar: Snackbar = Snackbar.NONE,
|
||||
val backupProgress: BackupV2Event? = null
|
||||
val snackbar: Snackbar = Snackbar.NONE
|
||||
) {
|
||||
enum class Dialog {
|
||||
NONE,
|
||||
|
||||
@@ -17,7 +17,6 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupFrequency
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupRepository
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupV2Event
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.jobs.BackupMessagesJob
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
@@ -28,7 +27,7 @@ import kotlin.time.Duration.Companion.milliseconds
|
||||
* ViewModel for state management of RemoteBackupsSettingsFragment
|
||||
*/
|
||||
class RemoteBackupsSettingsViewModel : ViewModel() {
|
||||
private val internalState = MutableStateFlow(
|
||||
private val _state = MutableStateFlow(
|
||||
RemoteBackupsSettingsState(
|
||||
messageBackupsType = null,
|
||||
lastBackupTimestamp = SignalStore.backup.lastBackupTime,
|
||||
@@ -37,7 +36,7 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
|
||||
)
|
||||
)
|
||||
|
||||
val state: StateFlow<RemoteBackupsSettingsState> = internalState
|
||||
val state: StateFlow<RemoteBackupsSettingsState> = _state
|
||||
|
||||
init {
|
||||
refresh()
|
||||
@@ -45,22 +44,22 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
|
||||
|
||||
fun setCanBackUpUsingCellular(canBackUpUsingCellular: Boolean) {
|
||||
SignalStore.backup.backupWithCellular = canBackUpUsingCellular
|
||||
internalState.update { it.copy(canBackUpUsingCellular = canBackUpUsingCellular) }
|
||||
_state.update { it.copy(canBackUpUsingCellular = canBackUpUsingCellular) }
|
||||
}
|
||||
|
||||
fun setBackupsFrequency(backupsFrequency: BackupFrequency) {
|
||||
SignalStore.backup.backupFrequency = backupsFrequency
|
||||
internalState.update { it.copy(backupsFrequency = backupsFrequency) }
|
||||
_state.update { it.copy(backupsFrequency = backupsFrequency) }
|
||||
MessageBackupListener.setNextBackupTimeToIntervalFromNow()
|
||||
MessageBackupListener.schedule(AppDependencies.application)
|
||||
}
|
||||
|
||||
fun requestDialog(dialog: RemoteBackupsSettingsState.Dialog) {
|
||||
internalState.update { it.copy(dialog = dialog) }
|
||||
_state.update { it.copy(dialog = dialog) }
|
||||
}
|
||||
|
||||
fun requestSnackbar(snackbar: RemoteBackupsSettingsState.Snackbar) {
|
||||
internalState.update { it.copy(snackbar = snackbar) }
|
||||
_state.update { it.copy(snackbar = snackbar) }
|
||||
}
|
||||
|
||||
fun refresh() {
|
||||
@@ -68,7 +67,7 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
|
||||
val tier = SignalStore.backup.backupTier
|
||||
val backupType = if (tier != null) BackupRepository.getBackupsType(tier) else null
|
||||
|
||||
internalState.update {
|
||||
_state.update {
|
||||
it.copy(
|
||||
messageBackupsType = backupType,
|
||||
lastBackupTimestamp = SignalStore.backup.lastBackupTime,
|
||||
@@ -96,13 +95,8 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun updateBackupProgress(backupEvent: BackupV2Event?) {
|
||||
internalState.update { it.copy(backupProgress = backupEvent) }
|
||||
refreshBackupState()
|
||||
}
|
||||
|
||||
private fun refreshBackupState() {
|
||||
internalState.update {
|
||||
_state.update {
|
||||
it.copy(
|
||||
lastBackupTimestamp = SignalStore.backup.lastBackupTime,
|
||||
backupSize = SignalStore.backup.totalBackupSize
|
||||
@@ -111,8 +105,6 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun onBackupNowClick() {
|
||||
if (internalState.value.backupProgress == null || internalState.value.backupProgress?.type == BackupV2Event.Type.FINISHED) {
|
||||
BackupMessagesJob.enqueue()
|
||||
}
|
||||
BackupMessagesJob.enqueue()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user