Login UX flow: warning if no profile can ba found
This commit is contained in:
parent
c141b26212
commit
51a39909dc
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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.app.core.extensions
|
||||||
|
|
||||||
|
import com.airbnb.mvrx.Async
|
||||||
|
import com.airbnb.mvrx.Fail
|
||||||
|
import com.airbnb.mvrx.Success
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It maybe already exist somewhere but I cannot find it
|
||||||
|
*/
|
||||||
|
suspend fun <T> tryAsync(block: suspend () -> T): Async<T> {
|
||||||
|
return try {
|
||||||
|
Success(block.invoke())
|
||||||
|
} catch (failure: Throwable) {
|
||||||
|
Fail(failure)
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,8 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import androidx.autofill.HintConstants
|
import androidx.autofill.HintConstants
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import com.airbnb.mvrx.Fail
|
||||||
import com.jakewharton.rxbinding3.widget.textChanges
|
import com.jakewharton.rxbinding3.widget.textChanges
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.extensions.hideKeyboard
|
import im.vector.app.core.extensions.hideKeyboard
|
||||||
|
@ -31,8 +33,10 @@ import im.vector.app.databinding.FragmentLogin2SigninPasswordBinding
|
||||||
import im.vector.app.features.home.AvatarRenderer
|
import im.vector.app.features.home.AvatarRenderer
|
||||||
import io.reactivex.rxkotlin.subscribeBy
|
import io.reactivex.rxkotlin.subscribeBy
|
||||||
import org.matrix.android.sdk.api.auth.login.LoginProfileInfo
|
import org.matrix.android.sdk.api.auth.login.LoginProfileInfo
|
||||||
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
import org.matrix.android.sdk.api.failure.isInvalidPassword
|
import org.matrix.android.sdk.api.failure.isInvalidPassword
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import javax.net.ssl.HttpsURLConnection
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In this screen:
|
* In this screen:
|
||||||
|
@ -103,13 +107,17 @@ class LoginFragment2SigninPassword @Inject constructor(
|
||||||
// Name and avatar
|
// Name and avatar
|
||||||
views.loginWelcomeBack.text = getString(
|
views.loginWelcomeBack.text = getString(
|
||||||
R.string.login_welcome_back,
|
R.string.login_welcome_back,
|
||||||
state.loginProfileInfo?.displayName?.takeIf { it.isNotBlank() } ?: state.userIdentifier()
|
state.loginProfileInfo()?.displayName?.takeIf { it.isNotBlank() } ?: state.userIdentifier()
|
||||||
)
|
)
|
||||||
|
|
||||||
avatarRenderer.render(
|
avatarRenderer.render(
|
||||||
profileInfo = state.loginProfileInfo ?: LoginProfileInfo(state.userIdentifier(), null, null),
|
profileInfo = state.loginProfileInfo() ?: LoginProfileInfo(state.userIdentifier(), null, null),
|
||||||
imageView = views.loginUserIcon
|
imageView = views.loginUserIcon
|
||||||
)
|
)
|
||||||
|
|
||||||
|
views.loginWelcomeBackWarning.isVisible = ((state.loginProfileInfo as? Fail)
|
||||||
|
?.error as? Failure.ServerError)
|
||||||
|
?.httpCode == HttpsURLConnection.HTTP_NOT_FOUND /* 404 */
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupSubmitButton() {
|
private fun setupSubmitButton() {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import android.net.Uri
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
|
import com.airbnb.mvrx.Loading
|
||||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
|
@ -30,6 +31,7 @@ import im.vector.app.R
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.extensions.configureAndStart
|
import im.vector.app.core.extensions.configureAndStart
|
||||||
import im.vector.app.core.extensions.exhaustive
|
import im.vector.app.core.extensions.exhaustive
|
||||||
|
import im.vector.app.core.extensions.tryAsync
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.core.utils.ensureTrailingSlash
|
import im.vector.app.core.utils.ensureTrailingSlash
|
||||||
|
@ -665,17 +667,11 @@ class LoginViewModel2 @AssistedInject constructor(
|
||||||
val safeLoginWizard = loginWizard
|
val safeLoginWizard = loginWizard
|
||||||
|
|
||||||
if (safeLoginWizard != null) {
|
if (safeLoginWizard != null) {
|
||||||
try {
|
setState { copy(loginProfileInfo = Loading()) }
|
||||||
val info = safeLoginWizard.getProfileInfo(username)
|
val result = tryAsync {
|
||||||
setState {
|
safeLoginWizard.getProfileInfo(username)
|
||||||
copy(
|
|
||||||
loginProfileInfo = info
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} catch (failure: Throwable) {
|
|
||||||
// Ignore error
|
|
||||||
// TODO 404 may indicates that the user does not exist, so there is a mistake in the id
|
|
||||||
}
|
}
|
||||||
|
setState { copy(loginProfileInfo = result) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,10 @@
|
||||||
|
|
||||||
package im.vector.app.features.login2
|
package im.vector.app.features.login2
|
||||||
|
|
||||||
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.MvRxState
|
import com.airbnb.mvrx.MvRxState
|
||||||
import com.airbnb.mvrx.PersistState
|
import com.airbnb.mvrx.PersistState
|
||||||
|
import com.airbnb.mvrx.Uninitialized
|
||||||
import im.vector.app.core.extensions.toReducedUrl
|
import im.vector.app.core.extensions.toReducedUrl
|
||||||
import im.vector.app.features.login.LoginMode
|
import im.vector.app.features.login.LoginMode
|
||||||
import org.matrix.android.sdk.api.MatrixPatterns
|
import org.matrix.android.sdk.api.MatrixPatterns
|
||||||
|
@ -45,7 +47,7 @@ data class LoginViewState2(
|
||||||
val deviceId: String? = null,
|
val deviceId: String? = null,
|
||||||
|
|
||||||
// Network result
|
// Network result
|
||||||
val loginProfileInfo: LoginProfileInfo? = null,
|
val loginProfileInfo: Async<LoginProfileInfo> = Uninitialized,
|
||||||
|
|
||||||
// True on Matrix.org
|
// True on Matrix.org
|
||||||
val isNumericOnlyUserIdForbidden: Boolean = false,
|
val isNumericOnlyUserIdForbidden: Boolean = false,
|
||||||
|
|
|
@ -31,6 +31,17 @@
|
||||||
android:textAppearance="@style/TextAppearance.Vector.Login.Text"
|
android:textAppearance="@style/TextAppearance.Vector.Login.Text"
|
||||||
tools:text="Welcome back user!" />
|
tools:text="Welcome back user!" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/loginWelcomeBackWarning"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/layout_vertical_margin"
|
||||||
|
android:text="@string/login_unknown_user_warning"
|
||||||
|
android:textAppearance="@style/TextAppearance.Vector.Login.Text"
|
||||||
|
android:textColor="@color/vector_warning_color_2"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<!-- Error colors -->
|
<!-- Error colors -->
|
||||||
<color name="vector_success_color">#70BF56</color>
|
<color name="vector_success_color">#70BF56</color>
|
||||||
<color name="vector_warning_color">#ff4b55</color>
|
<color name="vector_warning_color">#ff4b55</color>
|
||||||
|
<color name="vector_warning_color_2">#ff812d</color>
|
||||||
<color name="vector_error_color">#ff4b55</color>
|
<color name="vector_error_color">#ff4b55</color>
|
||||||
<color name="vector_info_color">#2f9edb</color>
|
<color name="vector_info_color">#2f9edb</color>
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
<string name="login_create_a_new_account">Create a new account</string>
|
<string name="login_create_a_new_account">Create a new account</string>
|
||||||
<string name="login_i_already_have_an_account">I already have an account</string>
|
<string name="login_i_already_have_an_account">I already have an account</string>
|
||||||
|
|
||||||
|
<string name="login_unknown_user_warning">Warning: no profile information can be retrieved with this Matrix identifier. Please check that there is no mistake.</string>
|
||||||
|
|
||||||
<string name="login_wait_for_email_notice_2">We just sent an email to %1$s.</string>
|
<string name="login_wait_for_email_notice_2">We just sent an email to %1$s.</string>
|
||||||
<string name="login_wait_for_email_help">Click on the link it contains to continue the account creation.</string>
|
<string name="login_wait_for_email_help">Click on the link it contains to continue the account creation.</string>
|
||||||
<string name="login_account_created_title">Congratulations!</string>
|
<string name="login_account_created_title">Congratulations!</string>
|
||||||
|
|
Loading…
Reference in New Issue