Adds private setting usage to FtueAuthVariant

This commit is contained in:
ericdecanini 2022-02-24 15:28:33 +01:00
parent 981393fefb
commit 92c6d59984
4 changed files with 19 additions and 6 deletions

View File

@ -46,6 +46,7 @@ import im.vector.app.features.login.LoginMode
import im.vector.app.features.login.ReAuthHelper
import im.vector.app.features.login.ServerType
import im.vector.app.features.login.SignMode
import im.vector.app.features.settings.VectorDataStore
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
@ -78,7 +79,8 @@ class OnboardingViewModel @AssistedInject constructor(
private val stringProvider: StringProvider,
private val homeServerHistoryService: HomeServerHistoryService,
private val vectorFeatures: VectorFeatures,
private val analyticsTracker: AnalyticsTracker
private val analyticsTracker: AnalyticsTracker,
private val vectorDataStore: VectorDataStore,
) : VectorViewModel<OnboardingViewState, OnboardingAction, OnboardingViewEvents>(initialState) {
@AssistedFactory
@ -90,6 +92,7 @@ class OnboardingViewModel @AssistedInject constructor(
init {
getKnownCustomHomeServersUrls()
observeDataStore()
}
private fun getKnownCustomHomeServersUrls() {
@ -98,6 +101,12 @@ class OnboardingViewModel @AssistedInject constructor(
}
}
private fun observeDataStore() = viewModelScope.launch {
vectorDataStore.forceLoginFallbackFlow.setOnEach { isForceLoginFallbackEnabled ->
copy(isForceLoginFallbackEnabled = isForceLoginFallbackEnabled)
}
}
// Store the last action, to redo it after user has trusted the untrusted certificate
private var lastAction: OnboardingAction? = null
private var currentHomeServerConnectionConfig: HomeServerConnectionConfig? = null

View File

@ -62,7 +62,8 @@ data class OnboardingViewState(
// Supported types for the login. We cannot use a sealed class for LoginType because it is not serializable
@PersistState
val loginModeSupportedTypes: List<String> = emptyList(),
val knownCustomHomeServersUrls: List<String> = emptyList()
val knownCustomHomeServersUrls: List<String> = emptyList(),
val isForceLoginFallbackEnabled: Boolean = false,
) : MavericksState {
fun isLoading(): Boolean {

View File

@ -76,6 +76,8 @@ class FtueAuthVariant(
private val popEnterAnim = R.anim.no_anim
private val popExitAnim = R.anim.exit_fade_out
private var isForceLoginFallbackEnabled = false
private val topFragment: Fragment?
get() = supportFragmentManager.findFragmentById(views.loginFragmentContainer.id)
@ -225,7 +227,7 @@ class FtueAuthVariant(
}
private fun registrationShouldFallback(registrationFlowResult: OnboardingViewEvents.RegistrationFlowResult) =
vectorFeatures.isForceLoginFallbackEnabled() || registrationFlowResult.containsUnsupportedRegistrationFlow()
isForceLoginFallbackEnabled || registrationFlowResult.containsUnsupportedRegistrationFlow()
private fun OnboardingViewEvents.RegistrationFlowResult.containsUnsupportedRegistrationFlow() =
flowResult.missingStages.any { !it.isSupported() }
@ -244,6 +246,8 @@ class FtueAuthVariant(
}
private fun updateWithState(viewState: OnboardingViewState) {
isForceLoginFallbackEnabled = viewState.isForceLoginFallbackEnabled
views.loginLoading.isVisible = if (vectorFeatures.isOnboardingPersonalizeEnabled()) {
viewState.isLoading()
} else {
@ -286,7 +290,7 @@ class FtueAuthVariant(
}
private fun handleSignInSelected(state: OnboardingViewState) {
if (vectorFeatures.isForceLoginFallbackEnabled()) {
if (isForceLoginFallbackEnabled) {
onLoginModeNotSupported(state.loginModeSupportedTypes)
} else {
disambiguateLoginMode(state)
@ -318,7 +322,7 @@ class FtueAuthVariant(
}
private fun handleSignInWithMatrixId(state: OnboardingViewState) {
if (vectorFeatures.isForceLoginFallbackEnabled()) {
if (isForceLoginFallbackEnabled) {
onLoginModeNotSupported(state.loginModeSupportedTypes)
} else {
openAuthLoginFragmentWithTag(FRAGMENT_LOGIN_TAG)

View File

@ -60,7 +60,6 @@ class VectorDataStore @Inject constructor(
}
}
private val forceLoginFallback = booleanPreferencesKey("force_login_fallback")
val forceLoginFallbackFlow: Flow<Boolean> = context.dataStore.data.map { preferences ->