Room creation Fragment: no more "Retry" action, loading and error displayed in a dialog

This commit is contained in:
Benoit Marty 2020-11-18 14:51:10 +01:00
parent 507d5d3758
commit 514263ae12
8 changed files with 40 additions and 44 deletions

View File

@ -22,7 +22,9 @@ import org.matrix.android.sdk.api.failure.MatrixError
sealed class CreateRoomFailure : Failure.FeatureFailure() {
object CreatedWithTimeout : CreateRoomFailure()
data class CreatedWithFederationFailure(val matrixError: MatrixError) : CreateRoomFailure()
object RoomAliasEmpty: CreateRoomFailure()
object RoomAliasNotAvailable: CreateRoomFailure()
object RoomAliasInvalid: CreateRoomFailure()
sealed class RoomAliasError : CreateRoomFailure() {
object AliasEmpty : RoomAliasError()
object AliasNotAvailable : RoomAliasError()
object AliasInvalid : RoomAliasError()
}
}

View File

@ -66,7 +66,7 @@ internal class DefaultCreateRoomTask @Inject constructor(
if (params.preset == CreateRoomPreset.PRESET_PUBLIC_CHAT) {
if (params.roomAliasName.isNullOrEmpty()) {
throw CreateRoomFailure.RoomAliasEmpty
throw CreateRoomFailure.RoomAliasError.AliasEmpty
}
// Check alias availability
val fullAlias = "#" + params.roomAliasName + ":" + userId.substringAfter(":")
@ -85,7 +85,7 @@ internal class DefaultCreateRoomTask @Inject constructor(
}
?.let {
// Alias already exists: error case
throw CreateRoomFailure.RoomAliasNotAvailable
throw CreateRoomFailure.RoomAliasError.AliasNotAvailable
}
}
@ -104,7 +104,7 @@ internal class DefaultCreateRoomTask @Inject constructor(
} else if (throwable.httpCode == 400
&& throwable.error.code == MatrixError.M_UNKNOWN
&& throwable.error.message == "Invalid characters in room alias") {
throw CreateRoomFailure.RoomAliasInvalid
throw CreateRoomFailure.RoomAliasError.AliasInvalid
}
}
throw throwable

View File

