Annual refactor
This commit is contained in:
@@ -32,15 +32,14 @@ import de.mm20.launcher2.icons.transformations.LegacyToAdaptiveTransformation
|
||||
import de.mm20.launcher2.icons.transformations.transform
|
||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import de.mm20.launcher2.search.Application
|
||||
import de.mm20.launcher2.search.SavableSearchable
|
||||
import de.mm20.launcher2.search.data.LauncherApp
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
@@ -283,9 +282,9 @@ class IconService(
|
||||
|
||||
val providerOptions = mutableListOf<CustomIcon>()
|
||||
|
||||
if (searchable is LauncherApp) {
|
||||
if (searchable is Application) {
|
||||
val iconPackIcons = iconPackManager.getAllIconPackIcons(
|
||||
searchable.launcherActivityInfo.componentName
|
||||
searchable.componentName
|
||||
)
|
||||
|
||||
providerOptions.addAll(
|
||||
|
||||
+3
-3
@@ -6,15 +6,15 @@ import android.content.pm.PackageManager
|
||||
import de.mm20.launcher2.icons.DynamicCalendarIcon
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.ktx.obtainTypedArrayOrNull
|
||||
import de.mm20.launcher2.search.Application
|
||||
import de.mm20.launcher2.search.SavableSearchable
|
||||
import de.mm20.launcher2.search.data.LauncherApp
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class CalendarIconProvider(val context: Context, val themed: Boolean): IconProvider {
|
||||
override suspend fun getIcon(searchable: SavableSearchable, size: Int): LauncherIcon? = withContext(Dispatchers.IO) {
|
||||
if(searchable !is LauncherApp) return@withContext null
|
||||
val component = ComponentName(searchable.`package`, searchable.activity)
|
||||
if(searchable !is Application) return@withContext null
|
||||
val component = searchable.componentName
|
||||
val pm = context.packageManager
|
||||
val ai = try {
|
||||
pm.getActivityInfo(component, PackageManager.GET_META_DATA)
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ import android.content.pm.PackageManager
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.icons.compat.AdaptiveIconDrawableCompat
|
||||
import de.mm20.launcher2.icons.compat.toLauncherIcon
|
||||
import de.mm20.launcher2.search.Application
|
||||
import de.mm20.launcher2.search.SavableSearchable
|
||||
import de.mm20.launcher2.search.data.LauncherApp
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@@ -16,8 +16,8 @@ class CompatIconProvider(
|
||||
private val themed: Boolean = false,
|
||||
) : IconProvider {
|
||||
override suspend fun getIcon(searchable: SavableSearchable, size: Int): LauncherIcon? {
|
||||
if (searchable !is LauncherApp) return null
|
||||
val component = ComponentName(searchable.`package`, searchable.activity)
|
||||
if (searchable !is Application) return null
|
||||
val component = searchable.componentName
|
||||
|
||||
val icon = withContext(Dispatchers.IO) {
|
||||
val activityInfo = try {
|
||||
|
||||
+4
-4
@@ -6,18 +6,18 @@ import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.icons.compat.AdaptiveIconDrawableCompat
|
||||
import de.mm20.launcher2.icons.compat.ClockIconConfig
|
||||
import de.mm20.launcher2.icons.compat.toLauncherIcon
|
||||
import de.mm20.launcher2.search.Application
|
||||
import de.mm20.launcher2.search.SavableSearchable
|
||||
import de.mm20.launcher2.search.data.LauncherApp
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class DynamicClockIconProvider(val context: Context, private val themed: Boolean) : IconProvider {
|
||||
override suspend fun getIcon(searchable: SavableSearchable, size: Int): LauncherIcon? = withContext(Dispatchers.IO) {
|
||||
if (searchable !is LauncherApp) return@withContext null
|
||||
if (searchable !is Application) return@withContext null
|
||||
val pm = context.packageManager
|
||||
val appInfo = try {
|
||||
pm.getApplicationInfo(
|
||||
searchable.`package`,
|
||||
searchable.componentName.packageName,
|
||||
PackageManager.GET_META_DATA
|
||||
)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
@@ -47,7 +47,7 @@ class DynamicClockIconProvider(val context: Context, private val themed: Boolean
|
||||
|
||||
// Workaround for Google Clock themed icon because it is weird and I don't understand
|
||||
// how to get the correct layers from the drawable without hardcoding them here.
|
||||
val clockConfig = if (themed && searchable.`package` == "com.google.android.deskclock") {
|
||||
val clockConfig = if (themed && searchable.componentName.packageName == "com.google.android.deskclock") {
|
||||
ClockIconConfig(
|
||||
hourLayer = 0,
|
||||
minuteLayer = 2,
|
||||
|
||||
+13
-6
@@ -1,10 +1,12 @@
|
||||
package de.mm20.launcher2.icons.providers
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.LauncherApps
|
||||
import androidx.core.content.getSystemService
|
||||
import de.mm20.launcher2.icons.*
|
||||
import de.mm20.launcher2.search.Application
|
||||
import de.mm20.launcher2.search.SavableSearchable
|
||||
import de.mm20.launcher2.search.data.LauncherApp
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@@ -15,15 +17,20 @@ class IconPackIconProvider(
|
||||
private val allowThemed: Boolean,
|
||||
): IconProvider {
|
||||
override suspend fun getIcon(searchable: SavableSearchable, size: Int): LauncherIcon? {
|
||||
if (searchable !is LauncherApp) return null
|
||||
if (searchable !is Application) return null
|
||||
|
||||
return iconPackManager.getIcon(iconPack.packageName, searchable.`package`, searchable.activity, allowThemed)
|
||||
|
||||
return iconPackManager.getIcon(iconPack.packageName, searchable.componentName.packageName, searchable.componentName.className, allowThemed)
|
||||
?: iconPackManager.generateIcon(
|
||||
context,
|
||||
iconPack.packageName,
|
||||
baseIcon = withContext(Dispatchers.IO) {
|
||||
searchable.launcherActivityInfo.getIcon(context.resources.displayMetrics.densityDpi)
|
||||
},
|
||||
val ai = context.getSystemService<LauncherApps>()?.resolveActivity(
|
||||
Intent().setComponent(searchable.componentName),
|
||||
searchable.user
|
||||
)
|
||||
ai?.getIcon(context.resources.displayMetrics.densityDpi)
|
||||
} ?: return null,
|
||||
size = size,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user