mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-16 03:08:58 +03:00
storing the user usecase selection and clearinng on signout
This commit is contained in:
parent
38a6c3ea61
commit
84e23e1911
4 changed files with 82 additions and 10 deletions
|
@ -36,6 +36,7 @@ import im.vector.app.features.analytics.VectorAnalytics
|
|||
import im.vector.app.features.home.HomeActivity
|
||||
import im.vector.app.features.home.ShortcutsHandler
|
||||
import im.vector.app.features.notifications.NotificationDrawerManager
|
||||
import im.vector.app.features.onboarding.store.OnboardingStore
|
||||
import im.vector.app.features.pin.PinCodeStore
|
||||
import im.vector.app.features.pin.PinLocker
|
||||
import im.vector.app.features.pin.UnlockedActivity
|
||||
|
@ -98,6 +99,7 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
@Inject lateinit var pinLocker: PinLocker
|
||||
@Inject lateinit var popupAlertManager: PopupAlertManager
|
||||
@Inject lateinit var vectorAnalytics: VectorAnalytics
|
||||
@Inject lateinit var onboardingStore: OnboardingStore
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -193,6 +195,7 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
pinLocker.unlock()
|
||||
pinCodeStore.deleteEncodedPin()
|
||||
vectorAnalytics.onSignOut()
|
||||
onboardingStore.clear()
|
||||
}
|
||||
withContext(Dispatchers.IO) {
|
||||
// On BG thread
|
||||
|
|
|
@ -16,9 +16,13 @@
|
|||
|
||||
package im.vector.app.features.onboarding
|
||||
|
||||
enum class FtueUseCase {
|
||||
FRIENDS_FAMILY,
|
||||
TEAMS,
|
||||
COMMUNITIES,
|
||||
SKIP
|
||||
enum class FtueUseCase(val persistableValue: String) {
|
||||
FRIENDS_FAMILY("friends_family"),
|
||||
TEAMS("teams"),
|
||||
COMMUNITIES("communities"),
|
||||
SKIP("skip");
|
||||
|
||||
companion object {
|
||||
fun from(persistedValue: String) = values().first { it.persistableValue == persistedValue }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,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.onboarding.store.OnboardingStore
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
|
@ -73,7 +74,8 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
private val reAuthHelper: ReAuthHelper,
|
||||
private val stringProvider: StringProvider,
|
||||
private val homeServerHistoryService: HomeServerHistoryService,
|
||||
private val vectorFeatures: VectorFeatures
|
||||
private val vectorFeatures: VectorFeatures,
|
||||
private val onboardingStore: OnboardingStore
|
||||
) : VectorViewModel<OnboardingViewState, OnboardingAction, OnboardingViewEvents>(initialState) {
|
||||
|
||||
@AssistedFactory
|
||||
|
@ -125,7 +127,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
when (action) {
|
||||
is OnboardingAction.OnGetStarted -> handleSplashAction(action.resetLoginConfig, action.onboardingFlow)
|
||||
is OnboardingAction.OnIAlreadyHaveAnAccount -> handleSplashAction(action.resetLoginConfig, action.onboardingFlow)
|
||||
is OnboardingAction.UpdateUseCase -> handleUpdateUseCase()
|
||||
is OnboardingAction.UpdateUseCase -> handleUpdateUseCase(action)
|
||||
OnboardingAction.ResetUseCase -> resetUseCase()
|
||||
is OnboardingAction.UpdateServerType -> handleUpdateServerType(action)
|
||||
is OnboardingAction.UpdateSignMode -> handleUpdateSignMode(action)
|
||||
|
@ -458,13 +460,17 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleUpdateUseCase() {
|
||||
// TODO act on the use case selection
|
||||
private fun handleUpdateUseCase(action: OnboardingAction.UpdateUseCase) {
|
||||
viewModelScope.launch {
|
||||
onboardingStore.setUseCase(action.useCase)
|
||||
}
|
||||
_viewEvents.post(OnboardingViewEvents.OpenServerSelection)
|
||||
}
|
||||
|
||||
private fun resetUseCase() {
|
||||
// TODO remove stored use case
|
||||
viewModelScope.launch {
|
||||
onboardingStore.resetUseCase()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleUpdateServerType(action: OnboardingAction.UpdateServerType) {
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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.features.onboarding.store
|
||||
|
||||
import android.content.Context
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import im.vector.app.features.onboarding.FtueUseCase
|
||||
import kotlinx.coroutines.flow.first
|
||||
import javax.inject.Inject
|
||||
|
||||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "vector_onboarding")
|
||||
|
||||
/**
|
||||
* Local storage for:
|
||||
* - messaging use case (Enum/String)
|
||||
*/
|
||||
class OnboardingStore @Inject constructor(
|
||||
private val context: Context
|
||||
) {
|
||||
private val useCaseKey = stringPreferencesKey("use_case")
|
||||
|
||||
suspend fun readUseCase() = context.dataStore.data.first().let { preferences ->
|
||||
preferences[useCaseKey]?.let { FtueUseCase.from(it) }
|
||||
}
|
||||
|
||||
suspend fun setUseCase(useCase: FtueUseCase) {
|
||||
context.dataStore.edit { settings ->
|
||||
settings[useCaseKey] = useCase.persistableValue
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun resetUseCase() {
|
||||
context.dataStore.edit { settings ->
|
||||
settings.remove(useCaseKey)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun clear() {
|
||||
context.dataStore.edit { it.clear() }
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue