Refactor icons
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package de.mm20.launcher2.search.data
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.Color
|
||||
import androidx.core.content.ContextCompat
|
||||
import de.mm20.launcher2.files.R
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.icons.ColorLayer
|
||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||
import de.mm20.launcher2.icons.TintedIconLayer
|
||||
import java.util.*
|
||||
|
||||
abstract class File(
|
||||
@@ -19,7 +21,7 @@ abstract class File(
|
||||
|
||||
open val providerIconRes: Int? = null
|
||||
|
||||
override fun getPlaceholderIcon(context: Context): LauncherIcon {
|
||||
override fun getPlaceholderIcon(context: Context): StaticLauncherIcon {
|
||||
val (resId, bgColor) = when {
|
||||
isDirectory -> R.drawable.ic_file_folder to R.color.lightblue
|
||||
mimeType.startsWith("image/") -> R.drawable.ic_file_picture to R.color.teal
|
||||
@@ -47,17 +49,23 @@ abstract class File(
|
||||
else -> R.drawable.ic_file_generic to R.color.bluegrey
|
||||
}
|
||||
}
|
||||
return LauncherIcon(
|
||||
foreground = context.getDrawable(resId)!!,
|
||||
background = ColorDrawable(ContextCompat.getColor(context, bgColor)),
|
||||
foregroundScale = 0.5f
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = TintedIconLayer(
|
||||
icon = ContextCompat.getDrawable(context, resId)!!,
|
||||
scale = 0.5f,
|
||||
color = Color.WHITE
|
||||
),
|
||||
backgroundLayer = ColorLayer(ContextCompat.getColor(context, bgColor))
|
||||
)
|
||||
}
|
||||
|
||||
fun getFileType(context: Context): String {
|
||||
if (isDirectory) return context.getString(R.string.file_type_directory)
|
||||
if (mimeType == "application/vendor.de.mm20.launcher2.backup") {
|
||||
return context.getString(R.string.file_type_launcherbackup, context.getString(R.string.app_name))
|
||||
return context.getString(
|
||||
R.string.file_type_launcherbackup,
|
||||
context.getString(R.string.app_name)
|
||||
)
|
||||
}
|
||||
val resource = when (mimeType) {
|
||||
"application/zip",
|
||||
@@ -107,7 +115,10 @@ abstract class File(
|
||||
}
|
||||
if (resource == R.string.file_type_none && label.matches(Regex(".+\\..+"))) {
|
||||
val extension = label.substringAfterLast(".").toUpperCase(Locale.getDefault())
|
||||
if (extension == "kvaesitso") return context.getString(R.string.file_type_launcherbackup, context.getString(R.string.app_name))
|
||||
if (extension == "kvaesitso") return context.getString(
|
||||
R.string.file_type_launcherbackup,
|
||||
context.getString(R.string.app_name)
|
||||
)
|
||||
return context.getString(R.string.file_type_generic, extension)
|
||||
}
|
||||
return context.getString(resource)
|
||||
|
||||
@@ -15,10 +15,12 @@ import android.util.Size
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import de.mm20.launcher2.files.R
|
||||
import de.mm20.launcher2.icons.ColorLayer
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.icons.StaticIconLayer
|
||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||
import de.mm20.launcher2.ktx.formatToString
|
||||
import de.mm20.launcher2.media.ThumbnailUtilsCompat
|
||||
import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.component.KoinComponent
|
||||
@@ -43,7 +45,6 @@ open class LocalFile(
|
||||
override suspend fun loadIcon(
|
||||
context: Context,
|
||||
size: Int,
|
||||
legacyIconBackground: LegacyIconBackground
|
||||
): LauncherIcon? {
|
||||
if (!JavaIOFile(path).exists()) return null
|
||||
when {
|
||||
@@ -55,9 +56,12 @@ open class LocalFile(
|
||||
)
|
||||
} ?: return null
|
||||
|
||||
return LauncherIcon(
|
||||
foreground = BitmapDrawable(context.resources, thumbnail),
|
||||
autoGenerateBackgroundMode = legacyIconBackground.number
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = BitmapDrawable(context.resources, thumbnail),
|
||||
scale = 1f,
|
||||
),
|
||||
backgroundLayer = ColorLayer()
|
||||
)
|
||||
}
|
||||
mimeType.startsWith("video/") -> {
|
||||
@@ -67,9 +71,13 @@ open class LocalFile(
|
||||
Size(size, size)
|
||||
)
|
||||
} ?: return null
|
||||
return LauncherIcon(
|
||||
foreground = BitmapDrawable(context.resources, thumbnail),
|
||||
autoGenerateBackgroundMode = legacyIconBackground.number
|
||||
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = BitmapDrawable(context.resources, thumbnail),
|
||||
scale = 1f,
|
||||
),
|
||||
backgroundLayer = ColorLayer()
|
||||
)
|
||||
}
|
||||
mimeType.startsWith("audio/") -> {
|
||||
@@ -94,9 +102,13 @@ open class LocalFile(
|
||||
|
||||
}
|
||||
thumbnail ?: return null
|
||||
return LauncherIcon(
|
||||
foreground = BitmapDrawable(context.resources, thumbnail),
|
||||
autoGenerateBackgroundMode = legacyIconBackground.number
|
||||
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = BitmapDrawable(context.resources, thumbnail),
|
||||
scale = 1f,
|
||||
),
|
||||
backgroundLayer = ColorLayer()
|
||||
)
|
||||
|
||||
}
|
||||
@@ -107,18 +119,24 @@ open class LocalFile(
|
||||
} ?: return null
|
||||
when {
|
||||
icon is AdaptiveIconDrawable -> {
|
||||
return LauncherIcon(
|
||||
foreground = icon.foreground,
|
||||
background = icon.background,
|
||||
foregroundScale = 1.5f,
|
||||
backgroundScale = 1.5f
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = icon.foreground,
|
||||
scale = 1.5f,
|
||||
),
|
||||
backgroundLayer = StaticIconLayer(
|
||||
icon = icon.background,
|
||||
scale = 1.5f,
|
||||
)
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
return LauncherIcon(
|
||||
foreground = icon,
|
||||
foregroundScale = 0.7f,
|
||||
autoGenerateBackgroundMode = legacyIconBackground.number
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = icon,
|
||||
scale = 0.7f,
|
||||
),
|
||||
backgroundLayer = ColorLayer()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user