From 2996966e49c97d636a75e2a8d5af08553c50d674 Mon Sep 17 00:00:00 2001 From: LooKeR Date: Wed, 25 Dec 2024 22:13:21 +0530 Subject: [PATCH] Some optmizations --- .../looker/droidify/index/RepositoryUpdater.kt | 2 +- .../com/looker/droidify/service/SyncService.kt | 16 ++++++++++------ build-logic/structure/src/main/kotlin/Modules.kt | 3 +-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/looker/droidify/index/RepositoryUpdater.kt b/app/src/main/kotlin/com/looker/droidify/index/RepositoryUpdater.kt index a3d7bf29..174adb4b 100644 --- a/app/src/main/kotlin/com/looker/droidify/index/RepositoryUpdater.kt +++ b/app/src/main/kotlin/com/looker/droidify/index/RepositoryUpdater.kt @@ -174,7 +174,7 @@ object RepositoryUpdater { authentication(repository.authentication) } ) { read, total -> - callback(Stage.DOWNLOAD, read.value, total.value) + callback(Stage.DOWNLOAD, read.value, total.value.takeIf { it != 0L }) } when (result) { diff --git a/app/src/main/kotlin/com/looker/droidify/service/SyncService.kt b/app/src/main/kotlin/com/looker/droidify/service/SyncService.kt index fd0bf467..01da7dba 100644 --- a/app/src/main/kotlin/com/looker/droidify/service/SyncService.kt +++ b/app/src/main/kotlin/com/looker/droidify/service/SyncService.kt @@ -43,6 +43,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.sample import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex @@ -67,13 +68,12 @@ class SyncService : ConnectionService() { private const val ACTION_CANCEL = "${BuildConfig.APPLICATION_ID}.intent.action.CANCEL" private val syncState = MutableSharedFlow() - private val onFinishState = MutableSharedFlow() } @Inject lateinit var settingsRepository: SettingsRepository - private sealed class State(val name: String) { + sealed class State(val name: String) { data class Connecting(val appName: String) : State(appName) data class Syncing( val appName: String, @@ -81,6 +81,8 @@ class SyncService : ConnectionService() { val read: DataSize, val total: DataSize? ) : State(appName) + + data object Finish : State("") } private class Task(val repositoryId: Long, val manual: Boolean) @@ -106,8 +108,8 @@ class SyncService : ConnectionService() { inner class Binder : android.os.Binder() { - val onFinish: SharedFlow - get() = onFinishState.asSharedFlow() + val state: SharedFlow + get() = syncState.asSharedFlow() private fun sync(ids: List, request: SyncRequest) { val cancelledTask = @@ -363,6 +365,8 @@ class SyncService : ConnectionService() { } } } + + is State.Finish -> {} }::class }.build() ) @@ -468,7 +472,7 @@ class SyncService : ConnectionService() { ) { try { if (!hasUpdates || !notifyUpdates) { - onFinishState.emit(Unit) + syncState.emit(State.Finish) val needStop = started == Started.MANUAL started = Started.NO if (needStop) stopForegroundCompat() @@ -573,7 +577,7 @@ class SyncService : ConnectionService() { private val syncConnection = Connection(SyncService::class.java, onBind = { connection, binder -> jobScope.launch { - binder.onFinish.collect { + binder.state.filter { it is State.Finish }.collect { val params = syncParams if (params != null) { syncParams = null diff --git a/build-logic/structure/src/main/kotlin/Modules.kt b/build-logic/structure/src/main/kotlin/Modules.kt index 91b17748..5999bbe9 100644 --- a/build-logic/structure/src/main/kotlin/Modules.kt +++ b/build-logic/structure/src/main/kotlin/Modules.kt @@ -15,8 +15,7 @@ object Modules { } fun DependencyHandlerScope.modules(vararg module: String) { - val modules = module.toList() - modules.forEach { + module.forEach { add("implementation", project(it)) } }