Cleanup the ViewModels

This commit is contained in:
Benoit Marty 2021-11-22 16:45:18 +01:00
parent e10af6476f
commit aee34ad552
3 changed files with 17 additions and 28 deletions

View File

@ -25,7 +25,6 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.EmptyViewEvents import im.vector.app.core.platform.EmptyViewEvents
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.settings.VectorDataStore import im.vector.app.features.settings.VectorDataStore
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class DebugPrivateSettingsViewModel @AssistedInject constructor( class DebugPrivateSettingsViewModel @AssistedInject constructor(
@ -45,14 +44,12 @@ class DebugPrivateSettingsViewModel @AssistedInject constructor(
} }
private fun observeVectorDataStore() { private fun observeVectorDataStore() {
vectorDataStore.forceDialPadDisplayFlow.onEach { vectorDataStore.forceDialPadDisplayFlow.setOnEach {
setState {
copy( copy(
dialPadVisible = it dialPadVisible = it
) )
} }
} }
}
override fun handle(action: DebugPrivateSettingsViewActions) { override fun handle(action: DebugPrivateSettingsViewActions) {
when (action) { when (action) {

View File

@ -38,7 +38,6 @@ import im.vector.app.features.invite.showInvites
import im.vector.app.features.settings.VectorDataStore import im.vector.app.features.settings.VectorDataStore
import im.vector.app.features.ui.UiStateRepository import im.vector.app.features.ui.UiStateRepository
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flatMapLatest
@ -104,19 +103,16 @@ class HomeDetailViewModel @AssistedInject constructor(
private var forceDialPad = false private var forceDialPad = false
private fun observeDataStore() { private fun observeDataStore() {
viewModelScope.launch { vectorDataStore.pushCounterFlow.setOnEach { nbOfPush ->
vectorDataStore.pushCounterFlow.collect { nbOfPush ->
setState {
copy( copy(
pushCounter = nbOfPush pushCounter = nbOfPush
) )
} }
}
vectorDataStore.forceDialPadDisplayFlow.collect { force -> vectorDataStore.forceDialPadDisplayFlow.onEach { force ->
forceDialPad = force forceDialPad = force
updateShowDialPadTab() updateShowDialPadTab()
} }.launchIn(viewModelScope)
}
} }
override fun handle(action: HomeDetailAction) { override fun handle(action: HomeDetailAction) {

View File

@ -195,16 +195,12 @@ class RoomDetailViewModel @AssistedInject constructor(
} }
private fun observeDataStore() { private fun observeDataStore() {
viewModelScope.launch { vectorDataStore.pushCounterFlow.setOnEach { nbOfPush ->
vectorDataStore.pushCounterFlow.collect { nbOfPush ->
setState {
copy( copy(
pushCounter = nbOfPush pushCounter = nbOfPush
) )
} }
} }
}
}
private fun prepareForEncryption() { private fun prepareForEncryption() {
// check if there is not already a call made, or if there has been an error // check if there is not already a call made, or if there has been an error