Close expiration settings screen after save

This commit is contained in:
charles 2022-12-19 12:41:17 +11:00
parent 065417ebbb
commit 70abf8a4d2
2 changed files with 26 additions and 8 deletions

View File

@ -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<RadioOption> {
if (!viewModel.showExpirationTypeSelector) return emptyList()
if (!viewModel.uiState.value.showExpirationTypeSelector) return emptyList()
val deleteTypeOptions = mutableListOf<RadioOption>()
if (ExpirationConfiguration.isNewConfigEnabled) {

View File

@ -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<ExpirationSettingsUiState> = _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
@ -136,3 +142,8 @@ class ExpirationSettingsViewModel(
}
}
}
data class ExpirationSettingsUiState(
val showExpirationTypeSelector: Boolean = false,
val settingsSaved: Boolean? = null
)