mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Check remaining attachment size before launching service.
This commit is contained in:
@@ -256,6 +256,16 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
mainNavigationViewModel.backupStatus.collect { remainingRestoreSize ->
|
||||
if (SignalStore.backup.restoreState == RestoreState.RESTORING_MEDIA && remainingRestoreSize != 0L) {
|
||||
Log.i(TAG, "Still restoring media, launching a service. Remaining restoration size: $remainingRestoreSize")
|
||||
BackupMediaRestoreService.resetTimeout()
|
||||
BackupMediaRestoreService.start(this@MainActivity, resources.getString(R.string.BackupStatus__restoring_media))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val callback = object : OnBackPressedCallback(toolbarViewModel.state.value.mode == MainToolbarMode.ACTION_MODE) {
|
||||
@@ -272,12 +282,6 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
|
||||
}
|
||||
}
|
||||
|
||||
if (SignalStore.backup.restoreState == RestoreState.RESTORING_MEDIA) {
|
||||
Log.i(TAG, "Still restoring media, launching a service.")
|
||||
BackupMediaRestoreService.resetTimeout()
|
||||
BackupMediaRestoreService.start(this, resources.getString(R.string.BackupStatus__restoring_media))
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, callback)
|
||||
|
||||
shareDataTimestampViewModel.setTimestampFromActivityCreation(savedInstanceState, intent)
|
||||
|
||||
@@ -21,7 +21,9 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.reactive.asFlow
|
||||
import kotlinx.coroutines.rx3.asObservable
|
||||
import org.thoughtcrime.securesms.backup.RestoreState
|
||||
import org.thoughtcrime.securesms.components.settings.app.notifications.profiles.NotificationProfilesRepository
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.megaphone.Megaphone
|
||||
@@ -62,6 +64,9 @@ class MainNavigationViewModel(
|
||||
private val internalMainNavigationState = MutableStateFlow(MainNavigationState(currentListLocation = initialListLocation))
|
||||
val mainNavigationState: StateFlow<MainNavigationState> = internalMainNavigationState
|
||||
|
||||
private val internalBackupStatus = MutableStateFlow(0L)
|
||||
val backupStatus: StateFlow<Long> = internalBackupStatus
|
||||
|
||||
/**
|
||||
* This is Rx because these are still accessed from Java.
|
||||
*/
|
||||
@@ -84,6 +89,8 @@ class MainNavigationViewModel(
|
||||
performStoreUpdate(MainNavigationRepository.getHasFailedOutgoingStories()) { hasFailedStories, state ->
|
||||
state.copy(storyFailure = hasFailedStories)
|
||||
}
|
||||
|
||||
getRemainingRestoreAttachmentSize()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,6 +219,18 @@ class MainNavigationViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getRemainingRestoreAttachmentSize() {
|
||||
viewModelScope.launch {
|
||||
internalBackupStatus.update {
|
||||
if (SignalStore.backup.restoreState == RestoreState.RESTORING_MEDIA) {
|
||||
SignalDatabase.attachments.getRemainingRestorableAttachmentSize()
|
||||
} else {
|
||||
0L
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : Any> performStoreUpdate(flow: Flow<T>, fn: (T, MainNavigationState) -> MainNavigationState) {
|
||||
viewModelScope.launch {
|
||||
flow.collectLatest { item ->
|
||||
|
||||
Reference in New Issue
Block a user