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