Use operator invoke.

This commit is contained in:
Benoit Marty 2023-06-23 15:13:03 +02:00 committed by Benoit Marty
parent cd3b653e1d
commit 6591fbec17
5 changed files with 8 additions and 8 deletions

View file

@ -127,13 +127,13 @@ class DeveloperSettingsPresenter @Inject constructor(
private fun CoroutineScope.computeCacheSize(cacheSize: MutableState<Async<String>>) = launch { private fun CoroutineScope.computeCacheSize(cacheSize: MutableState<Async<String>>) = launch {
suspend { suspend {
computeCacheSizeUseCase.execute() computeCacheSizeUseCase()
}.execute(cacheSize) }.execute(cacheSize)
} }
private fun CoroutineScope.clearCache(clearCacheAction: MutableState<Async<Unit>>) = launch { private fun CoroutineScope.clearCache(clearCacheAction: MutableState<Async<Unit>>) = launch {
suspend { suspend {
clearCacheUseCase.execute() clearCacheUseCase()
}.execute(clearCacheAction) }.execute(clearCacheAction)
} }
} }

View file

@ -33,7 +33,7 @@ import javax.inject.Inject
import javax.inject.Provider import javax.inject.Provider
interface ClearCacheUseCase { interface ClearCacheUseCase {
suspend fun execute() suspend operator fun invoke()
} }
@ContributesBinding(SessionScope::class) @ContributesBinding(SessionScope::class)
@ -44,7 +44,7 @@ class DefaultClearCacheUseCase @Inject constructor(
private val authenticationService: MatrixAuthenticationService, private val authenticationService: MatrixAuthenticationService,
private val okHttpClient: Provider<OkHttpClient>, private val okHttpClient: Provider<OkHttpClient>,
) : ClearCacheUseCase { ) : ClearCacheUseCase {
override suspend fun execute() = withContext(coroutineDispatchers.io) { override suspend fun invoke() = withContext(coroutineDispatchers.io) {
// Clear Matrix cache // Clear Matrix cache
matrixClient.clearCache() matrixClient.clearCache()
// Clear Coil cache // Clear Coil cache

View file

@ -28,7 +28,7 @@ import kotlinx.coroutines.withContext
import javax.inject.Inject import javax.inject.Inject
interface ComputeCacheSizeUseCase { interface ComputeCacheSizeUseCase {
suspend fun execute(): String suspend operator fun invoke(): String
} }
@ContributesBinding(SessionScope::class) @ContributesBinding(SessionScope::class)
@ -38,7 +38,7 @@ class DefaultComputeCacheSizeUseCase @Inject constructor(
private val coroutineDispatchers: CoroutineDispatchers, private val coroutineDispatchers: CoroutineDispatchers,
private val fileSizeFormatter: FileSizeFormatter, private val fileSizeFormatter: FileSizeFormatter,
) : ComputeCacheSizeUseCase { ) : ComputeCacheSizeUseCase {
override suspend fun execute(): String = withContext(coroutineDispatchers.io) { override suspend fun invoke(): String = withContext(coroutineDispatchers.io) {
var cumulativeSize = 0L var cumulativeSize = 0L
cumulativeSize += matrixClient.getCacheSize() cumulativeSize += matrixClient.getCacheSize()
// - 4096 to not include the size fo the folder // - 4096 to not include the size fo the folder

View file

@ -22,7 +22,7 @@ class FakeClearCacheUseCase : ClearCacheUseCase {
var executeHasBeenCalled = false var executeHasBeenCalled = false
private set private set
override suspend fun execute() = simulateLongTask { override suspend fun invoke() = simulateLongTask {
executeHasBeenCalled = true executeHasBeenCalled = true
} }
} }

View file

@ -19,7 +19,7 @@ package io.element.android.features.preferences.impl.tasks
import io.element.android.tests.testutils.simulateLongTask import io.element.android.tests.testutils.simulateLongTask
class FakeComputeCacheSizeUseCase : ComputeCacheSizeUseCase { class FakeComputeCacheSizeUseCase : ComputeCacheSizeUseCase {
override suspend fun execute() = simulateLongTask { override suspend fun invoke() = simulateLongTask {
"O kB" "O kB"
} }
} }