When clearing cache, also reset some data store in prefs/datastore.
This commit is contained in:
parent
e566bab75d
commit
7207afebcc
10 changed files with 38 additions and 1 deletions
|
|
@ -67,4 +67,8 @@ class FakeAnalyticsService(
|
|||
|
||||
override fun trackError(throwable: Throwable) {
|
||||
}
|
||||
|
||||
override suspend fun reset() {
|
||||
didAskUserConsentFlow.value = false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,4 +20,6 @@ import kotlinx.coroutines.flow.StateFlow
|
|||
|
||||
interface FtueState {
|
||||
val shouldDisplayFlow: StateFlow<Boolean>
|
||||
|
||||
suspend fun reset()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ class DefaultFtueState @Inject constructor(
|
|||
|
||||
override val shouldDisplayFlow = MutableStateFlow(isAnyStepIncomplete())
|
||||
|
||||
override suspend fun reset() {
|
||||
welcomeScreenState.reset()
|
||||
analyticsService.reset()
|
||||
}
|
||||
|
||||
init {
|
||||
analyticsService.didAskUserConsent()
|
||||
.onEach { updateState() }
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package io.element.android.features.ftue.impl.welcome.state
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.di.DefaultPreferences
|
||||
|
|
@ -27,7 +28,7 @@ import javax.inject.Inject
|
|||
@SingleIn(AppScope::class)
|
||||
class AndroidWelcomeScreenState @Inject constructor(
|
||||
@DefaultPreferences private val sharedPreferences: SharedPreferences,
|
||||
): WelcomeScreenState {
|
||||
) : WelcomeScreenState {
|
||||
|
||||
companion object {
|
||||
private const val IS_WELCOME_SCREEN_SHOWN = "is_welcome_screen_shown"
|
||||
|
|
@ -40,4 +41,10 @@ class AndroidWelcomeScreenState @Inject constructor(
|
|||
override fun setWelcomeScreenShown() {
|
||||
sharedPreferences.edit().putBoolean(IS_WELCOME_SCREEN_SHOWN, true).apply()
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
sharedPreferences.edit {
|
||||
remove(IS_WELCOME_SCREEN_SHOWN)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,5 @@ package io.element.android.features.ftue.impl.welcome.state
|
|||
interface WelcomeScreenState {
|
||||
fun isWelcomeScreenNeeded(): Boolean
|
||||
fun setWelcomeScreenShown()
|
||||
fun reset()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,4 +27,8 @@ class FakeWelcomeState : WelcomeScreenState {
|
|||
override fun setWelcomeScreenShown() {
|
||||
isWelcomeScreenNeeded = false
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
isWelcomeScreenNeeded = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ dependencies {
|
|||
implementation(projects.libraries.uiStrings)
|
||||
implementation(projects.features.rageshake.api)
|
||||
implementation(projects.features.analytics.api)
|
||||
implementation(projects.features.ftue.api)
|
||||
implementation(projects.libraries.matrixui)
|
||||
implementation(projects.features.logout.api)
|
||||
implementation(projects.services.toolbox.api)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import android.content.Context
|
|||
import coil.Coil
|
||||
import coil.annotation.ExperimentalCoilApi
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.features.ftue.api.state.FtueState
|
||||
import io.element.android.features.preferences.impl.DefaultCacheService
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.di.ApplicationContext
|
||||
|
|
@ -43,6 +44,7 @@ class DefaultClearCacheUseCase @Inject constructor(
|
|||
private val coroutineDispatchers: CoroutineDispatchers,
|
||||
private val defaultCacheIndexProvider: DefaultCacheService,
|
||||
private val okHttpClient: Provider<OkHttpClient>,
|
||||
private val ftueState: FtueState,
|
||||
) : ClearCacheUseCase {
|
||||
override suspend fun invoke() = withContext(coroutineDispatchers.io) {
|
||||
// Clear Matrix cache
|
||||
|
|
@ -56,6 +58,8 @@ class DefaultClearCacheUseCase @Inject constructor(
|
|||
okHttpClient.get().cache?.delete()
|
||||
// Clear app cache
|
||||
context.cacheDir.deleteRecursively()
|
||||
// Clear some settings
|
||||
ftueState.reset()
|
||||
// Ensure the app is restarted
|
||||
defaultCacheIndexProvider.onClearedCache(matrixClient.sessionId)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,4 +58,9 @@ interface AnalyticsService: AnalyticsTracker, ErrorTracker {
|
|||
* To be called when a session is destroyed.
|
||||
*/
|
||||
suspend fun onSignOut()
|
||||
|
||||
/**
|
||||
* Reset the analytics service (will ask for user consent again).
|
||||
*/
|
||||
suspend fun reset()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@ class DefaultAnalyticsService @Inject constructor(
|
|||
analyticsStore.setDidAskUserConsent()
|
||||
}
|
||||
|
||||
override suspend fun reset() {
|
||||
analyticsStore.setDidAskUserConsent(false)
|
||||
}
|
||||
|
||||
override fun getAnalyticsId(): Flow<String> {
|
||||
return analyticsStore.analyticsIdFlow
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue