Nodes: rework RootFlowNode with cache service
This commit is contained in:
parent
4612da16d5
commit
fc7bdafbcb
6 changed files with 90 additions and 52 deletions
|
|
@ -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