mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Let the View model compute the state
This commit is contained in:
parent
f62ab84e59
commit
96720af52f
@ -51,8 +51,7 @@ class RoomDirectoryPickerController @Inject constructor(
|
||||
private val stringProvider: StringProvider,
|
||||
private val colorProvider: ColorProvider,
|
||||
private val dimensionConverter: DimensionConverter,
|
||||
private val errorFormatter: ErrorFormatter,
|
||||
private val roomDirectoryListCreator: RoomDirectoryListCreator
|
||||
private val errorFormatter: ErrorFormatter
|
||||
) : TypedEpoxyController<RoomDirectoryPickerViewState>() {
|
||||
|
||||
var currentRoomDirectoryData: RoomDirectoryData? = null
|
||||
@ -65,11 +64,7 @@ class RoomDirectoryPickerController @Inject constructor(
|
||||
|
||||
when (val asyncThirdPartyProtocol = data.asyncThirdPartyRequest) {
|
||||
is Success -> {
|
||||
val directories = roomDirectoryListCreator.computeDirectories(
|
||||
asyncThirdPartyProtocol(),
|
||||
data.customHomeservers
|
||||
)
|
||||
directories.join(
|
||||
data.directories.join(
|
||||
each = { _, roomDirectoryServer -> buildDirectory(roomDirectoryServer) },
|
||||
between = { idx, _ -> buildDivider(idx) }
|
||||
)
|
||||
|
@ -38,7 +38,8 @@ import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsPa
|
||||
class RoomDirectoryPickerViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: RoomDirectoryPickerViewState,
|
||||
private val session: Session,
|
||||
private val uiStateRepository: UiStateRepository
|
||||
private val uiStateRepository: UiStateRepository,
|
||||
private val roomDirectoryListCreator: RoomDirectoryListCreator
|
||||
) : VectorViewModel<RoomDirectoryPickerViewState, RoomDirectoryPickerAction, EmptyViewEvents>(initialState) {
|
||||
|
||||
@AssistedFactory
|
||||
@ -56,10 +57,24 @@ class RoomDirectoryPickerViewModel @AssistedInject constructor(
|
||||
}
|
||||
|
||||
init {
|
||||
observeAndCompute()
|
||||
load()
|
||||
loadCustomRoomDirectoryHomeservers()
|
||||
}
|
||||
|
||||
private fun observeAndCompute() {
|
||||
selectSubscribe(
|
||||
RoomDirectoryPickerViewState::asyncThirdPartyRequest,
|
||||
RoomDirectoryPickerViewState::customHomeservers
|
||||
) { async, custom ->
|
||||
async()?.let {
|
||||
setState {
|
||||
copy(directories = roomDirectoryListCreator.computeDirectories(it, custom))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun load() {
|
||||
viewModelScope.launch {
|
||||
setState {
|
||||
|
@ -19,6 +19,7 @@ package im.vector.app.features.roomdirectory.picker
|
||||
import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.MvRxState
|
||||
import com.airbnb.mvrx.Uninitialized
|
||||
import im.vector.app.features.roomdirectory.RoomDirectoryServer
|
||||
import org.matrix.android.sdk.api.session.room.model.thirdparty.ThirdPartyProtocol
|
||||
|
||||
data class RoomDirectoryPickerViewState(
|
||||
@ -26,5 +27,7 @@ data class RoomDirectoryPickerViewState(
|
||||
val customHomeservers: Set<String> = emptySet(),
|
||||
val inEditMode: Boolean = false,
|
||||
val enteredServer: String = "",
|
||||
val addServerAsync: Async<Unit> = Uninitialized
|
||||
val addServerAsync: Async<Unit> = Uninitialized,
|
||||
// computed
|
||||
val directories: List<RoomDirectoryServer> = emptyList()
|
||||
) : MvRxState
|
||||
|
Loading…
Reference in New Issue
Block a user