mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Close expiration settings screen after save
This commit is contained in:
parent
065417ebbb
commit
70abf8a4d2
@ -105,6 +105,13 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
|
|||||||
viewModel.onSetClick()
|
viewModel.onSetClick()
|
||||||
}
|
}
|
||||||
lifecycleScope.launchWhenStarted {
|
lifecycleScope.launchWhenStarted {
|
||||||
|
launch {
|
||||||
|
viewModel.uiState.collect { uiState ->
|
||||||
|
if (uiState.settingsSaved == true) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
launch {
|
launch {
|
||||||
viewModel.selectedExpirationType.collect { type ->
|
viewModel.selectedExpirationType.collect { type ->
|
||||||
val position = deleteTypeOptions.indexOfFirst { it.value.toIntOrNull() == type }
|
val position = deleteTypeOptions.indexOfFirst { it.value.toIntOrNull() == type }
|
||||||
@ -119,15 +126,15 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
|
|||||||
}
|
}
|
||||||
launch {
|
launch {
|
||||||
viewModel.expirationTimerOptions.collect { options ->
|
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()
|
binding.layoutTimer.isVisible = options.isNotEmpty()
|
||||||
timerOptionAdapter.submitList(options)
|
timerOptionAdapter.submitList(options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
launch {
|
launch {
|
||||||
viewModel.recipient.collect {
|
viewModel.recipient.collect {
|
||||||
binding.textViewDeleteType.isVisible = viewModel.showExpirationTypeSelector
|
binding.textViewDeleteType.isVisible = viewModel.uiState.value.showExpirationTypeSelector
|
||||||
binding.layoutDeleteTypes.isVisible = viewModel.showExpirationTypeSelector
|
binding.layoutDeleteTypes.isVisible = viewModel.uiState.value.showExpirationTypeSelector
|
||||||
binding.textViewFooter.isVisible = it?.isClosedGroupRecipient == true
|
binding.textViewFooter.isVisible = it?.isClosedGroupRecipient == true
|
||||||
binding.textViewFooter.text = HtmlCompat.fromHtml(getString(R.string.activity_expiration_settings_group_footer), HtmlCompat.FROM_HTML_MODE_COMPACT)
|
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> {
|
private fun getDeleteOptions(): List<RadioOption> {
|
||||||
if (!viewModel.showExpirationTypeSelector) return emptyList()
|
if (!viewModel.uiState.value.showExpirationTypeSelector) return emptyList()
|
||||||
|
|
||||||
val deleteTypeOptions = mutableListOf<RadioOption>()
|
val deleteTypeOptions = mutableListOf<RadioOption>()
|
||||||
if (ExpirationConfiguration.isNewConfigEnabled) {
|
if (ExpirationConfiguration.isNewConfigEnabled) {
|
||||||
|
@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.StateFlow
|
|||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.mapLatest
|
import kotlinx.coroutines.flow.mapLatest
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
||||||
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
||||||
@ -28,8 +29,8 @@ class ExpirationSettingsViewModel(
|
|||||||
private val storage: Storage
|
private val storage: Storage
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
var showExpirationTypeSelector: Boolean = false
|
private val _uiState = MutableStateFlow(ExpirationSettingsUiState())
|
||||||
private set
|
val uiState: StateFlow<ExpirationSettingsUiState> = _uiState
|
||||||
|
|
||||||
private var expirationConfig: ExpirationConfiguration? = null
|
private var expirationConfig: ExpirationConfiguration? = null
|
||||||
|
|
||||||
@ -50,7 +51,9 @@ class ExpirationSettingsViewModel(
|
|||||||
expirationConfig = storage.getExpirationConfiguration(threadId)
|
expirationConfig = storage.getExpirationConfiguration(threadId)
|
||||||
val recipient = threadDb.getRecipientForThreadId(threadId)
|
val recipient = threadDb.getRecipientForThreadId(threadId)
|
||||||
_recipient.value = recipient
|
_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)) {
|
if (ExpirationConfiguration.isNewConfigEnabled && (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true)) {
|
||||||
_selectedExpirationType.value = ExpirationType.DELETE_AFTER_SEND.number
|
_selectedExpirationType.value = ExpirationType.DELETE_AFTER_SEND.number
|
||||||
} else {
|
} else {
|
||||||
@ -105,6 +108,9 @@ class ExpirationSettingsViewModel(
|
|||||||
message.recipient = address.serialize()
|
message.recipient = address.serialize()
|
||||||
message.sentTimestamp = System.currentTimeMillis()
|
message.sentTimestamp = System.currentTimeMillis()
|
||||||
MessageSender.send(message, address)
|
MessageSender.send(message, address)
|
||||||
|
_uiState.update {
|
||||||
|
it.copy(settingsSaved = true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@dagger.assisted.AssistedFactory
|
@dagger.assisted.AssistedFactory
|
||||||
@ -136,3 +142,8 @@ class ExpirationSettingsViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class ExpirationSettingsUiState(
|
||||||
|
val showExpirationTypeSelector: Boolean = false,
|
||||||
|
val settingsSaved: Boolean? = null
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user