dynamically changing the account created layout based on if the homeserver supports personalisation

This commit is contained in:
Adam Brown 2022-02-24 17:37:19 +00:00
parent 3df4f1e099
commit 537c2f56a1
5 changed files with 80 additions and 23 deletions

View file

@ -48,6 +48,7 @@ import im.vector.app.features.login.ReAuthHelper
import im.vector.app.features.login.ServerType import im.vector.app.features.login.ServerType
import im.vector.app.features.login.SignMode import im.vector.app.features.login.SignMode
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.MatrixPatterns.getDomain import org.matrix.android.sdk.api.MatrixPatterns.getDomain
import org.matrix.android.sdk.api.auth.AuthenticationService import org.matrix.android.sdk.api.auth.AuthenticationService
@ -80,6 +81,7 @@ class OnboardingViewModel @AssistedInject constructor(
private val stringProvider: StringProvider, private val stringProvider: StringProvider,
private val homeServerHistoryService: HomeServerHistoryService, private val homeServerHistoryService: HomeServerHistoryService,
private val vectorFeatures: VectorFeatures, private val vectorFeatures: VectorFeatures,
private val vectorOverrides: VectorOverrides,
private val analyticsTracker: AnalyticsTracker, private val analyticsTracker: AnalyticsTracker,
private val uriFilenameResolver: UriFilenameResolver, private val uriFilenameResolver: UriFilenameResolver,
private val vectorOverrides: VectorOverrides private val vectorOverrides: VectorOverrides
@ -762,15 +764,24 @@ class OnboardingViewModel @AssistedInject constructor(
authenticationService.reset() authenticationService.reset()
session.configureAndStart(applicationContext) session.configureAndStart(applicationContext)
setState {
copy(
asyncLoginAction = Success(Unit)
)
}
when (isAccountCreated) { when (isAccountCreated) {
true -> _viewEvents.post(OnboardingViewEvents.OnAccountCreated) true -> {
false -> _viewEvents.post(OnboardingViewEvents.OnAccountSignedIn) val homeServerCapabilities = session.getHomeServerCapabilities()
val capabilityOverrides = vectorOverrides.forceHomeserverCapabilities()?.firstOrNull()
val personalizationState = state.personalizationState.copy(
supportsChangingDisplayName = capabilityOverrides?.canChangeDisplayName ?: homeServerCapabilities.canChangeDisplayName,
supportsChangingProfilePicture = capabilityOverrides?.canChangeAvatar ?: homeServerCapabilities.canChangeAvatar
)
setState {
copy(asyncLoginAction = Success(Unit), personalizationState = personalizationState)
}
_viewEvents.post(OnboardingViewEvents.OnAccountCreated)
}
false -> {
setState { copy(asyncLoginAction = Success(Unit)) }
_viewEvents.post(OnboardingViewEvents.OnAccountSignedIn)
}
} }
} }

View file

