Add plugin badges
This commit is contained in:
parent
a94cc2ae01
commit
0f6d636ca0
@ -1,6 +1,7 @@
|
|||||||
package de.mm20.launcher2.search
|
package de.mm20.launcher2.search
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import de.mm20.launcher2.icons.LauncherIcon
|
import de.mm20.launcher2.icons.LauncherIcon
|
||||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||||
@ -31,6 +32,7 @@ interface SavableSearchable : Searchable, Comparable<SavableSearchable> {
|
|||||||
themed: Boolean
|
themed: Boolean
|
||||||
): LauncherIcon? = null
|
): LauncherIcon? = null
|
||||||
|
|
||||||
|
suspend fun getProviderIcon(context: Context): Drawable? = null
|
||||||
|
|
||||||
override fun compareTo(other: SavableSearchable): Int {
|
override fun compareTo(other: SavableSearchable): Int {
|
||||||
val label1 = labelOverride ?: label
|
val label1 = labelOverride ?: label
|
||||||
|
|||||||
@ -19,6 +19,8 @@ import de.mm20.launcher2.search.FileMetaType
|
|||||||
import de.mm20.launcher2.search.SavableSearchable
|
import de.mm20.launcher2.search.SavableSearchable
|
||||||
import de.mm20.launcher2.search.SearchableSerializer
|
import de.mm20.launcher2.search.SearchableSerializer
|
||||||
import kotlinx.collections.immutable.ImmutableMap
|
import kotlinx.collections.immutable.ImmutableMap
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
data class PluginFile(
|
data class PluginFile(
|
||||||
val id: String,
|
val id: String,
|
||||||
@ -54,6 +56,12 @@ data class PluginFile(
|
|||||||
return PluginFileSerializer()
|
return PluginFileSerializer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun getProviderIcon(context: Context): Drawable? {
|
||||||
|
return withContext(Dispatchers.IO) {
|
||||||
|
context.packageManager.resolveContentProvider(authority, 0)?.loadIcon(context.packageManager)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun loadIcon(context: Context, size: Int, themed: Boolean): LauncherIcon? {
|
override suspend fun loadIcon(context: Context, size: Int, themed: Boolean): LauncherIcon? {
|
||||||
if (thumbnailUri != null) {
|
if (thumbnailUri != null) {
|
||||||
val request = ImageRequest.Builder(context)
|
val request = ImageRequest.Builder(context)
|
||||||
|
|||||||
@ -37,6 +37,7 @@ internal class BadgeServiceImpl(private val context: Context) : BadgeService, Ko
|
|||||||
if (it.suspendedApps) {
|
if (it.suspendedApps) {
|
||||||
providers += SuspendedAppsBadgeProvider()
|
providers += SuspendedAppsBadgeProvider()
|
||||||
}
|
}
|
||||||
|
providers += PluginBadgeProvider(context)
|
||||||
badgeProviders.value = providers
|
badgeProviders.value = providers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
package de.mm20.launcher2.badges.providers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import de.mm20.launcher2.badges.Badge
|
||||||
|
import de.mm20.launcher2.search.SavableSearchable
|
||||||
|
import de.mm20.launcher2.search.Searchable
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
|
||||||
|
class PluginBadgeProvider(private val context: Context): BadgeProvider {
|
||||||
|
override fun getBadge(searchable: Searchable): Flow<Badge?> {
|
||||||
|
if (searchable !is SavableSearchable) return flowOf(null)
|
||||||
|
return flow {
|
||||||
|
val icon = searchable.getProviderIcon(context)
|
||||||
|
if (icon != null) {
|
||||||
|
emit(Badge(icon = icon))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user