Skip to content

Commit

Permalink
Some optmizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamlooker committed Dec 25, 2024
1 parent 6483c46 commit 2996966
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 10 additions & 6 deletions app/src/main/kotlin/com/looker/droidify/service/SyncService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,20 +68,21 @@ class SyncService : ConnectionService<SyncService.Binder>() {
private const val ACTION_CANCEL = "${BuildConfig.APPLICATION_ID}.intent.action.CANCEL"

private val syncState = MutableSharedFlow<State>()
private val onFinishState = MutableSharedFlow<Unit>()
}

@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,
val stage: RepositoryUpdater.Stage,
val read: DataSize,
val total: DataSize?
) : State(appName)

data object Finish : State("")
}

private class Task(val repositoryId: Long, val manual: Boolean)
Expand All @@ -106,8 +108,8 @@ class SyncService : ConnectionService<SyncService.Binder>() {

inner class Binder : android.os.Binder() {

val onFinish: SharedFlow<Unit>
get() = onFinishState.asSharedFlow()
val state: SharedFlow<State>
get() = syncState.asSharedFlow()

private fun sync(ids: List<Long>, request: SyncRequest) {
val cancelledTask =
Expand Down Expand Up @@ -363,6 +365,8 @@ class SyncService : ConnectionService<SyncService.Binder>() {
}
}
}

is State.Finish -> {}
}::class
}.build()
)
Expand Down Expand Up @@ -468,7 +472,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
) {
try {
if (!hasUpdates || !notifyUpdates) {
onFinishState.emit(Unit)
syncState.emit(State.Finish)
val needStop = started == Started.MANUAL
started = Started.NO
if (needStop) stopForegroundCompat()
Expand Down Expand Up @@ -573,7 +577,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
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
Expand Down
3 changes: 1 addition & 2 deletions build-logic/structure/src/main/kotlin/Modules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ object Modules {
}

fun DependencyHandlerScope.modules(vararg module: String) {
val modules = module.toList()
modules.forEach {
module.forEach {
add("implementation", project(it))
}
}

0 comments on commit 2996966

Please sign in to comment.