Login: some cleanup

This commit is contained in:
Benoit Marty 2019-09-13 15:27:08 +02:00 committed by Benoit Marty
parent 5fbd271b1c
commit 3ccdf4a244
5 changed files with 16 additions and 18 deletions

View file

@ -23,5 +23,6 @@ sealed class LoginActions {
data class UpdateHomeServer(val homeServerUrl: String) : LoginActions()
data class Login(val login: String, val password: String) : LoginActions()
data class SsoLoginSuccess(val credentials: Credentials) : LoginActions()
data class NavigateTo(val target: LoginActivity.Navigation) : LoginActions()
}

View file

@ -112,7 +112,7 @@ class LoginFragment : VectorBaseFragment() {
}
private fun openSso() {
viewModel.openSso()
viewModel.handle(LoginActions.NavigateTo(LoginActivity.Navigation.OpenSsoLoginFallback))
}
private fun setupPasswordReveal() {

View file

@ -67,7 +67,7 @@ class LoginSsoFallbackFragment : VectorBaseFragment() {
super.onViewCreated(view, savedInstanceState)
setupToolbar(login_sso_fallback_toolbar)
requireActivity().setTitle(R.string.login)
login_sso_fallback_toolbar.title = getString(R.string.login)
setupWebview()
}
@ -143,8 +143,8 @@ class LoginSsoFallbackFragment : VectorBaseFragment() {
override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) {
super.onReceivedError(view, errorCode, description, failingUrl)
// on error case, close this activity
viewModel.goBack()
// on error case, close this fragment
viewModel.handle(LoginActions.NavigateTo(LoginActivity.Navigation.GoBack))
}
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {

View file

@ -36,9 +36,10 @@ import im.vector.riotx.core.utils.LiveEvent
import im.vector.riotx.features.notifications.PushRuleTriggerListener
class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginViewState,
val authenticator: Authenticator,
val activeSessionHolder: ActiveSessionHolder,
val pushRuleTriggerListener: PushRuleTriggerListener) : VectorViewModel<LoginViewState>(initialState) {
private val authenticator: Authenticator,
private val activeSessionHolder: ActiveSessionHolder,
private val pushRuleTriggerListener: PushRuleTriggerListener)
: VectorViewModel<LoginViewState>(initialState) {
@AssistedInject.Factory
interface Factory {
@ -58,7 +59,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
val navigationLiveData: LiveData<LiveEvent<LoginActivity.Navigation>>
get() = _navigationLiveData
var homeServerConnectionConfig: HomeServerConnectionConfig? = null
private var homeServerConnectionConfig: HomeServerConnectionConfig? = null
private var currentTask: Cancelable? = null
@ -67,6 +68,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
is LoginActions.UpdateHomeServer -> handleUpdateHomeserver(action)
is LoginActions.Login -> handleLogin(action)
is LoginActions.SsoLoginSuccess -> handleSsoLoginSuccess(action)
is LoginActions.NavigateTo -> handleNavigation(action)
}
}
@ -174,22 +176,16 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
}
}
private fun handleNavigation(action: LoginActions.NavigateTo) {
_navigationLiveData.postValue(LiveEvent(action.target))
}
override fun onCleared() {
super.onCleared()
currentTask?.cancel()
}
fun openSso() {
// Navigate to SSO
_navigationLiveData.postValue(LiveEvent(LoginActivity.Navigation.OpenSsoLoginFallback))
}
fun goBack() {
// Navigate back
_navigationLiveData.postValue(LiveEvent(LoginActivity.Navigation.GoBack))
}
fun getHomeServerUrl(): String {
return homeServerConnectionConfig?.homeServerUri?.toString() ?: ""
}

View file

@ -10,6 +10,7 @@
style="@style/VectorToolbarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
tools:subtitle="https://www.example.org"
tools:title="@string/auth_login" />