Refactor icons
This commit is contained in:
@@ -3,22 +3,13 @@ package de.mm20.launcher2.search.data
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.net.Uri
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.palette.graphics.Palette
|
||||
import androidx.core.content.ContextCompat
|
||||
import coil.imageLoader
|
||||
import coil.request.ImageRequest
|
||||
import de.mm20.launcher2.graphics.TextDrawable
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.ktx.dp
|
||||
import de.mm20.launcher2.ktx.sp
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
||||
import de.mm20.launcher2.icons.*
|
||||
import de.mm20.launcher2.websites.R
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
class Website(
|
||||
@@ -31,7 +22,10 @@ class Website(
|
||||
) : Searchable() {
|
||||
|
||||
override val key = "web://$url"
|
||||
override suspend fun loadIcon(context: Context, size: Int, legacyIconBackground: LegacyIconBackground): LauncherIcon? {
|
||||
override suspend fun loadIcon(
|
||||
context: Context,
|
||||
size: Int,
|
||||
): LauncherIcon? {
|
||||
if (favicon.isEmpty()) return null
|
||||
try {
|
||||
val request = ImageRequest.Builder(context)
|
||||
@@ -40,11 +34,13 @@ class Website(
|
||||
.allowHardware(false)
|
||||
.build()
|
||||
val icon = context.imageLoader.execute(request).drawable ?: return null
|
||||
return LauncherIcon(
|
||||
foreground = icon,
|
||||
background = color.let { ColorDrawable(it) },
|
||||
foregroundScale = 0.7f,
|
||||
autoGenerateBackgroundMode = legacyIconBackground.number
|
||||
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = icon,
|
||||
scale = 0.7f,
|
||||
),
|
||||
backgroundLayer = ColorLayer(color)
|
||||
)
|
||||
} catch (e: ExecutionException) {
|
||||
return null
|
||||
@@ -52,19 +48,20 @@ class Website(
|
||||
|
||||
}
|
||||
|
||||
override fun getPlaceholderIcon(context: Context): LauncherIcon {
|
||||
val drawable = if (label.isNotEmpty()) {
|
||||
TextDrawable(
|
||||
label[0].toString(),
|
||||
typeface = Typeface.DEFAULT_BOLD,
|
||||
fontSize = 40 * context.sp,
|
||||
height = (48 * context.dp).toInt()
|
||||
override fun getPlaceholderIcon(context: Context): StaticLauncherIcon {
|
||||
if (label.isNotBlank()) {
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = TextLayer(text = label[0].toString(), color = Color.WHITE),
|
||||
backgroundLayer = ColorLayer(Color.LTGRAY)
|
||||
)
|
||||
} else context.getDrawable(R.drawable.ic_website)!!
|
||||
return LauncherIcon(
|
||||
foreground = drawable,
|
||||
background = ColorDrawable(if (color != 0) color else Color.LTGRAY),
|
||||
foregroundScale = 1f
|
||||
}
|
||||
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_website)!!,
|
||||
scale = 0.5f,
|
||||
),
|
||||
backgroundLayer = ColorLayer(if (color != 0) color else Color.LTGRAY)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user