mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Login: some cleanup
This commit is contained in:
parent
5fbd271b1c
commit
3ccdf4a244
5 changed files with 16 additions and 18 deletions
|
@ -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()
|
||||
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ class LoginFragment : VectorBaseFragment() {
|
|||
}
|
||||
|
||||
private fun openSso() {
|
||||
viewModel.openSso()
|
||||
viewModel.handle(LoginActions.NavigateTo(LoginActivity.Navigation.OpenSsoLoginFallback))
|
||||
}
|
||||
|
||||
private fun setupPasswordReveal() {
|
||||
|
|
|
@ -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?) {
|
||||
|
|
|
@ -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() ?: ""
|
||||
}
|
||||
|
|
|
@ -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" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue