Login screens: Fix navigation issue
This commit is contained in:
parent
adf299081d
commit
5b9876a20c
|
@ -21,6 +21,7 @@ import im.vector.matrix.android.api.failure.MatrixError
|
|||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import java.net.SocketTimeoutException
|
||||
import java.net.UnknownHostException
|
||||
import javax.inject.Inject
|
||||
|
||||
class ErrorFormatter @Inject constructor(private val stringProvider: StringProvider) {
|
||||
|
@ -36,6 +37,9 @@ class ErrorFormatter @Inject constructor(private val stringProvider: StringProvi
|
|||
is Failure.NetworkConnection -> {
|
||||
if (throwable.ioException is SocketTimeoutException) {
|
||||
stringProvider.getString(R.string.error_network_timeout)
|
||||
} else if (throwable.ioException is UnknownHostException) {
|
||||
// Invalid homeserver?
|
||||
stringProvider.getString(R.string.login_error_unknown_host)
|
||||
} else {
|
||||
stringProvider.getString(R.string.error_no_network)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import android.content.Intent
|
|||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.viewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import im.vector.riotx.R
|
||||
|
@ -69,7 +68,7 @@ class LoginActivity : VectorBaseActivity() {
|
|||
is LoginNavigation.OpenServerSelection -> addFragmentToBackstack(R.id.loginFragmentContainer, LoginServerSelectionFragment::class.java)
|
||||
is LoginNavigation.OnServerSelectionDone -> onServerSelectionDone()
|
||||
is LoginNavigation.OnSignModeSelected -> onSignModeSelected(it)
|
||||
is LoginNavigation.OnLoginFlowRetrieved -> onLoginFlowRetrieved(it)
|
||||
is LoginNavigation.OnLoginFlowRetrieved -> onLoginFlowRetrieved()
|
||||
is LoginNavigation.OnSsoLoginFallbackError -> onSsoLoginFallbackError(it)
|
||||
}
|
||||
}
|
||||
|
@ -82,16 +81,12 @@ class LoginActivity : VectorBaseActivity() {
|
|||
.disposeOnDestroy()
|
||||
}
|
||||
|
||||
private fun onLoginFlowRetrieved(onLoginFlowRetrieved: LoginNavigation.OnLoginFlowRetrieved) {
|
||||
when (onLoginFlowRetrieved.loginMode) {
|
||||
LoginMode.Sso -> addFragmentToBackstack(R.id.loginFragmentContainer, LoginSsoFallbackFragment::class.java)
|
||||
LoginMode.Unsupported,
|
||||
LoginMode.Password -> addFragmentToBackstack(R.id.loginFragmentContainer, LoginSignUpSignInSelectionFragment::class.java)
|
||||
}
|
||||
private fun onLoginFlowRetrieved() {
|
||||
addFragmentToBackstack(R.id.loginFragmentContainer, LoginSignUpSignInSelectionFragment::class.java)
|
||||
}
|
||||
|
||||
private fun updateWithState(loginViewState: LoginViewState) {
|
||||
if (loginViewState.asyncLoginAction is Success) {
|
||||
if (loginViewState.isUserLogged()) {
|
||||
val intent = HomeActivity.newIntent(this)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
|
@ -123,11 +118,21 @@ class LoginActivity : VectorBaseActivity() {
|
|||
}
|
||||
|
||||
private fun onSignModeSelected(mode: LoginNavigation.OnSignModeSelected) {
|
||||
// We cannot use the state, it is not ready...
|
||||
// We cannot use the state to get the SignMode, it is not ready...
|
||||
when (mode.signMode) {
|
||||
SignMode.Unknown -> error("Sign mode has to be set before calling this method")
|
||||
SignMode.SignUp -> Unit // TODO addFragmentToBackstack(R.id.loginFragmentContainer, SignUpFragment::class.java)
|
||||
SignMode.SignIn -> addFragmentToBackstack(R.id.loginFragmentContainer, LoginFragment::class.java)
|
||||
SignMode.SignIn -> {
|
||||
// It depends on the LoginMode
|
||||
withState(loginViewModel) {
|
||||
when (it.asyncHomeServerLoginFlowRequest.invoke()) {
|
||||
null -> error("Developer error")
|
||||
LoginMode.Password -> addFragmentToBackstack(R.id.loginFragmentContainer, LoginFragment::class.java)
|
||||
LoginMode.Sso -> addFragmentToBackstack(R.id.loginFragmentContainer, LoginSsoFallbackFragment::class.java)
|
||||
LoginMode.Unsupported -> TODO() // TODO Import Fallback login fragment from Riot-Android
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright 2019 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.riotx.features.login
|
||||
|
||||
enum class LoginMode {
|
||||
Password,
|
||||
Sso,
|
||||
Unsupported
|
||||
}
|
|
@ -22,7 +22,7 @@ import im.vector.riotx.core.platform.VectorSharedAction
|
|||
sealed class LoginNavigation : VectorSharedAction {
|
||||
object OpenServerSelection : LoginNavigation()
|
||||
object OnServerSelectionDone : LoginNavigation()
|
||||
data class OnLoginFlowRetrieved(val loginMode: LoginMode) : LoginNavigation()
|
||||
object OnLoginFlowRetrieved : LoginNavigation()
|
||||
data class OnSignModeSelected(val signMode: SignMode) : LoginNavigation()
|
||||
//object OpenSsoLoginFallback : LoginNavigation()
|
||||
data class OnSsoLoginFallbackError(val errorCode: Int, val description: String, val failingUrl: String) : LoginNavigation()
|
||||
|
|
|
@ -112,7 +112,7 @@ class LoginServerSelectionFragment @Inject constructor() : AbstractLoginFragment
|
|||
}
|
||||
is Success -> {
|
||||
// The home server url is valid
|
||||
loginSharedActionViewModel.post(LoginNavigation.OnLoginFlowRetrieved(it.asyncHomeServerLoginFlowRequest.invoke()))
|
||||
loginSharedActionViewModel.post(LoginNavigation.OnLoginFlowRetrieved)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ class LoginServerUrlFormFragment @Inject constructor(
|
|||
}
|
||||
is Success -> {
|
||||
// The home server url is valid
|
||||
loginSharedActionViewModel.post(LoginNavigation.OnLoginFlowRetrieved(state.asyncHomeServerLoginFlowRequest.invoke()))
|
||||
loginSharedActionViewModel.post(LoginNavigation.OnLoginFlowRetrieved)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,7 @@
|
|||
|
||||
package im.vector.riotx.features.login
|
||||
|
||||
import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.Loading
|
||||
import com.airbnb.mvrx.MvRxState
|
||||
import com.airbnb.mvrx.Uninitialized
|
||||
import com.airbnb.mvrx.*
|
||||
|
||||
data class LoginViewState(
|
||||
val serverType: ServerType = ServerType.MatrixOrg,
|
||||
|
@ -33,10 +30,10 @@ data class LoginViewState(
|
|||
return asyncLoginAction is Loading
|
||||
|| asyncHomeServerLoginFlowRequest is Loading
|
||||
}
|
||||
|
||||
fun isUserLogged(): Boolean {
|
||||
// TODO Add other async here
|
||||
return asyncLoginAction is Success
|
||||
}
|
||||
}
|
||||
|
||||
enum class LoginMode {
|
||||
Password,
|
||||
Sso,
|
||||
Unsupported
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue