mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Add event flow
This commit is contained in:
parent
b65a383ac5
commit
c22860665e
@ -100,20 +100,22 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
|
||||
|
||||
binding.container.setContent { DisappearingMessagesScreen() }
|
||||
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
viewModel.event.collect {
|
||||
if (it.saveSuccess) {
|
||||
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(this@ExpirationSettingsActivity)
|
||||
finish()
|
||||
} else showToast(getString(R.string.ExpirationSettingsActivity_settings_not_updated))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
viewModel.state.collect { state ->
|
||||
actionBar?.subtitle = state.subtitle(this@ExpirationSettingsActivity)
|
||||
|
||||
when (state.settingsSaved) {
|
||||
true -> {
|
||||
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(this@ExpirationSettingsActivity)
|
||||
finish()
|
||||
}
|
||||
false -> showToast(getString(R.string.ExpirationSettingsActivity_settings_not_updated))
|
||||
else -> {}
|
||||
}
|
||||
|
||||
// val position = deleteTypeOptions.indexOfFirst { it.value == state.selectedExpirationType }
|
||||
// deleteTypeOptionAdapter.setSelectedPosition(max(0, position))
|
||||
}
|
||||
|
@ -7,9 +7,11 @@ import androidx.lifecycle.viewModelScope
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import network.loki.messenger.BuildConfig
|
||||
@ -43,6 +45,9 @@ class ExpirationSettingsViewModel(
|
||||
private val storage: Storage
|
||||
) : ViewModel() {
|
||||
|
||||
private val _event = Channel<Event>()
|
||||
val event = _event.receiveAsFlow()
|
||||
|
||||
private val _state = MutableStateFlow(State())
|
||||
val state = _state.asStateFlow()
|
||||
|
||||
@ -171,9 +176,7 @@ class ExpirationSettingsViewModel(
|
||||
}
|
||||
val address = state.recipient?.address
|
||||
if (address == null || expirationConfig?.expiryMode == typeValue) {
|
||||
_state.update {
|
||||
it.copy(settingsSaved = false)
|
||||
}
|
||||
_event.send(Event(false))
|
||||
return@launch
|
||||
}
|
||||
|
||||
@ -187,9 +190,7 @@ class ExpirationSettingsViewModel(
|
||||
messageExpirationManager.setExpirationTimer(message, typeValue)
|
||||
|
||||
MessageSender.send(message, address)
|
||||
_state.update {
|
||||
it.copy(settingsSaved = true)
|
||||
}
|
||||
_event.send(Event(true))
|
||||
}
|
||||
|
||||
@dagger.assisted.AssistedFactory
|
||||
@ -218,10 +219,13 @@ class ExpirationSettingsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
data class Event(
|
||||
val saveSuccess: Boolean
|
||||
)
|
||||
|
||||
data class State(
|
||||
val isGroup: Boolean = false,
|
||||
val isSelfAdmin: Boolean = false,
|
||||
val settingsSaved: Boolean? = null,
|
||||
val recipient: Recipient? = null,
|
||||
val expiryMode: ExpiryMode? = null,
|
||||
val types: List<ExpiryType> = emptyList()
|
||||
|
Loading…
Reference in New Issue
Block a user