@ -44,32 +44,8 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
var index = 0
override fun buildModels(viewState: CreateRoomViewState) {
when (val asyncCreateRoom = viewState.asyncCreateRoomRequest) {
is Success -> {
// Nothing to display, the screen will be closed
}
is Loading -> {
// display the form
buildForm(viewState, false)
loadingItem {
id("loading")
}
}
is Uninitialized -> {
// display the form
buildForm(viewState, true)
}
is Fail -> {
// display the form
buildForm(viewState, true)
// TODO BMA DO NOT COMMIT Update this
errorWithRetryItem {
id("error")
text(errorFormatter.toHumanReadable(asyncCreateRoom.error))
listener { listener?.retry() }
}
}
}
// display the form
buildForm(viewState, viewState.asyncCreateRoomRequest !is Loading)
}
private fun buildForm(viewState: CreateRoomViewState, enableFormElement: Boolean) {
@ -133,10 +109,10 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
homeServer(":" + viewState.homeServerName)
errorMessage(
when ((viewState.asyncCreateRoomRequest as? Fail)?.error) {
is CreateRoomFailure.RoomAliasEmpty -> R.string.create_room_alias_empty
is CreateRoomFailure.RoomAliasNotAvailable -> R.string.create_room_alias_already_in_use
is CreateRoomFailure.RoomAliasInvalid -> R.string.create_room_alias_invalid
else -> null
is CreateRoomFailure.RoomAliasError.AliasEmpty -> R.string.create_room_alias_empty
is CreateRoomFailure.RoomAliasError.AliasNotAvailable -> R.string.create_room_alias_already_in_use
is CreateRoomFailure.RoomAliasError.AliasInvalid -> R.string.create_room_alias_invalid
else -> null
}
?.let { stringProvider.getString(it) }
)
@ -195,7 +171,6 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
fun setIsPublic(isPublic: Boolean)
fun setAliasLocalPart(aliasLocalPart: String)
fun setIsEncrypted(isEncrypted: Boolean)
fun retry()
fun toggleShowAdvanced()
fun setDisableFederation(disableFederation: Boolean)
fun submit()

View File

@ -21,6 +21,8 @@ import android.os.Bundle
import android.os.Parcelable
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel
@ -37,7 +39,8 @@ import im.vector.app.features.roomdirectory.RoomDirectorySharedAction
import im.vector.app.features.roomdirectory.RoomDirectorySharedActionViewModel
import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.fragment_create_room.*
import timber.log.Timber
import kotlinx.android.synthetic.main.merge_overlay_waiting_view.*
import org.matrix.android.sdk.api.session.room.failure.CreateRoomFailure
import javax.inject.Inject
@Parcelize
@ -66,17 +69,31 @@ class CreateRoomFragment @Inject constructor(
super.onViewCreated(view, savedInstanceState)
vectorBaseActivity.setSupportActionBar(createRoomToolbar)
sharedActionViewModel = activityViewModelProvider.get(RoomDirectorySharedActionViewModel::class.java)
setupWaitingView()
setupRecyclerView()
createRoomClose.debouncedClicks {
sharedActionViewModel.post(RoomDirectorySharedAction.Back)
}
viewModel.observeViewEvents {
when (it) {
CreateRoomViewEvents.Quit -> vectorBaseActivity.onBackPressed()
CreateRoomViewEvents.Quit -> vectorBaseActivity.onBackPressed()
is CreateRoomViewEvents.Failure -> showFailure(it.throwable)
}.exhaustive
}
}
override fun showFailure(throwable: Throwable) {
// Note: RoomAliasError are displayed directly in the form
if (throwable !is CreateRoomFailure.RoomAliasError) {
super.showFailure(throwable)
}
}
private fun setupWaitingView() {
waiting_view_status_text.isVisible = true
waiting_view_status_text.setText(R.string.create_room_in_progress)
}
override fun onDestroyView() {
createRoomForm.cleanup()
createRoomController.listener = null
@ -132,11 +149,6 @@ class CreateRoomFragment @Inject constructor(
viewModel.handle(CreateRoomAction.Create)
}
override fun retry() {
Timber.v("Retry")
viewModel.handle(CreateRoomAction.Create)
}
override fun onBackPressed(toolbarButton: Boolean): Boolean {
return withState(viewModel) {
return@withState if (!it.isEmpty()) {
@ -157,6 +169,7 @@ class CreateRoomFragment @Inject constructor(
override fun invalidate() = withState(viewModel) { state ->
val async = state.asyncCreateRoomRequest
waiting_view.isVisible = async is Loading
if (async is Success) {
// Navigate to freshly created room
navigator.openRoom(requireActivity(), async())

View File

@ -22,5 +22,6 @@ import im.vector.app.core.platform.VectorViewEvents
* Transient events for room creation screen
*/
sealed class CreateRoomViewEvents : VectorViewEvents {
data class Failure(val throwable: Throwable) : CreateRoomViewEvents()
object Quit : CreateRoomViewEvents()
}

View File

@ -36,6 +36,7 @@ import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.raw.RawService
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.failure.CreateRoomFailure
import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset
@ -221,6 +222,7 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
setState {
copy(asyncCreateRoomRequest = Fail(failure))
}
_viewEvents.post(CreateRoomViewEvents.Failure(failure))
}
})
}

View File

@ -67,5 +67,7 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<include layout="@layout/merge_overlay_waiting_view" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -2104,6 +2104,7 @@
<string name="create_room_alias_already_in_use">This address is already in use</string>
<string name="create_room_alias_empty">Please provide a room address</string>
<string name="create_room_alias_invalid">Some characters are not allowed</string>
<string name="create_room_in_progress">Creating room…</string>
<string name="login_error_threepid_denied">Your email domain is not authorized to register on this server</string>