cloning the splash fragment into the onboarding

This commit is contained in:
Adam Brown 2021-12-08 17:07:57 +00:00
parent 8de892bc60
commit 7b3163e140
5 changed files with 244 additions and 41 deletions

View file

@ -18,6 +18,7 @@ package im.vector.app.features.onboarding
import im.vector.app.features.VectorFeatures
import im.vector.app.features.login2.LoginViewModel2
import im.vector.app.features.onboarding.ftueauth.FtueAuthVariant
import javax.inject.Inject
class OnboardingVariantFactory @Inject constructor(
@ -29,7 +30,7 @@ class OnboardingVariantFactory @Inject constructor(
loginViewModel2: Lazy<LoginViewModel2>
) = when (vectorFeatures.onboardingVariant()) {
VectorFeatures.OnboardingVariant.LEGACY -> error("Legacy is not supported by the FTUE")
VectorFeatures.OnboardingVariant.FTUE_AUTH -> OnboardingAuthVariant(
VectorFeatures.OnboardingVariant.FTUE_AUTH -> FtueAuthVariant(
views = activity.getBinding(),
onboardingViewModel = onboardingViewModel.value,
activity = activity,

View file

@ -63,11 +63,11 @@ abstract class AbstractFtueAuthFragment<VB : ViewBinding> : VectorBaseFragment<V
super.onViewCreated(view, savedInstanceState)
viewModel.observeViewEvents {
handleOnboardingViewEvents(it)
handleLoginViewEvents(it)
}
}
private fun handleOnboardingViewEvents(viewEvents: OnboardingViewEvents) {
private fun handleLoginViewEvents(viewEvents: OnboardingViewEvents) {
when (viewEvents) {
is OnboardingViewEvents.Failure -> showFailure(viewEvents.throwable)
else ->
@ -178,6 +178,6 @@ abstract class AbstractFtueAuthFragment<VB : ViewBinding> : VectorBaseFragment<V
// No op by default
}
// Reset any modification on the viewModel by the current fragment
// Reset any modification on the loginViewModel by the current fragment
abstract fun resetViewModel()
}

View file

@ -26,8 +26,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.databinding.FragmentLoginSplashBinding
import im.vector.app.features.login.AbstractLoginFragment
import im.vector.app.features.login.LoginAction
import im.vector.app.features.onboarding.OnboardingAction
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.failure.Failure
import java.net.UnknownHostException
@ -38,7 +37,7 @@ import javax.inject.Inject
*/
class FtueAuthSplashFragment @Inject constructor(
private val vectorPreferences: VectorPreferences
) : AbstractLoginFragment<FragmentLoginSplashBinding>() {
) : AbstractFtueAuthFragment<FragmentLoginSplashBinding>() {
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLoginSplashBinding {
return FragmentLoginSplashBinding.inflate(inflater, container, false)
@ -63,7 +62,7 @@ class FtueAuthSplashFragment @Inject constructor(
}
private fun getStarted() {
loginViewModel.handle(LoginAction.OnGetStarted(resetLoginConfig = false))
viewModel.handle(OnboardingAction.OnGetStarted(resetLoginConfig = false))
}
override fun resetViewModel() {
@ -74,12 +73,12 @@ class FtueAuthSplashFragment @Inject constructor(
if (throwable is Failure.NetworkConnection &&
throwable.ioException is UnknownHostException) {
// Invalid homeserver from URL config
val url = loginViewModel.getInitialHomeServerUrl().orEmpty()
val url = viewModel.getInitialHomeServerUrl().orEmpty()
MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.dialog_title_error)
.setMessage(getString(R.string.login_error_homeserver_from_url_not_found, url))
.setPositiveButton(R.string.login_error_homeserver_from_url_not_found_enter_manual) { _, _ ->
loginViewModel.handle(LoginAction.OnGetStarted(resetLoginConfig = true))
viewModel.handle(OnboardingAction.OnGetStarted(resetLoginConfig = true))
}
.setNegativeButton(R.string.action_cancel, null)
.show()

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package im.vector.app.features.onboarding
package im.vector.app.features.onboarding.ftueauth
import android.content.Intent
import android.view.View
@ -42,21 +42,12 @@ import im.vector.app.features.login.SignMode
import im.vector.app.features.login.TextInputFormFragmentMode
import im.vector.app.features.login.isSupported
import im.vector.app.features.login.terms.toLocalizedLoginTerms
import im.vector.app.features.onboarding.ftueauth.FtueAuthCaptchaFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthCaptchaFragmentArgument
import im.vector.app.features.onboarding.ftueauth.FtueAuthGenericTextInputFormFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthGenericTextInputFormFragmentArgument
import im.vector.app.features.onboarding.ftueauth.FtueAuthLoginFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthResetPasswordFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthResetPasswordMailConfirmationFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthResetPasswordSuccessFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthServerSelectionFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthServerUrlFormFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthSignUpSignInSelectionFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthSplashFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthWaitForEmailFragment
import im.vector.app.features.onboarding.ftueauth.FtueAuthWaitForEmailFragmentArgument
import im.vector.app.features.onboarding.ftueauth.FtueAuthWebFragment
import im.vector.app.features.onboarding.OnboardingAction
import im.vector.app.features.onboarding.OnboardingActivity
import im.vector.app.features.onboarding.OnboardingVariant
import im.vector.app.features.onboarding.OnboardingViewEvents
import im.vector.app.features.onboarding.OnboardingViewModel
import im.vector.app.features.onboarding.OnboardingViewState
import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsFragment
import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsFragmentArgument
import org.matrix.android.sdk.api.auth.registration.FlowResult
@ -66,7 +57,7 @@ import org.matrix.android.sdk.api.extensions.tryOrNull
private const val FRAGMENT_REGISTRATION_STAGE_TAG = "FRAGMENT_REGISTRATION_STAGE_TAG"
private const val FRAGMENT_LOGIN_TAG = "FRAGMENT_LOGIN_TAG"
class OnboardingAuthVariant(
class FtueAuthVariant(
private val views: ActivityLoginBinding,
private val onboardingViewModel: OnboardingViewModel,
private val activity: VectorBaseActivity<ActivityLoginBinding>,
@ -120,17 +111,17 @@ class OnboardingAuthVariant(
activity.addFragment(views.loginFragmentContainer, FtueAuthSplashFragment::class.java)
}
private fun handleOnboardingViewEvents(onboardingViewEvents: OnboardingViewEvents) {
when (onboardingViewEvents) {
private fun handleOnboardingViewEvents(viewEvents: OnboardingViewEvents) {
when (viewEvents) {
is OnboardingViewEvents.RegistrationFlowResult -> {
// Check that all flows are supported by the application
if (onboardingViewEvents.flowResult.missingStages.any { !it.isSupported() }) {
if (viewEvents.flowResult.missingStages.any { !it.isSupported() }) {
// Display a popup to propose use web fallback
onRegistrationStageNotSupported()
} else {
if (onboardingViewEvents.isRegistrationStarted) {
if (viewEvents.isRegistrationStarted) {
// Go on with registration flow
handleRegistrationNavigation(onboardingViewEvents.flowResult)
handleRegistrationNavigation(viewEvents.flowResult)
} else {
// First ask for login and password
// I add a tag to indicate that this fragment is a registration stage.
@ -163,13 +154,13 @@ class OnboardingAuthVariant(
// TODO Disabled because it provokes a flickering
// ft.setCustomAnimations(enterAnim, exitAnim, popEnterAnim, popExitAnim)
})
is OnboardingViewEvents.OnServerSelectionDone -> onServerSelectionDone(onboardingViewEvents)
is OnboardingViewEvents.OnSignModeSelected -> onSignModeSelected(onboardingViewEvents)
is OnboardingViewEvents.OnServerSelectionDone -> onServerSelectionDone(viewEvents)
is OnboardingViewEvents.OnSignModeSelected -> onSignModeSelected(viewEvents)
is OnboardingViewEvents.OnLoginFlowRetrieved ->
activity.addFragmentToBackstack(views.loginFragmentContainer,
FtueAuthSignUpSignInSelectionFragment::class.java,
option = commonOption)
is OnboardingViewEvents.OnWebLoginError -> onWebLoginError(onboardingViewEvents)
is OnboardingViewEvents.OnWebLoginError -> onWebLoginError(viewEvents)
is OnboardingViewEvents.OnForgetPasswordClicked ->
activity.addFragmentToBackstack(views.loginFragmentContainer,
FtueAuthResetPasswordFragment::class.java,
@ -195,7 +186,7 @@ class OnboardingAuthVariant(
supportFragmentManager.popBackStack(FRAGMENT_REGISTRATION_STAGE_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE)
activity.addFragmentToBackstack(views.loginFragmentContainer,
FtueAuthWaitForEmailFragment::class.java,
FtueAuthWaitForEmailFragmentArgument(onboardingViewEvents.email),
FtueAuthWaitForEmailFragmentArgument(viewEvents.email),
tag = FRAGMENT_REGISTRATION_STAGE_TAG,
option = commonOption)
}
@ -204,7 +195,7 @@ class OnboardingAuthVariant(
supportFragmentManager.popBackStack(FRAGMENT_REGISTRATION_STAGE_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE)
activity.addFragmentToBackstack(views.loginFragmentContainer,
FtueAuthGenericTextInputFormFragment::class.java,
FtueAuthGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.ConfirmMsisdn, true, onboardingViewEvents.msisdn),
FtueAuthGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.ConfirmMsisdn, true, viewEvents.msisdn),
tag = FRAGMENT_REGISTRATION_STAGE_TAG,
option = commonOption)
}
@ -215,11 +206,11 @@ class OnboardingAuthVariant(
}.exhaustive
}
private fun updateWithState(onboardingViewState: OnboardingViewState) {
if (onboardingViewState.isUserLogged()) {
private fun updateWithState(viewState: OnboardingViewState) {
if (viewState.isUserLogged()) {
val intent = HomeActivity.newIntent(
activity,
accountCreation = onboardingViewState.signMode == SignMode.SignUp
accountCreation = viewState.signMode == SignMode.SignUp
)
activity.startActivity(intent)
activity.finish()
@ -227,7 +218,7 @@ class OnboardingAuthVariant(
}
// Loading
views.loginLoading.isVisible = onboardingViewState.isLoading()
views.loginLoading.isVisible = viewState.isLoading()
}
private fun onWebLoginError(onWebLoginError: OnboardingViewEvents.OnWebLoginError) {

View file

@ -0,0 +1,212 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground"
android:paddingStart="36dp"
android:paddingTop="@dimen/layout_vertical_margin"
android:paddingEnd="36dp"
android:paddingBottom="@dimen/layout_vertical_margin">
<!-- Strategy: 5 Spaces are used to spread the remaining space, using weight -->
<Space
android:id="@+id/loginSplashSpace1"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/loginSplashLogoContainer"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside"
app:layout_constraintVertical_weight="4" />
<LinearLayout
android:id="@+id/loginSplashLogoContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@id/loginSplashSpace2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/loginSplashSpace1">
<ImageView
android:id="@+id/loginSplashLogo"
android:layout_width="64dp"
android:layout_height="64dp"
android:importantForAccessibility="no"
android:src="@drawable/element_logo_green"
android:transitionName="loginLogoTransition" />
<ImageView
android:id="@+id/logoType"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_marginTop="8dp"
android:contentDescription="@string/app_name"
android:src="@drawable/element_logotype"
app:tint="?colorSecondary"
tools:ignore="MissingPrefix" />
</LinearLayout>
<Space
android:id="@+id/loginSplashSpace2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/loginSplashTitle"
app:layout_constraintTop_toBottomOf="@id/loginSplashLogoContainer"
app:layout_constraintVertical_weight="1" />
<TextView
android:id="@+id/loginSplashTitle"
style="@style/Widget.Vector.TextView.Title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/login_splash_title"
android:textColor="?vctr_content_primary"
android:transitionName="loginTitleTransition"
app:layout_constraintBottom_toTopOf="@id/loginSplashSpace3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/loginSplashSpace2" />
<Space
android:id="@+id/loginSplashSpace3"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/loginSplashContent"
app:layout_constraintTop_toBottomOf="@id/loginSplashTitle"
app:layout_constraintVertical_weight="2" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/loginSplashContent"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/loginSplashSpace4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/loginSplashSpace3">
<ImageView
android:id="@+id/loginSplashPicto1"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:importantForAccessibility="no"
android:src="@drawable/ic_login_splash_message_circle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/loginSplashText1"
app:tint="?vctr_content_secondary"
tools:ignore="MissingPrefix" />
<TextView
android:id="@+id/loginSplashText1"
style="@style/Widget.Vector.TextView.Body"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:gravity="start"
android:text="@string/login_splash_text1"
android:textColor="?vctr_content_secondary"
app:layout_constraintBottom_toTopOf="@id/loginSplashText2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/loginSplashPicto1"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/loginSplashPicto2"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:importantForAccessibility="no"
android:src="@drawable/ic_login_splash_lock"
app:layout_constraintStart_toStartOf="@id/loginSplashPicto1"
app:layout_constraintTop_toTopOf="@id/loginSplashText2"
app:tint="?vctr_content_secondary"
tools:ignore="MissingPrefix" />
<TextView
android:id="@+id/loginSplashText2"
style="@style/Widget.Vector.TextView.Body"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="start"
android:text="@string/login_splash_text2"
android:textColor="?vctr_content_secondary"
app:layout_constraintBottom_toTopOf="@id/loginSplashText3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/loginSplashText1"
app:layout_constraintTop_toBottomOf="@id/loginSplashText1" />
<ImageView
android:id="@+id/loginSplashPicto3"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:importantForAccessibility="no"
android:src="@drawable/ic_login_splash_sliders"
app:layout_constraintStart_toStartOf="@id/loginSplashPicto1"
app:layout_constraintTop_toTopOf="@id/loginSplashText3"
app:tint="?vctr_content_secondary"
tools:ignore="MissingPrefix" />
<TextView
android:id="@+id/loginSplashText3"
style="@style/Widget.Vector.TextView.Body"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="start"
android:text="@string/login_splash_text3"
android:textColor="?vctr_content_secondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/loginSplashText1"
app:layout_constraintTop_toBottomOf="@id/loginSplashText2" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Space
android:id="@+id/loginSplashSpace4"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/loginSplashSubmit"
app:layout_constraintTop_toBottomOf="@id/loginSplashContent"
app:layout_constraintVertical_weight="2" />
<Button
android:id="@+id/loginSplashSubmit"
style="@style/Widget.Vector.Button.Login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/login_splash_submit"
android:transitionName="loginSubmitTransition"
app:layout_constraintBottom_toTopOf="@id/loginSplashSpace5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/loginSplashSpace4" />
<Space
android:id="@+id/loginSplashSpace5"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/loginSplashSubmit"
app:layout_constraintVertical_weight="4" />
<TextView
android:id="@+id/loginSplashVersion"
style="@style/Widget.Vector.TextView.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?vctr_content_secondary"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="@string/settings_version"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>