Migrate search UI to Jetpack Compose
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
package de.mm20.launcher2.badges
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import de.mm20.launcher2.badges.providers.*
|
||||
import de.mm20.launcher2.badges.providers.BadgeProvider
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
@@ -47,40 +42,42 @@ internal class BadgeRepositoryImpl(private val context: Context) : BadgeReposito
|
||||
}
|
||||
|
||||
override fun getBadge(badgeKey: String): Flow<Badge?> = channelFlow {
|
||||
badgeProviders.collectLatest { providers ->
|
||||
if (providers.isEmpty()) {
|
||||
send(null)
|
||||
return@collectLatest
|
||||
}
|
||||
combine(providers.map { it.getBadge(badgeKey) }) { badges ->
|
||||
if (badges.all { it == null }) {
|
||||
return@combine null
|
||||
withContext(Dispatchers.Default) {
|
||||
badgeProviders.collectLatest { providers ->
|
||||
if (providers.isEmpty()) {
|
||||
send(null)
|
||||
return@collectLatest
|
||||
}
|
||||
val badge = Badge()
|
||||
var progresses = 0
|
||||
badges.filterNotNull().forEach {
|
||||
if (it.icon != null && badge.icon == null) badge.icon = it.icon
|
||||
if (it.iconRes != null && badge.iconRes == null) badge.iconRes = it.iconRes
|
||||
it.number?.let { a ->
|
||||
badge.number?.let { b -> badge.number = a + b } ?: run {
|
||||
badge.number = a
|
||||
combine(providers.map { it.getBadge(badgeKey) }) { badges ->
|
||||
if (badges.all { it == null }) {
|
||||
return@combine null
|
||||
}
|
||||
val badge = Badge()
|
||||
var progresses = 0
|
||||
badges.filterNotNull().forEach {
|
||||
if (it.icon != null && badge.icon == null) badge.icon = it.icon
|
||||
if (it.iconRes != null && badge.iconRes == null) badge.iconRes = it.iconRes
|
||||
it.number?.let { a ->
|
||||
badge.number?.let { b -> badge.number = a + b } ?: run {
|
||||
badge.number = a
|
||||
}
|
||||
}
|
||||
it.progress?.let { a ->
|
||||
badge.progress?.let { b ->
|
||||
badge.progress = a + b
|
||||
} ?: run {
|
||||
badge.progress = a
|
||||
}
|
||||
progresses++
|
||||
}
|
||||
}
|
||||
it.progress?.let { a ->
|
||||
badge.progress?.let {
|
||||
b -> badge.progress = a + b
|
||||
} ?: run {
|
||||
badge.progress = a
|
||||
}
|
||||
progresses++
|
||||
if (progresses > 0) {
|
||||
badge.progress?.let { badge.progress = it / progresses }
|
||||
}
|
||||
return@combine badge
|
||||
}.collectLatest {
|
||||
send(it)
|
||||
}
|
||||
if (progresses > 0) {
|
||||
badge.progress?.let { badge.progress = it / progresses }
|
||||
}
|
||||
return@combine badge
|
||||
}.collectLatest {
|
||||
send(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user