mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 01:45:52 +03:00
dynamically changing the account created layout based on if the homeserver supports personalisation
This commit is contained in:
parent
3df4f1e099
commit
537c2f56a1
5 changed files with 80 additions and 23 deletions
|
@ -48,6 +48,7 @@ import im.vector.app.features.login.ReAuthHelper
|
|||
import im.vector.app.features.login.ServerType
|
||||
import im.vector.app.features.login.SignMode
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.auth.AuthenticationService
|
||||
|
@ -80,6 +81,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
private val stringProvider: StringProvider,
|
||||
private val homeServerHistoryService: HomeServerHistoryService,
|
||||
private val vectorFeatures: VectorFeatures,
|
||||
private val vectorOverrides: VectorOverrides,
|
||||
private val analyticsTracker: AnalyticsTracker,
|
||||
private val uriFilenameResolver: UriFilenameResolver,
|
||||
private val vectorOverrides: VectorOverrides
|
||||
|
@ -762,15 +764,24 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
|
||||
authenticationService.reset()
|
||||
session.configureAndStart(applicationContext)
|
||||
setState {
|
||||
copy(
|
||||
asyncLoginAction = Success(Unit)
|
||||
)
|
||||
}
|
||||
|
||||
when (isAccountCreated) {
|
||||
true -> _viewEvents.post(OnboardingViewEvents.OnAccountCreated)
|
||||
false -> _viewEvents.post(OnboardingViewEvents.OnAccountSignedIn)
|
||||
true -> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,11 @@ enum class OnboardingFlow {
|
|||
|
||||
@Parcelize
|
||||
data class PersonalizationState(
|
||||
val supportsChangingDisplayName: Boolean = false,
|
||||
val supportsChangingProfilePicture: Boolean = false,
|
||||
val displayName: String? = null,
|
||||
val selectedPictureUri: Uri? = null
|
||||
) : Parcelable
|
||||
) : Parcelable {
|
||||
|
||||
fun supportsPersonalization() = supportsChangingDisplayName || supportsChangingProfilePicture
|
||||
}
|
||||
|
|
|
@ -20,11 +20,13 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import im.vector.app.databinding.FragmentFtueAccountCreatedBinding
|
||||
import im.vector.app.features.onboarding.OnboardingAction
|
||||
import im.vector.app.features.onboarding.OnboardingViewEvents
|
||||
import im.vector.app.features.onboarding.OnboardingViewState
|
||||
import javax.inject.Inject
|
||||
|
||||
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.accountCreatedPersonalize.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnPersonalizeProfile)) }
|
||||
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() {
|
||||
|
|
|
@ -230,7 +230,7 @@ class FtueAuthVariant(
|
|||
FtueAuthUseCaseFragment::class.java,
|
||||
option = commonOption)
|
||||
}
|
||||
OnboardingViewEvents.OnAccountCreated -> onAccountCreated()
|
||||
is OnboardingViewEvents.OnAccountCreated -> onAccountCreated()
|
||||
OnboardingViewEvents.OnAccountSignedIn -> onAccountSignedIn()
|
||||
OnboardingViewEvents.OnPersonalizeProfile -> onPersonalizeProfile()
|
||||
OnboardingViewEvents.OnTakeMeHome -> navigateToHome(createdAccount = true)
|
||||
|
@ -399,15 +399,11 @@ class FtueAuthVariant(
|
|||
}
|
||||
|
||||
private fun onAccountCreated() {
|
||||
if (vectorFeatures.isOnboardingPersonalizeEnabled()) {
|
||||
activity.supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
|
||||
activity.replaceFragment(
|
||||
views.loginFragmentContainer,
|
||||
FtueAuthAccountCreatedFragment::class.java,
|
||||
)
|
||||
} else {
|
||||
navigateToHome(createdAccount = true)
|
||||
}
|
||||
activity.supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
|
||||
activity.replaceFragment(
|
||||
views.loginFragmentContainer,
|
||||
FtueAuthAccountCreatedFragment::class.java
|
||||
)
|
||||
}
|
||||
|
||||
private fun navigateToHome(createdAccount: Boolean) {
|
||||
|
|
|
@ -86,6 +86,14 @@
|
|||
app:layout_constraintBottom_toTopOf="@id/accountCreatedPersonalize"
|
||||
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
|
||||
android:id="@+id/accountCreatedPersonalize"
|
||||
style="@style/Widget.Vector.Button.Login"
|
||||
|
@ -96,11 +104,10 @@
|
|||
android:textAllCaps="true"
|
||||
android:textColor="?colorSecondary"
|
||||
android:transitionName="loginSubmitTransition"
|
||||
app:layout_constraintBottom_toTopOf="@id/accountCreatedSpace5"
|
||||
app:layout_constraintBottom_toTopOf="@id/accountCreatedTakeMeHome"
|
||||
app:layout_constraintEnd_toEndOf="@id/ftueAuthGutterEnd"
|
||||
app:layout_constraintStart_toStartOf="@id/ftueAuthGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/accountCreatedSpace4"
|
||||
tools:text="@string/ftue_account_created_personalize" />
|
||||
app:layout_constraintTop_toBottomOf="@id/accountCreatedSpace4" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/accountCreatedTakeMeHome"
|
||||
|
@ -111,17 +118,46 @@
|
|||
android:textAllCaps="true"
|
||||
android:textColor="@color/element_background_light"
|
||||
android:transitionName="loginSubmitTransition"
|
||||
app:layout_constraintBottom_toTopOf="@id/accountCreatedSpace5"
|
||||
app:layout_constraintBottom_toTopOf="@id/ctaBottomBarrier"
|
||||
app:layout_constraintEnd_toEndOf="@id/ftueAuthGutterEnd"
|
||||
app:layout_constraintStart_toStartOf="@id/ftueAuthGutterStart"
|
||||
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
|
||||
android:id="@+id/accountCreatedSpace5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintHeight_percent="0.05"
|
||||
app:layout_constraintTop_toBottomOf="@id/accountCreatedPersonalize" />
|
||||
app:layout_constraintTop_toBottomOf="@id/ctaBottomBarrier" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
Loading…
Reference in a new issue