Room settings: use boolean instead of Async

This commit is contained in:
Benoit Marty 2020-01-20 17:41:29 +01:00
parent 28db05e509
commit d672313649
3 changed files with 5 additions and 6 deletions

View file

@ -20,7 +20,6 @@ import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
@ -82,7 +81,7 @@ class RoomSettingsFragment @Inject constructor(
}
private fun renderRoomSummary(state: RoomSettingsViewState) {
waiting_view.isVisible = state.currentRequest is Loading
waiting_view.isVisible = state.isLoading
state.roomSummary()?.let {
roomSettingsToolbarTitleView.text = it.displayName

View file

@ -71,13 +71,13 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
private fun handleEnableEncryption() {
setState {
copy(currentRequest = Loading())
copy(isLoading = true)
}
room.enableEncryption(MXCRYPTO_ALGORITHM_MEGOLM, object : MatrixCallback<Unit> {
override fun onFailure(failure: Throwable) {
setState {
copy(currentRequest = Uninitialized)
copy(isLoading = false)
}
_requestErrorLiveData.postLiveEvent(failure)
@ -85,7 +85,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
override fun onSuccess(data: Unit) {
setState {
copy(currentRequest = Uninitialized)
copy(isLoading = false)
}
}
})

View file

@ -25,7 +25,7 @@ import im.vector.riotx.features.roomprofile.RoomProfileArgs
data class RoomSettingsViewState(
val roomId: String,
val roomSummary: Async<RoomSummary> = Uninitialized,
val currentRequest: Async<Unit> = Uninitialized
val isLoading: Boolean = false
) : MvRxState {
constructor(args: RoomProfileArgs) : this(roomId = args.roomId)