diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsActivity.kt index 5422712202..1c6960e7ac 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsActivity.kt @@ -105,6 +105,13 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { viewModel.onSetClick() } lifecycleScope.launchWhenStarted { + launch { + viewModel.uiState.collect { uiState -> + if (uiState.settingsSaved == true) { + finish() + } + } + } launch { viewModel.selectedExpirationType.collect { type -> val position = deleteTypeOptions.indexOfFirst { it.value.toIntOrNull() == type } @@ -119,15 +126,15 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { } launch { viewModel.expirationTimerOptions.collect { options -> - binding.textViewTimer.isVisible = options.isNotEmpty() && viewModel.showExpirationTypeSelector + binding.textViewTimer.isVisible = options.isNotEmpty() && viewModel.uiState.value.showExpirationTypeSelector binding.layoutTimer.isVisible = options.isNotEmpty() timerOptionAdapter.submitList(options) } } launch { viewModel.recipient.collect { - binding.textViewDeleteType.isVisible = viewModel.showExpirationTypeSelector - binding.layoutDeleteTypes.isVisible = viewModel.showExpirationTypeSelector + binding.textViewDeleteType.isVisible = viewModel.uiState.value.showExpirationTypeSelector + binding.layoutDeleteTypes.isVisible = viewModel.uiState.value.showExpirationTypeSelector binding.textViewFooter.isVisible = it?.isClosedGroupRecipient == true binding.textViewFooter.text = HtmlCompat.fromHtml(getString(R.string.activity_expiration_settings_group_footer), HtmlCompat.FROM_HTML_MODE_COMPACT) } @@ -137,7 +144,7 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() { } private fun getDeleteOptions(): List { - if (!viewModel.showExpirationTypeSelector) return emptyList() + if (!viewModel.uiState.value.showExpirationTypeSelector) return emptyList() val deleteTypeOptions = mutableListOf() if (ExpirationConfiguration.isNewConfigEnabled) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt index beb4e377c5..9bdd2f42a2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import org.session.libsession.messaging.messages.ExpirationConfiguration import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate @@ -28,8 +29,8 @@ class ExpirationSettingsViewModel( private val storage: Storage ) : ViewModel() { - var showExpirationTypeSelector: Boolean = false - private set + private val _uiState = MutableStateFlow(ExpirationSettingsUiState()) + val uiState: StateFlow = _uiState private var expirationConfig: ExpirationConfiguration? = null @@ -50,7 +51,9 @@ class ExpirationSettingsViewModel( expirationConfig = storage.getExpirationConfiguration(threadId) val recipient = threadDb.getRecipientForThreadId(threadId) _recipient.value = recipient - showExpirationTypeSelector = !ExpirationConfiguration.isNewConfigEnabled || (recipient?.isContactRecipient == true && !recipient.isLocalNumber) + _uiState.update { + it.copy(showExpirationTypeSelector = !ExpirationConfiguration.isNewConfigEnabled || (recipient?.isContactRecipient == true && !recipient.isLocalNumber)) + } if (ExpirationConfiguration.isNewConfigEnabled && (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true)) { _selectedExpirationType.value = ExpirationType.DELETE_AFTER_SEND.number } else { @@ -105,6 +108,9 @@ class ExpirationSettingsViewModel( message.recipient = address.serialize() message.sentTimestamp = System.currentTimeMillis() MessageSender.send(message, address) + _uiState.update { + it.copy(settingsSaved = true) + } } @dagger.assisted.AssistedFactory @@ -135,4 +141,9 @@ class ExpirationSettingsViewModel( ) as T } } -} \ No newline at end of file +} + +data class ExpirationSettingsUiState( + val showExpirationTypeSelector: Boolean = false, + val settingsSaved: Boolean? = null +)