@ -97,6 +97,11 @@ enum class OnboardingFlow {
@Parcelize @Parcelize
data class PersonalizationState( data class PersonalizationState(
val supportsChangingDisplayName: Boolean = false,
val supportsChangingProfilePicture: Boolean = false,
val displayName: String? = null, val displayName: String? = null,
val selectedPictureUri: Uri? = null val selectedPictureUri: Uri? = null
) : Parcelable ) : Parcelable {
fun supportsPersonalization() = supportsChangingDisplayName || supportsChangingProfilePicture
}

View file

@ -20,11 +20,13 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.isVisible
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.databinding.FragmentFtueAccountCreatedBinding import im.vector.app.databinding.FragmentFtueAccountCreatedBinding
import im.vector.app.features.onboarding.OnboardingAction import im.vector.app.features.onboarding.OnboardingAction
import im.vector.app.features.onboarding.OnboardingViewEvents import im.vector.app.features.onboarding.OnboardingViewEvents
import im.vector.app.features.onboarding.OnboardingViewState
import javax.inject.Inject import javax.inject.Inject
class FtueAuthAccountCreatedFragment @Inject constructor( class FtueAuthAccountCreatedFragment @Inject constructor(
@ -44,6 +46,13 @@ class FtueAuthAccountCreatedFragment @Inject constructor(
views.accountCreatedSubtitle.text = getString(R.string.ftue_account_created_subtitle, activeSessionHolder.getActiveSession().myUserId) views.accountCreatedSubtitle.text = getString(R.string.ftue_account_created_subtitle, activeSessionHolder.getActiveSession().myUserId)
views.accountCreatedPersonalize.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnPersonalizeProfile)) } views.accountCreatedPersonalize.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnPersonalizeProfile)) }
views.accountCreatedTakeMeHome.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnTakeMeHome)) } views.accountCreatedTakeMeHome.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnTakeMeHome)) }
views.accountCreatedTakeMeHomeCta.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnTakeMeHome)) }
}
override fun updateWithState(state: OnboardingViewState) {
val canPersonalize = state.personalizationState.supportsPersonalization()
views.personalizeButtonGroup.isVisible = canPersonalize
views.takeMeHomeButtonGroup.isVisible = !canPersonalize
} }
override fun resetViewModel() { override fun resetViewModel() {

View file

@ -230,7 +230,7 @@ class FtueAuthVariant(
FtueAuthUseCaseFragment::class.java, FtueAuthUseCaseFragment::class.java,
option = commonOption) option = commonOption)
} }
OnboardingViewEvents.OnAccountCreated -> onAccountCreated() is OnboardingViewEvents.OnAccountCreated -> onAccountCreated()
OnboardingViewEvents.OnAccountSignedIn -> onAccountSignedIn() OnboardingViewEvents.OnAccountSignedIn -> onAccountSignedIn()
OnboardingViewEvents.OnPersonalizeProfile -> onPersonalizeProfile() OnboardingViewEvents.OnPersonalizeProfile -> onPersonalizeProfile()
OnboardingViewEvents.OnTakeMeHome -> navigateToHome(createdAccount = true) OnboardingViewEvents.OnTakeMeHome -> navigateToHome(createdAccount = true)
@ -399,15 +399,11 @@ class FtueAuthVariant(
} }
private fun onAccountCreated() { private fun onAccountCreated() {
if (vectorFeatures.isOnboardingPersonalizeEnabled()) {
activity.supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) activity.supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
activity.replaceFragment( activity.replaceFragment(
views.loginFragmentContainer, views.loginFragmentContainer,
FtueAuthAccountCreatedFragment::class.java, FtueAuthAccountCreatedFragment::class.java
) )
} else {
navigateToHome(createdAccount = true)
}
} }
private fun navigateToHome(createdAccount: Boolean) { private fun navigateToHome(createdAccount: Boolean) {

View file

@ -86,6 +86,14 @@
app:layout_constraintBottom_toTopOf="@id/accountCreatedPersonalize" app:layout_constraintBottom_toTopOf="@id/accountCreatedPersonalize"
app:layout_constraintTop_toBottomOf="@id/accountCreatedSubtitle" /> app:layout_constraintTop_toBottomOf="@id/accountCreatedSubtitle" />
<androidx.constraintlayout.widget.Group
android:id="@+id/personalizeButtonGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="accountCreatedPersonalize,accountCreatedTakeMeHome"
tools:visibility="visible" />
<Button <Button
android:id="@+id/accountCreatedPersonalize" android:id="@+id/accountCreatedPersonalize"
style="@style/Widget.Vector.Button.Login" style="@style/Widget.Vector.Button.Login"
@ -96,11 +104,10 @@
android:textAllCaps="true" android:textAllCaps="true"
android:textColor="?colorSecondary" android:textColor="?colorSecondary"
android:transitionName="loginSubmitTransition" android:transitionName="loginSubmitTransition"
app:layout_constraintBottom_toTopOf="@id/accountCreatedSpace5" app:layout_constraintBottom_toTopOf="@id/accountCreatedTakeMeHome"
app:layout_constraintEnd_toEndOf="@id/ftueAuthGutterEnd" app:layout_constraintEnd_toEndOf="@id/ftueAuthGutterEnd"
app:layout_constraintStart_toStartOf="@id/ftueAuthGutterStart" app:layout_constraintStart_toStartOf="@id/ftueAuthGutterStart"
app:layout_constraintTop_toBottomOf="@id/accountCreatedSpace4" app:layout_constraintTop_toBottomOf="@id/accountCreatedSpace4" />
tools:text="@string/ftue_account_created_personalize" />
<Button <Button
android:id="@+id/accountCreatedTakeMeHome" android:id="@+id/accountCreatedTakeMeHome"
@ -111,17 +118,46 @@
android:textAllCaps="true" android:textAllCaps="true"
android:textColor="@color/element_background_light" android:textColor="@color/element_background_light"
android:transitionName="loginSubmitTransition" android:transitionName="loginSubmitTransition"
app:layout_constraintBottom_toTopOf="@id/accountCreatedSpace5" app:layout_constraintBottom_toTopOf="@id/ctaBottomBarrier"
app:layout_constraintEnd_toEndOf="@id/ftueAuthGutterEnd" app:layout_constraintEnd_toEndOf="@id/ftueAuthGutterEnd"
app:layout_constraintStart_toStartOf="@id/ftueAuthGutterStart" app:layout_constraintStart_toStartOf="@id/ftueAuthGutterStart"
app:layout_constraintTop_toBottomOf="@id/accountCreatedPersonalize" /> app:layout_constraintTop_toBottomOf="@id/accountCreatedPersonalize" />
<androidx.constraintlayout.widget.Group
android:id="@+id/takeMeHomeButtonGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="accountCreatedTakeMeHomeCta" />
<Button
android:id="@+id/accountCreatedTakeMeHomeCta"
style="@style/Widget.Vector.Button.Login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:backgroundTint="@color/element_background_light"
android:text="@string/ftue_account_created_take_me_home"
android:textAllCaps="true"
android:textColor="?colorSecondary"
android:transitionName="loginSubmitTransition"
app:layout_constraintBottom_toTopOf="@id/ctaBottomBarrier"
app:layout_constraintEnd_toEndOf="@id/ftueAuthGutterEnd"
app:layout_constraintStart_toStartOf="@id/ftueAuthGutterStart"
app:layout_constraintTop_toBottomOf="@id/accountCreatedSpace4" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/ctaBottomBarrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="accountCreatedTakeMeHomeCta,accountCreatedTakeMeHome" />
<Space <Space
android:id="@+id/accountCreatedSpace5" android:id="@+id/accountCreatedSpace5"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_percent="0.05" app:layout_constraintHeight_percent="0.05"
app:layout_constraintTop_toBottomOf="@id/accountCreatedPersonalize" /> app:layout_constraintTop_toBottomOf="@id/ctaBottomBarrier" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>