Fix bad UI state when changing backup status.

This commit is contained in:
Cody Henthorne
2022-01-03 12:25:36 -05:00
committed by Alex Hart
parent d1eab086f1
commit e48c1bf207
2 changed files with 12 additions and 0 deletions

View File

@@ -14,6 +14,11 @@ class ChatsSettingsFragment : DSLSettingsFragment(R.string.preferences_chats__ch
private lateinit var viewModel: ChatsSettingsViewModel
override fun onResume() {
super.onResume()
viewModel.refresh()
}
override fun bindAdapter(adapter: DSLSettingsAdapter) {
val repository = ChatsSettingsRepository()
val factory = ChatsSettingsViewModel.Factory(repository)

View File

@@ -52,6 +52,13 @@ class ChatsSettingsViewModel(private val repository: ChatsSettingsRepository) :
SignalStore.settings().isEnterKeySends = enabled
}
fun refresh() {
val backupsEnabled = SignalStore.settings().isBackupEnabled && BackupUtil.canUserAccessBackupDirectory(ApplicationDependencies.getApplication())
if (store.state.chatBackupsEnabled != backupsEnabled) {
store.update { it.copy(chatBackupsEnabled = backupsEnabled) }
}
}
class Factory(private val repository: ChatsSettingsRepository) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return requireNotNull(modelClass.cast(ChatsSettingsViewModel(repository)))