Benoit Marty
1 year ago
committed by
Benoit Marty
7 changed files with 74 additions and 32 deletions
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.features.preferences.api |
||||
|
||||
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. |
||||
*/ |
||||
fun cacheIndex(): Flow<Int> |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.features.preferences.impl |
||||
|
||||
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 kotlinx.coroutines.flow.Flow |
||||
import kotlinx.coroutines.flow.MutableStateFlow |
||||
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 |
||||
} |
||||
|
||||
fun incrementCacheIndex() { |
||||
cacheIndexState.value++ |
||||
} |
||||
} |
Loading…
Reference in new issue