Nodes: rework RootFlowNode with cache service
This commit is contained in:
parent
4612da16d5
commit
fc7bdafbcb
6 changed files with 90 additions and 52 deletions
|
|
@ -23,4 +23,5 @@ android {
|
|||
|
||||
dependencies {
|
||||
implementation(projects.libraries.architecture)
|
||||
api(projects.libraries.matrix.api)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
package io.element.android.features.preferences.api
|
||||
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface CacheService {
|
||||
/**
|
||||
* Returns a flow of the current cache index, can let the app to know when the
|
||||
* cache has been cleared, for instance to restart the app.
|
||||
* Will be a flow of Int, starting from 0, and incrementing each time the cache is cleared.
|
||||
* A flow of [SessionId], can let the app to know when the
|
||||
* cache has been cleared for a given session, for instance to restart the app.
|
||||
*/
|
||||
fun cacheIndex(): Flow<Int>
|
||||
val clearedCacheEventFlow: Flow<SessionId>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,20 +20,19 @@ import com.squareup.anvil.annotations.ContributesBinding
|
|||
import io.element.android.features.preferences.api.CacheService
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.di.SingleIn
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import javax.inject.Inject
|
||||
|
||||
@SingleIn(AppScope::class)
|
||||
@ContributesBinding(AppScope::class)
|
||||
class DefaultCacheService @Inject constructor() : CacheService {
|
||||
private val cacheIndexState = MutableStateFlow(0)
|
||||
|
||||
override fun cacheIndex(): Flow<Int> {
|
||||
return cacheIndexState
|
||||
}
|
||||
private val _clearedCacheEventFlow = MutableSharedFlow<SessionId>(0)
|
||||
override val clearedCacheEventFlow: Flow<SessionId> = _clearedCacheEventFlow
|
||||
|
||||
fun incrementCacheIndex() {
|
||||
cacheIndexState.value++
|
||||
suspend fun onClearedCache(sessionId: SessionId) {
|
||||
_clearedCacheEventFlow.emit(sessionId)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
|||
import io.element.android.libraries.di.ApplicationContext
|
||||
import io.element.android.libraries.di.SessionScope
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
import javax.inject.Inject
|
||||
|
|
@ -57,6 +58,6 @@ class DefaultClearCacheUseCase @Inject constructor(
|
|||
// Clear app cache
|
||||
context.cacheDir.deleteRecursively()
|
||||
// Ensure the app is restarted
|
||||
defaultCacheIndexProvider.incrementCacheIndex()
|
||||
defaultCacheIndexProvider.onClearedCache(matrixClient.sessionId)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue