Create Uri extension and cleanup login code

This commit is contained in:
Benoit Marty 2019-12-11 16:39:20 +01:00
parent bb85d41f05
commit a193b2659d
8 changed files with 24 additions and 18 deletions

View File

@ -37,7 +37,7 @@ class ActiveSessionHolder @Inject constructor(private val authenticationService:
fun setActiveSession(session: Session) {
activeSession.set(session)
sessionObservableStore.post(Option.fromNullable(session))
sessionObservableStore.post(Option.just(session))
keyRequestHandler.start(session)
incomingVerificationRequestHandler.start(session)
}

View File

@ -35,3 +35,13 @@ fun StringBuilder.appendParamToUrl(param: String, value: String): StringBuilder
return this
}
/**
* Ex: "https://matrix.org/" -> "matrix.org"
*/
fun String?.toReducedUrl(): String {
return (this ?: "")
.substringAfter("://")
.trim { it == '/' }
}

View File

@ -96,7 +96,8 @@ class LoginActivity : VectorBaseActivity(), ToolbarConfigurable {
}
loginSharedActionViewModel = viewModelProvider.get(LoginSharedActionViewModel::class.java)
loginSharedActionViewModel.observe()
loginSharedActionViewModel
.observe()
.subscribe {
handleLoginNavigation(it)
}
@ -106,7 +107,6 @@ class LoginActivity : VectorBaseActivity(), ToolbarConfigurable {
.subscribe(this) {
updateWithState(it)
}
.disposeOnDestroy()
loginViewModel.viewEvents
.observe()

View File

@ -32,6 +32,7 @@ import im.vector.riotx.R
import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.hideKeyboard
import im.vector.riotx.core.extensions.showPassword
import im.vector.riotx.core.extensions.toReducedUrl
import io.reactivex.Observable
import io.reactivex.functions.BiFunction
import io.reactivex.rxkotlin.subscribeBy
@ -103,7 +104,7 @@ class LoginFragment @Inject constructor(
ServerType.MatrixOrg -> {
loginServerIcon.isVisible = true
loginServerIcon.setImageResource(R.drawable.ic_logo_matrix_org)
loginTitle.text = getString(resId, state.homeServerUrlSimple)
loginTitle.text = getString(resId, state.homeServerUrl.toReducedUrl())
loginNotice.text = getString(R.string.login_server_matrix_org_text)
}
ServerType.Modular -> {
@ -114,7 +115,7 @@ class LoginFragment @Inject constructor(
}
ServerType.Other -> {
loginServerIcon.isVisible = false
loginTitle.text = getString(resId, state.homeServerUrlSimple)
loginTitle.text = getString(resId, state.homeServerUrl.toReducedUrl())
loginNotice.text = getString(R.string.login_server_other_text)
}
}

View File

@ -29,6 +29,7 @@ import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.hideKeyboard
import im.vector.riotx.core.extensions.isEmail
import im.vector.riotx.core.extensions.showPassword
import im.vector.riotx.core.extensions.toReducedUrl
import io.reactivex.Observable
import io.reactivex.functions.BiFunction
import io.reactivex.rxkotlin.subscribeBy
@ -57,7 +58,7 @@ class LoginResetPasswordFragment @Inject constructor(
}
private fun setupUi(state: LoginViewState) {
resetPasswordTitle.text = getString(R.string.login_reset_password_on, state.homeServerUrlSimple)
resetPasswordTitle.text = getString(R.string.login_reset_password_on, state.homeServerUrl.toReducedUrl())
}
private fun setupSubmitButton() {

View File

@ -21,6 +21,7 @@ import androidx.core.view.isVisible
import butterknife.OnClick
import im.vector.riotx.R
import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.toReducedUrl
import kotlinx.android.synthetic.main.fragment_login_signup_signin_selection.*
import javax.inject.Inject
@ -40,19 +41,19 @@ class LoginSignUpSignInSelectionFragment @Inject constructor(
ServerType.MatrixOrg -> {
loginSignupSigninServerIcon.setImageResource(R.drawable.ic_logo_matrix_org)
loginSignupSigninServerIcon.isVisible = true
loginSignupSigninTitle.text = getString(R.string.login_connect_to, state.homeServerUrlSimple)
loginSignupSigninTitle.text = getString(R.string.login_connect_to, state.homeServerUrl.toReducedUrl())
loginSignupSigninText.text = getString(R.string.login_server_matrix_org_text)
}
ServerType.Modular -> {
loginSignupSigninServerIcon.setImageResource(R.drawable.ic_logo_modular)
loginSignupSigninServerIcon.isVisible = true
loginSignupSigninTitle.text = getString(R.string.login_connect_to_modular)
loginSignupSigninText.text = state.homeServerUrlSimple
loginSignupSigninText.text = state.homeServerUrl.toReducedUrl()
}
ServerType.Other -> {
loginSignupSigninServerIcon.isVisible = false
loginSignupSigninTitle.text = getString(R.string.login_server_other_title)
loginSignupSigninText.text = getString(R.string.login_connect_to, state.homeServerUrlSimple)
loginSignupSigninText.text = getString(R.string.login_connect_to, state.homeServerUrl.toReducedUrl())
}
}
}

View File

@ -54,12 +54,4 @@ data class LoginViewState(
fun isUserLogged(): Boolean {
return asyncLoginAction is Success
}
/**
* Ex: "https://matrix.org/" -> "matrix.org"
*/
val homeServerUrlSimple: String
get() = (homeServerUrl ?: "")
.substringAfter("://")
.trim { it == '/' }
}

View File

@ -26,6 +26,7 @@ import im.vector.riotx.R
import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.configureWith
import im.vector.riotx.core.extensions.toReducedUrl
import im.vector.riotx.core.utils.openUrlInExternalBrowser
import im.vector.riotx.features.login.AbstractLoginFragment
import im.vector.riotx.features.login.LoginAction
@ -115,7 +116,7 @@ class LoginTermsFragment @Inject constructor(
}
override fun updateWithState(state: LoginViewState) {
policyController.homeServer = state.homeServerUrlSimple
policyController.homeServer = state.homeServerUrl.toReducedUrl()
renderState()
}