mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat(apps): add icon packs, per-app icons and an Appearance panel (#2207)
* feat(apps): add an Appearance panel to the Apps page A Palette button in the Apps header opens a panel for icon size, spacing and hiding app names. * feat(apps): support icon packs and per-app icons The Appearance panel gains an Icon pack choice. Packs are found through the ADW and Nova theme intents and must ship an appfilter.xml in res/xml, res/raw or assets. Work profile apps keep their badge. Apps a pack does not cover are drawn on its iconback, iconmask, iconupon and scale tags when it has them, and keep their system icon otherwise. For packs with an iconback, App color background paints that plate in each app's main color instead of the pack's own. With a pack selected, an app's long-press menu offers Change icon, which opens a searchable picker listing icons that match the app first. Reset icon removes one choice, and Reset in the panel removes them all. Calendar apps use the pack's icon for today's date. * feat(apps): translate the Appearance panel and icon strings Adds the 19 new strings to all 32 languages, reusing each language's existing wording where it has one. Icon size and spacing labels are kept short to fit the panel's tabs. * fix(apps): finish loading custom icons before marking them loaded Two app list refreshes can start together on resume. The second one could see the overrides as loaded before the first had read them, and build the list without custom icons.
This commit is contained in:
1 parent
dacfee64ab
commit
b1b6ab7931
47 files changed
+1475
-23
No files matched your search
@@ -227,6 +227,11 @@ class FrontEndActivity : ComponentActivity() {
|
||||
refreshWifiDiscovery()
|
||||
}
|
||||
}
|
||||
private val dateReceiver = object : android.content.BroadcastReceiver() {
|
||||
override fun onReceive(context: android.content.Context?, intent: Intent?) {
|
||||
refreshAndroidApps()
|
||||
}
|
||||
}
|
||||
private val mediaRefresh = Runnable {
|
||||
refresh()
|
||||
refreshAddedGames()
|
||||
@@ -1594,6 +1599,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
refreshHomeAppState()
|
||||
}
|
||||
},
|
||||
onAppIconsChanged = { refreshAndroidApps() },
|
||||
onAndroidApp = { app, displayId -> launchAndroidApp(app, displayId) },
|
||||
onBackActionsInverted = { inverted ->
|
||||
SessionPrefs.setBackActionsInverted(this, inverted)
|
||||
@@ -1972,6 +1978,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
registerReceiver(wifiLocationReceiver, android.content.IntentFilter(android.location.LocationManager.MODE_CHANGED_ACTION))
|
||||
registerReceiver(dateReceiver, android.content.IntentFilter(Intent.ACTION_DATE_CHANGED))
|
||||
registerReceiver(mediaReceiver, android.content.IntentFilter().apply {
|
||||
for (action in listOf(Intent.ACTION_MEDIA_MOUNTED, Intent.ACTION_MEDIA_UNMOUNTED, Intent.ACTION_MEDIA_REMOVED,
|
||||
Intent.ACTION_MEDIA_EJECT, Intent.ACTION_MEDIA_BAD_REMOVAL)) addAction(action)
|
||||
@@ -2038,6 +2045,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
override fun onStop() {
|
||||
if (!homeChoiceOpen) HomeApp.releaseUnusedHomeEntry(this)
|
||||
unregisterReceiver(wifiLocationReceiver)
|
||||
unregisterReceiver(dateReceiver)
|
||||
unregisterReceiver(mediaReceiver)
|
||||
getSystemService(android.content.pm.LauncherApps::class.java).unregisterCallback(packageCallback)
|
||||
HomeWidgets.stopListening(this)
|
||||
|
||||
@@ -41,7 +41,7 @@ object HomeApp {
|
||||
val userSerial: Long = 0L,
|
||||
) {
|
||||
val component get() = ComponentName(packageName, className)
|
||||
val key get() = "$packageName/$className" + if (userSerial != 0L) "#$userSerial" else ""
|
||||
val key get() = appKey(packageName, className, userSerial)
|
||||
val work get() = userSerial != 0L
|
||||
}
|
||||
|
||||
@@ -101,6 +101,9 @@ object HomeApp {
|
||||
?: resolved.loadLabel(pm)?.toString()?.trim()?.takeIf { it.isNotEmpty() }
|
||||
}
|
||||
|
||||
private fun appKey(packageName: String, className: String, userSerial: Long) =
|
||||
"$packageName/$className" + if (userSerial != 0L) "#$userSerial" else ""
|
||||
|
||||
fun roleRequestIntent(context: Context): Intent? {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return null
|
||||
val roles = context.getSystemService(RoleManager::class.java) ?: return null
|
||||
@@ -116,13 +119,25 @@ object HomeApp {
|
||||
val pm = context.packageManager
|
||||
val own = Process.myUserHandle()
|
||||
val iconPx = (ICON_DP * context.resources.displayMetrics.density).roundToInt()
|
||||
val densityDpi = context.resources.displayMetrics.densityDpi
|
||||
val pack = IconPack.active(context)
|
||||
val appColors = IconPack.appColors(context)
|
||||
HomeIcons.load(context)
|
||||
val overrides = HomeIcons.overrides
|
||||
val apps = users.userProfiles.flatMap { user ->
|
||||
val serial = if (user == own) 0L else users.getSerialNumberForUser(user)
|
||||
runCatching { launcher.getActivityList(null, user) }.getOrDefault(emptyList()).mapNotNull { info ->
|
||||
val component = info.componentName
|
||||
if (component.packageName == context.packageName && user == own) return@mapNotNull null
|
||||
val label = info.label?.toString()?.trim().orEmpty().ifEmpty { component.packageName }
|
||||
val icon = runCatching { info.getBadgedIcon(0).toBitmap(iconPx, iconPx) }.getOrNull()
|
||||
val icon = runCatching {
|
||||
(overrides[appKey(component.packageName, component.className, serial)]
|
||||
?.let { IconPack.drawable(context, it.pack, it.drawable, densityDpi) }
|
||||
?: pack?.icon(component, densityDpi)
|
||||
?: pack?.plated(info.getIcon(0), iconPx, densityDpi, appColors))
|
||||
?.let { pm.getUserBadgedIcon(it, user) }
|
||||
?.toBitmap(iconPx, iconPx)
|
||||
}.getOrNull() ?: runCatching { info.getBadgedIcon(0).toBitmap(iconPx, iconPx) }.getOrNull()
|
||||
val app = info.applicationInfo
|
||||
val updated = if (user == own) runCatching { pm.getPackageInfo(component.packageName, 0).lastUpdateTime }.getOrNull() else null
|
||||
@Suppress("DEPRECATION")
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.droiddeck.launcher
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
|
||||
object HomeIcons {
|
||||
private const val PREFS = "home_launcher"
|
||||
private const val KEY = "icon_overrides"
|
||||
private const val SEPARATOR = '\t'
|
||||
|
||||
data class Choice(val pack: String, val drawable: String)
|
||||
|
||||
var overrides by mutableStateOf<Map<String, Choice>>(emptyMap())
|
||||
private set
|
||||
@Volatile private var loaded = false
|
||||
|
||||
@Synchronized
|
||||
fun load(context: Context) {
|
||||
if (loaded) return
|
||||
overrides = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
.getStringSet(KEY, emptySet()).orEmpty().mapNotNull(::decode).toMap()
|
||||
loaded = true
|
||||
}
|
||||
|
||||
fun set(context: Context, key: String, pack: String, drawable: String) = save(context, overrides + (key to Choice(pack, drawable)))
|
||||
|
||||
fun clear(context: Context, key: String) = save(context, overrides - key)
|
||||
|
||||
fun clearAll(context: Context) = save(context, emptyMap())
|
||||
|
||||
private fun save(context: Context, next: Map<String, Choice>) {
|
||||
overrides = next
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
|
||||
.putStringSet(KEY, next.map { (key, choice) -> encode(key, choice) }.toSet()).apply()
|
||||
}
|
||||
|
||||
internal fun encode(key: String, choice: Choice) = listOf(key, choice.pack, choice.drawable).joinToString(SEPARATOR.toString())
|
||||
|
||||
internal fun decode(entry: String): Pair<String, Choice>? {
|
||||
val parts = entry.split(SEPARATOR)
|
||||
if (parts.size != 3 || parts.any { it.isEmpty() }) return null
|
||||
return parts[0] to Choice(parts[1], parts[2])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package com.droiddeck.launcher
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffColorFilter
|
||||
import android.graphics.PorterDuffXfermode
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.Xml
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.graphics.createBitmap
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import androidx.palette.graphics.Palette
|
||||
import org.xmlpull.v1.XmlPullParser
|
||||
import java.time.LocalDate
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object IconPack {
|
||||
const val NONE = ""
|
||||
private const val PREFS = "home_launcher"
|
||||
private const val KEY = "icon_pack"
|
||||
private const val APP_COLORS = "icon_pack_app_colors"
|
||||
private const val FILTER = "appfilter"
|
||||
private const val DRAWABLES = "drawable"
|
||||
|
||||
private val ACTIONS = listOf("org.adw.launcher.THEMES", "com.novalauncher.THEME")
|
||||
|
||||
data class Pack(val packageName: String, val label: String)
|
||||
|
||||
internal data class Plate(val back: String?, val mask: String?, val upon: String?, val scale: Float)
|
||||
|
||||
internal data class Filter(val icons: Map<String, String>, val calendars: Map<String, String>, val plate: Plate?) {
|
||||
fun names(component: String, day: Int) = listOfNotNull(calendars[component]?.plus(day), icons[component])
|
||||
}
|
||||
|
||||
class Loaded internal constructor(
|
||||
private val resources: Resources,
|
||||
internal val pack: String,
|
||||
internal val updatedAt: Long,
|
||||
private val filter: Filter,
|
||||
) {
|
||||
fun icon(component: ComponentName, densityDpi: Int) =
|
||||
filter.names(component.flattenToString(), LocalDate.now().dayOfMonth).firstNotNullOfOrNull { load(resources, pack, it, densityDpi) }
|
||||
|
||||
val hasBack get() = filter.plate?.back != null
|
||||
|
||||
fun plated(icon: Drawable, size: Int, densityDpi: Int, appColor: Boolean): Drawable? {
|
||||
val plate = filter.plate ?: return null
|
||||
fun image(name: String?) = name?.let { load(resources, pack, it, densityDpi) }?.toBitmap(size, size)
|
||||
val base = icon.toBitmap(size, size)
|
||||
val color = if (appColor) Palette.from(base).generate().getDominantColor(0).takeIf { it != 0 } else null
|
||||
return compose(base, image(plate.back), image(plate.mask), image(plate.upon), plate.scale, color).toDrawable(resources)
|
||||
}
|
||||
}
|
||||
|
||||
@Volatile private var cached: Loaded? = null
|
||||
|
||||
fun selected(context: Context): String =
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getString(KEY, NONE).orEmpty()
|
||||
|
||||
fun select(context: Context, pack: String) {
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putString(KEY, pack).apply()
|
||||
}
|
||||
|
||||
fun appColors(context: Context): Boolean =
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean(APP_COLORS, false)
|
||||
|
||||
fun setAppColors(context: Context, on: Boolean) {
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean(APP_COLORS, on).apply()
|
||||
}
|
||||
|
||||
fun installed(context: Context): List<Pack> {
|
||||
val pm = context.packageManager
|
||||
return ACTIONS.flatMap { pm.queryIntentActivities(Intent(it), 0) }
|
||||
.map { it.activityInfo.applicationInfo }
|
||||
.distinctBy { it.packageName }
|
||||
.filter { app -> resources(pm, app.packageName)?.let { withXml(it, app.packageName, FILTER) { true } } == true }
|
||||
.map { app -> Pack(app.packageName, app.loadLabel(pm).toString().trim().ifEmpty { app.packageName }) }
|
||||
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.label })
|
||||
}
|
||||
|
||||
fun active(context: Context): Loaded? {
|
||||
val pack = selected(context)
|
||||
if (pack == NONE) return null
|
||||
val pm = context.packageManager
|
||||
val updatedAt = runCatching { pm.getPackageInfo(pack, 0).lastUpdateTime }.getOrNull() ?: return null
|
||||
cached?.takeIf { it.pack == pack && it.updatedAt == updatedAt }?.let { return it }
|
||||
val resources = resources(pm, pack) ?: return null
|
||||
val filter = withXml(resources, pack, FILTER) { parse(it) } ?: return null
|
||||
return Loaded(resources, pack, updatedAt, filter).also { cached = it }
|
||||
}
|
||||
|
||||
fun drawable(context: Context, pack: String, name: String, densityDpi: Int): Drawable? {
|
||||
val resources = resources(context.packageManager, pack) ?: return null
|
||||
return load(resources, pack, name, densityDpi)
|
||||
}
|
||||
|
||||
fun names(context: Context, pack: String): List<String> {
|
||||
val resources = resources(context.packageManager, pack) ?: return emptyList()
|
||||
return withXml(resources, pack, DRAWABLES) { parseNames(it) }?.takeIf { it.isNotEmpty() }
|
||||
?: withXml(resources, pack, FILTER) { parse(it).icons.values.distinct().sorted() }.orEmpty()
|
||||
}
|
||||
|
||||
private fun resources(pm: PackageManager, pack: String): Resources? =
|
||||
runCatching { pm.getResourcesForApplication(pack) }.getOrNull()
|
||||
|
||||
private fun load(resources: Resources, pack: String, name: String, densityDpi: Int): Drawable? {
|
||||
val id = resources.getIdentifier(name, "drawable", pack).takeIf { it != 0 }
|
||||
?: resources.getIdentifier(name, "mipmap", pack).takeIf { it != 0 }
|
||||
?: return null
|
||||
return runCatching { ResourcesCompat.getDrawableForDensity(resources, id, densityDpi, null) }.getOrNull()
|
||||
}
|
||||
|
||||
internal fun parseNames(xml: XmlPullParser): List<String> {
|
||||
val names = LinkedHashSet<String>()
|
||||
forEachTag(xml) { if (xml.name == "item") xml.getAttributeValue(null, "drawable")?.trim()?.takeIf { it.isNotEmpty() }?.let { names.add(it) } }
|
||||
return names.toList()
|
||||
}
|
||||
|
||||
internal fun parse(xml: XmlPullParser): Filter {
|
||||
val icons = HashMap<String, String>()
|
||||
val calendars = HashMap<String, String>()
|
||||
var back: String? = null
|
||||
var mask: String? = null
|
||||
var upon: String? = null
|
||||
var scale = 1f
|
||||
fun image() = xml.getAttributeValue(null, "img1")?.trim()?.takeIf { it.isNotEmpty() }
|
||||
forEachTag(xml) {
|
||||
when (xml.name) {
|
||||
"item" -> {
|
||||
val key = componentKey(xml.getAttributeValue(null, "component"))
|
||||
val drawable = xml.getAttributeValue(null, "drawable")?.trim()
|
||||
if (key != null && !drawable.isNullOrEmpty()) icons.putIfAbsent(key, drawable)
|
||||
}
|
||||
"calendar" -> {
|
||||
val key = componentKey(xml.getAttributeValue(null, "component"))
|
||||
val prefix = xml.getAttributeValue(null, "prefix")?.trim()
|
||||
if (key != null && !prefix.isNullOrEmpty()) calendars.putIfAbsent(key, prefix)
|
||||
}
|
||||
"iconback" -> back = back ?: image()
|
||||
"iconmask" -> mask = mask ?: image()
|
||||
"iconupon" -> upon = upon ?: image()
|
||||
"scale" -> scale = xml.getAttributeValue(null, "factor")?.toFloatOrNull() ?: scale
|
||||
}
|
||||
}
|
||||
return Filter(icons, calendars, if (back == null && mask == null && upon == null) null else Plate(back, mask, upon, scale))
|
||||
}
|
||||
|
||||
internal fun compose(icon: Bitmap, back: Bitmap?, mask: Bitmap?, upon: Bitmap?, scale: Float, backColor: Int? = null): Bitmap {
|
||||
val size = icon.width
|
||||
val inset = (size * (1 - scale) / 2).roundToInt()
|
||||
val result = createBitmap(size, size)
|
||||
val canvas = Canvas(result)
|
||||
val paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
|
||||
val full = Rect(0, 0, size, size)
|
||||
canvas.drawBitmap(icon, null, Rect(inset, inset, size - inset, size - inset), paint)
|
||||
mask?.let {
|
||||
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_OUT)
|
||||
canvas.drawBitmap(it, null, full, paint)
|
||||
}
|
||||
back?.let {
|
||||
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_OVER)
|
||||
paint.colorFilter = backColor?.let { color -> PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN) }
|
||||
canvas.drawBitmap(it, null, full, paint)
|
||||
}
|
||||
paint.xfermode = null
|
||||
paint.colorFilter = null
|
||||
upon?.let { canvas.drawBitmap(it, null, full, paint) }
|
||||
return result
|
||||
}
|
||||
|
||||
private inline fun forEachTag(xml: XmlPullParser, block: () -> Unit) {
|
||||
var event = xml.eventType
|
||||
while (event != XmlPullParser.END_DOCUMENT) {
|
||||
if (event == XmlPullParser.START_TAG) block()
|
||||
event = xml.next()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun componentKey(component: String?): String? =
|
||||
component?.trim()?.removePrefix("ComponentInfo{")?.removeSuffix("}")?.let(ComponentName::unflattenFromString)?.flattenToString()
|
||||
|
||||
private fun <T> withXml(resources: Resources, pack: String, file: String, block: (XmlPullParser) -> T): T? = runCatching {
|
||||
val xml = resources.getIdentifier(file, "xml", pack)
|
||||
val raw = resources.getIdentifier(file, "raw", pack)
|
||||
if (xml != 0) resources.getXml(xml).use(block)
|
||||
else (if (raw != 0) resources.openRawResource(raw) else resources.assets.open("$file.xml"))
|
||||
.use { stream -> block(Xml.newPullParser().also { it.setInput(stream, null) }) }
|
||||
}.getOrNull()
|
||||
}
|
||||
@@ -73,6 +73,7 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -108,10 +109,13 @@ import androidx.compose.ui.zIndex
|
||||
import com.droiddeck.launcher.HomeApp
|
||||
import com.droiddeck.launcher.HomeFolders
|
||||
import com.droiddeck.launcher.HomeHidden
|
||||
import com.droiddeck.launcher.HomeIcons
|
||||
import com.droiddeck.launcher.HomePins
|
||||
import com.droiddeck.launcher.IconPack
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.graphics.Bitmap
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.withContext
|
||||
import com.droiddeck.launcher.HomeWidgets
|
||||
import com.droiddeck.launcher.R
|
||||
@@ -229,6 +233,48 @@ internal object AppsView {
|
||||
}
|
||||
}
|
||||
|
||||
internal object AppsGrid {
|
||||
const val SMALL = 44
|
||||
const val MEDIUM = 52
|
||||
const val LARGE = 64
|
||||
private val ICON_SIZES = listOf(SMALL, MEDIUM, LARGE)
|
||||
const val TIGHT = -12
|
||||
const val NORMAL = 0
|
||||
const val ROOMY = 16
|
||||
private val SPACINGS = listOf(TIGHT, NORMAL, ROOMY)
|
||||
|
||||
var labels by mutableStateOf(true)
|
||||
private set
|
||||
var iconDp by mutableStateOf(MEDIUM)
|
||||
private set
|
||||
var spacing by mutableStateOf(NORMAL)
|
||||
private set
|
||||
|
||||
private fun prefs(context: Context) = context.getSharedPreferences("home_launcher", Context.MODE_PRIVATE)
|
||||
|
||||
fun load(context: Context) {
|
||||
val p = prefs(context)
|
||||
labels = p.getBoolean("grid_labels", true)
|
||||
iconDp = p.getInt("grid_icon", MEDIUM).takeIf { it in ICON_SIZES } ?: MEDIUM
|
||||
spacing = p.getInt("grid_spacing", NORMAL).takeIf { it in SPACINGS } ?: NORMAL
|
||||
}
|
||||
|
||||
fun setLabels(context: Context, value: Boolean) {
|
||||
labels = value
|
||||
prefs(context).edit().putBoolean("grid_labels", value).apply()
|
||||
}
|
||||
|
||||
fun setIconDp(context: Context, value: Int) {
|
||||
iconDp = value
|
||||
prefs(context).edit().putInt("grid_icon", value).apply()
|
||||
}
|
||||
|
||||
fun setSpacing(context: Context, value: Int) {
|
||||
spacing = value
|
||||
prefs(context).edit().putInt("grid_spacing", value).apply()
|
||||
}
|
||||
}
|
||||
|
||||
internal interface AppEntryKey {
|
||||
val label: String
|
||||
val installedAt: Long
|
||||
@@ -237,9 +283,9 @@ internal interface AppEntryKey {
|
||||
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
internal fun AndroidAppsPage(s: FrontEndState, modifier: Modifier, onLaunch: (HomeApp.LaunchableApp) -> Unit) {
|
||||
internal fun AndroidAppsPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier, onLaunch: (HomeApp.LaunchableApp) -> Unit) {
|
||||
val ctx = LocalContext.current
|
||||
remember { HomeFolders.load(ctx); HomeWidgets.load(ctx); HomeHidden.load(ctx); AppsView.load(ctx); true }
|
||||
remember { HomeFolders.load(ctx); HomeWidgets.load(ctx); HomeHidden.load(ctx); AppsView.load(ctx); AppsGrid.load(ctx); true }
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val narrow = LocalNarrowPane.current
|
||||
val padH = if (narrow) 16.dp else 22.dp
|
||||
@@ -247,6 +293,10 @@ internal fun AndroidAppsPage(s: FrontEndState, modifier: Modifier, onLaunch: (Ho
|
||||
var openFolder by rememberSaveable { mutableStateOf<String?>(null) }
|
||||
var renameOnOpen by rememberSaveable { mutableStateOf(false) }
|
||||
var picking by rememberSaveable { mutableStateOf(false) }
|
||||
var iconFor by remember { mutableStateOf<HomeApp.LaunchableApp?>(null) }
|
||||
LaunchedEffect(Unit) {
|
||||
snapshotFlow { HomeIcons.overrides }.drop(1).collect { a.onAppIconsChanged() }
|
||||
}
|
||||
val folders = HomeFolders.folders
|
||||
val byKey = remember(s.androidApps) { s.androidApps.associateBy { it.key } }
|
||||
val byPkg = remember(s.androidApps) { s.androidApps.filterNot { it.work }.groupBy { it.packageName }.mapNotNull { (pkg, apps) -> apps.singleOrNull()?.let { pkg to it } }.toMap() }
|
||||
@@ -292,7 +342,7 @@ internal fun AndroidAppsPage(s: FrontEndState, modifier: Modifier, onLaunch: (Ho
|
||||
ModeHeader(
|
||||
stringResource(R.string.content_android_apps), query, { query = it },
|
||||
placeholder = stringResource(R.string.apps_search_hint),
|
||||
clearSearchFocus = openFolder != null || picking,
|
||||
clearSearchFocus = openFolder != null || picking || iconFor != null,
|
||||
lead = {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(start = 2.dp, end = 4.dp)) {
|
||||
Text(stringResource(R.string.content_android_apps), fontSize = if (narrow) 20.sp else 24.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1)
|
||||
@@ -303,6 +353,7 @@ internal fun AndroidAppsPage(s: FrontEndState, modifier: Modifier, onLaunch: (Ho
|
||||
) {
|
||||
AppsFilterButton()
|
||||
AppsSortButton()
|
||||
AppsAppearanceButton(a)
|
||||
HeaderIconButton(stringResource(R.string.apps_add_widget), Icons.Filled.Widgets, "add-widget") {
|
||||
HomeWidgets.loadProviders(ctx)
|
||||
picking = true
|
||||
@@ -312,7 +363,7 @@ internal fun AndroidAppsPage(s: FrontEndState, modifier: Modifier, onLaunch: (Ho
|
||||
Box(Modifier.weight(1f).fillMaxWidth()) {
|
||||
val scroller = q.isEmpty() && byName && entries.size > 16
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Adaptive(if (narrow) 84.dp else 96.dp),
|
||||
columns = GridCells.Adaptive((if (narrow) 84 else 96).dp + AppsGrid.spacing.dp),
|
||||
state = grid,
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
@@ -343,7 +394,7 @@ internal fun AndroidAppsPage(s: FrontEndState, modifier: Modifier, onLaunch: (Ho
|
||||
items(entries, key = { it.key }) { entry ->
|
||||
when (entry) {
|
||||
is AppEntry.App -> AppTile(
|
||||
entry.app, folderId = null, onLaunch = onLaunch, onNewFolder = newFolder,
|
||||
entry.app, folderId = null, onLaunch = onLaunch, onNewFolder = newFolder, onChangeIcon = { iconFor = it },
|
||||
first = entry === entries.first(),
|
||||
)
|
||||
is AppEntry.Shortcut -> PinnedTile(entry.pinned, first = entry === entries.first())
|
||||
@@ -367,7 +418,7 @@ internal fun AndroidAppsPage(s: FrontEndState, modifier: Modifier, onLaunch: (Ho
|
||||
var last by remember { mutableStateOf(folder) }
|
||||
if (folder != null) last = folder
|
||||
last?.let { f ->
|
||||
FolderSheet(f, f.apps.mapNotNull(member).filter { it.key !in hidden }.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.label }), renameOnOpen, onLaunch, newFolder) {
|
||||
FolderSheet(f, f.apps.mapNotNull(member).filter { it.key !in hidden }.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.label }), renameOnOpen, onLaunch, newFolder, { iconFor = it }) {
|
||||
openFolder = null
|
||||
renameOnOpen = false
|
||||
}
|
||||
@@ -377,11 +428,19 @@ internal fun AndroidAppsPage(s: FrontEndState, modifier: Modifier, onLaunch: (Ho
|
||||
picking, enter = fadeIn(Motion.tw(180)), exit = fadeOut(Motion.tw(160)),
|
||||
modifier = Modifier.fillMaxSize().zIndex(3f),
|
||||
) { WidgetPicker(padH) { picking = false } }
|
||||
AnimatedVisibility(
|
||||
iconFor != null, enter = fadeIn(Motion.tw(180)), exit = fadeOut(Motion.tw(160)),
|
||||
modifier = Modifier.fillMaxSize().zIndex(4f),
|
||||
) {
|
||||
var last by remember { mutableStateOf(iconFor) }
|
||||
iconFor?.let { last = it }
|
||||
last?.let { app -> AppIconPicker(app, padH) { iconFor = null } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SwipeLock() {
|
||||
internal fun SwipeLock() {
|
||||
DisposableEffect(Unit) {
|
||||
PageSwipe.locks++
|
||||
onDispose { PageSwipe.locks-- }
|
||||
@@ -568,22 +627,22 @@ private fun AppIcon(app: HomeApp.LaunchableApp, size: androidx.compose.ui.unit.D
|
||||
private fun AppTile(
|
||||
app: HomeApp.LaunchableApp, folderId: String?, first: Boolean,
|
||||
onLaunch: (HomeApp.LaunchableApp) -> Unit, onNewFolder: (HomeApp.LaunchableApp) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
onChangeIcon: (HomeApp.LaunchableApp) -> Unit, modifier: Modifier = Modifier,
|
||||
) {
|
||||
var menu by remember { mutableStateOf(false) }
|
||||
Box(modifier) {
|
||||
TileFrame(app.key, first, onClick = { onLaunch(app) }, onMenu = { menu = true }) {
|
||||
AppIcon(app, 52.dp)
|
||||
TileLabel(app.label)
|
||||
AppIcon(app, AppsGrid.iconDp.dp)
|
||||
if (AppsGrid.labels) TileLabel(app.label)
|
||||
}
|
||||
AppMenu(app, folderId, menu, onDismiss = { menu = false }, onNewFolder = onNewFolder)
|
||||
AppMenu(app, folderId, menu, onDismiss = { menu = false }, onNewFolder = onNewFolder, onChangeIcon = onChangeIcon)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AppMenu(
|
||||
app: HomeApp.LaunchableApp, folderId: String?, open: Boolean,
|
||||
onDismiss: () -> Unit, onNewFolder: (HomeApp.LaunchableApp) -> Unit,
|
||||
onDismiss: () -> Unit, onNewFolder: (HomeApp.LaunchableApp) -> Unit, onChangeIcon: (HomeApp.LaunchableApp) -> Unit,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
var choosing by remember { mutableStateOf(false) }
|
||||
@@ -636,6 +695,14 @@ private fun AppMenu(
|
||||
onDismiss()
|
||||
HomeHidden.set(ctx, app.key, !isHidden)
|
||||
}
|
||||
if (IconPack.active(ctx) != null) MenuItem(stringResource(R.string.apps_change_icon), checked = false) {
|
||||
onDismiss()
|
||||
onChangeIcon(app)
|
||||
}
|
||||
if (app.key in HomeIcons.overrides) MenuItem(stringResource(R.string.apps_reset_icon), checked = false) {
|
||||
onDismiss()
|
||||
HomeIcons.clear(ctx, app.key)
|
||||
}
|
||||
MenuItem(stringResource(R.string.apps_app_info), checked = false) {
|
||||
onDismiss()
|
||||
runCatching { HomeApp.openAppInfo(ctx, app) }
|
||||
@@ -662,10 +729,10 @@ private fun PinnedTile(pinned: HomePins.Pinned, first: Boolean) {
|
||||
TileFrame(pinned.key, first, onClick = { runCatching { HomeApp.startShortcut(ctx, pinned.info) } }, onMenu = { menu = true }) {
|
||||
Box {
|
||||
val icon = pinned.icon
|
||||
if (icon != null) Image(icon.asImageBitmap(), null, contentScale = ContentScale.Fit, modifier = Modifier.size(52.dp))
|
||||
else Box(Modifier.size(52.dp).clip(CircleShape).background(artBrush(hueOf(pinned.label))))
|
||||
if (icon != null) Image(icon.asImageBitmap(), null, contentScale = ContentScale.Fit, modifier = Modifier.size(AppsGrid.iconDp.dp))
|
||||
else Box(Modifier.size(AppsGrid.iconDp.dp).clip(CircleShape).background(artBrush(hueOf(pinned.label))))
|
||||
}
|
||||
TileLabel(pinned.label)
|
||||
if (AppsGrid.labels) TileLabel(pinned.label)
|
||||
}
|
||||
AnchoredMenu(menu, onDismiss = { menu = false }, title = pinned.label, compact = true, minWidth = 180.dp) { firstItem ->
|
||||
MenuItem(stringResource(R.string.apps_shortcut_remove), checked = false, detail = pinned.appLabel, focusRequester = firstItem) {
|
||||
@@ -700,8 +767,8 @@ private fun FolderTile(entry: AppEntry.Folder, first: Boolean, onOpen: () -> Uni
|
||||
var menu by remember { mutableStateOf(false) }
|
||||
Box {
|
||||
TileFrame(entry.key, first, onClick = onOpen, onMenu = { menu = true }) {
|
||||
FolderIcon(entry.apps, 52.dp)
|
||||
TileLabel(entry.folder.name)
|
||||
FolderIcon(entry.apps, AppsGrid.iconDp.dp)
|
||||
if (AppsGrid.labels) TileLabel(entry.folder.name)
|
||||
}
|
||||
AnchoredMenu(menu, onDismiss = { menu = false }, title = entry.folder.name, compact = true, minWidth = 160.dp) { firstItem ->
|
||||
MenuItem(stringResource(R.string.apps_folder_rename), checked = false, focusRequester = firstItem) {
|
||||
@@ -720,7 +787,8 @@ private fun FolderTile(entry: AppEntry.Folder, first: Boolean, onOpen: () -> Uni
|
||||
@Composable
|
||||
private fun FolderSheet(
|
||||
folder: HomeFolders.Folder, apps: List<HomeApp.LaunchableApp>, renameFirst: Boolean,
|
||||
onLaunch: (HomeApp.LaunchableApp) -> Unit, onNewFolder: (HomeApp.LaunchableApp) -> Unit, onClose: () -> Unit,
|
||||
onLaunch: (HomeApp.LaunchableApp) -> Unit, onNewFolder: (HomeApp.LaunchableApp) -> Unit,
|
||||
onChangeIcon: (HomeApp.LaunchableApp) -> Unit, onClose: () -> Unit,
|
||||
) {
|
||||
SwipeLock()
|
||||
val ctx = LocalContext.current
|
||||
@@ -803,14 +871,14 @@ private fun FolderSheet(
|
||||
}
|
||||
}
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Adaptive(92.dp),
|
||||
columns = GridCells.Adaptive(92.dp + AppsGrid.spacing.dp),
|
||||
state = grid,
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
items(apps, key = { it.key }) { app ->
|
||||
AppTile(
|
||||
app, folderId = folder.id, first = false, onLaunch = { onClose(); onLaunch(it) }, onNewFolder = onNewFolder,
|
||||
app, folderId = folder.id, first = false, onLaunch = { onClose(); onLaunch(it) }, onNewFolder = onNewFolder, onChangeIcon = onChangeIcon,
|
||||
modifier = if (app === apps.first()) Modifier.focusRequester(firstApp) else Modifier,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.util.LruCache
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.focusGroup
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.GridItemSpan
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.focus.FocusDirection
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusProperties
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.input.InputMode
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalInputModeManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.droiddeck.launcher.HomeApp
|
||||
import com.droiddeck.launcher.HomeIcons
|
||||
import com.droiddeck.launcher.IconPack
|
||||
import com.droiddeck.launcher.R
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
private val CELL_ICON = 44.dp
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
private fun Modifier.focusTrap(): Modifier = focusProperties {
|
||||
exit = { dir ->
|
||||
if (dir == FocusDirection.Up || dir == FocusDirection.Down || dir == FocusDirection.Left || dir == FocusDirection.Right) FocusRequester.Cancel
|
||||
else FocusRequester.Default
|
||||
}
|
||||
}.focusGroup()
|
||||
|
||||
private fun normalized(text: String) = text.lowercase().filter { it.isLetterOrDigit() }
|
||||
|
||||
internal fun iconMatches(names: List<String>, label: String, query: String): List<String> {
|
||||
val q = normalized(query)
|
||||
if (q.isNotEmpty()) return names.filter { q in normalized(it) }
|
||||
val hint = normalized(label)
|
||||
val (likely, rest) = names.partition { hint in normalized(it) }
|
||||
return likely + rest
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun AppIconPicker(app: HomeApp.LaunchableApp, padH: androidx.compose.ui.unit.Dp, onClose: () -> Unit) {
|
||||
SwipeLock()
|
||||
val ctx = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pack = remember { IconPack.selected(ctx) }
|
||||
val names by produceState<List<String>?>(null, pack) { value = withContext(Dispatchers.IO) { IconPack.names(ctx, pack) } }
|
||||
var query by remember { mutableStateOf("") }
|
||||
val shown = remember(names, query) { names?.let { iconMatches(it, app.label, query) } }
|
||||
val cache = remember { LruCache<String, Bitmap>(256) }
|
||||
val inputMode = LocalInputModeManager.current.inputMode
|
||||
val ff = LocalFrontFocus.current
|
||||
val first = remember { FocusRequester() }
|
||||
var closing by remember { mutableStateOf(false) }
|
||||
val close = {
|
||||
closing = true
|
||||
onClose()
|
||||
if (inputMode == InputMode.Keyboard && ff != null) {
|
||||
runCatching { ff.items.getValue("tile:${app.key}").requestFocus() }
|
||||
.onFailure { runCatching { ff.firstTile.requestFocus() } }
|
||||
}
|
||||
}
|
||||
LaunchedEffect(names != null, inputMode) {
|
||||
if (names != null && !closing && inputMode == InputMode.Keyboard) {
|
||||
repeat(2) { androidx.compose.runtime.withFrameNanos { } }
|
||||
ff?.last = "icon:${shown?.firstOrNull()}"
|
||||
if (!closing) runCatching { first.requestFocus() }
|
||||
}
|
||||
}
|
||||
BackHandler { close() }
|
||||
Column(
|
||||
Modifier.fillMaxSize().imePadding().background(colors.background)
|
||||
.blockTouches()
|
||||
.focusTrap(),
|
||||
) {
|
||||
val title = stringResource(R.string.touch_icon_for, app.label)
|
||||
Box(Modifier.fillMaxWidth().padding(start = padH, end = padH, top = 8.dp)) {
|
||||
ModeHeader(
|
||||
title, query, { query = it }, placeholder = stringResource(R.string.apps_icons_search),
|
||||
lead = {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
BackLink(stringResource(R.string.rail_apps), compact = true, onClick = close)
|
||||
Text(title, fontSize = 15.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
},
|
||||
inlineWhenStacked = true,
|
||||
) { }
|
||||
}
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Adaptive(64.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
contentPadding = PaddingValues(horizontal = padH, vertical = 8.dp),
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) {
|
||||
when {
|
||||
shown == null -> item(key = "loading", span = { GridItemSpan(maxLineSpan) }) { Note(stringResource(R.string.apps_icons_loading)) }
|
||||
shown.isEmpty() -> item(key = "none", span = { GridItemSpan(maxLineSpan) }) { Note(stringResource(R.string.apps_icons_none)) }
|
||||
else -> items(shown, key = { it }) { name ->
|
||||
PackIconCell(
|
||||
pack, name, cache,
|
||||
modifier = if (name == shown.first()) Modifier.focusRequester(first) else Modifier,
|
||||
) {
|
||||
HomeIcons.set(ctx, app.key, pack, name)
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PackIconCell(
|
||||
pack: String, name: String, cache: LruCache<String, Bitmap>, modifier: Modifier, onPick: () -> Unit,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
val iconPx = with(LocalDensity.current) { CELL_ICON.roundToPx() }
|
||||
val bitmap by produceState(cache.get(name), name) {
|
||||
if (value == null) value = withContext(Dispatchers.IO) {
|
||||
runCatching { IconPack.drawable(ctx, pack, name, ctx.resources.displayMetrics.densityDpi)?.toBitmap(iconPx, iconPx) }.getOrNull()?.also { cache.put(name, it) }
|
||||
}
|
||||
}
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = modifier.fillMaxWidth().paneItem("icon:$name").clip(Shape12)
|
||||
.background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent)
|
||||
.glideBorder(hot, Shape12, pal.signal)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onPick)
|
||||
.controllerConfirm(onClick = onPick)
|
||||
.semantics { contentDescription = name.replace('_', ' ') }
|
||||
.padding(10.dp),
|
||||
) {
|
||||
val icon = bitmap
|
||||
if (icon != null) Image(icon.asImageBitmap(), null, contentScale = ContentScale.Fit, modifier = Modifier.size(CELL_ICON))
|
||||
else Spacer(Modifier.size(CELL_ICON))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Palette
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.geometry.Rect
|
||||
import androidx.compose.ui.layout.boundsInRoot
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.droiddeck.launcher.HomeIcons
|
||||
import com.droiddeck.launcher.IconPack
|
||||
import com.droiddeck.launcher.R
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
private val PanelWidth = 348.dp
|
||||
private val PanelHeight = 316.dp
|
||||
private val TabsWidth = 204.dp
|
||||
|
||||
@Composable
|
||||
internal fun AppsAppearanceButton(a: FrontEndActions) {
|
||||
val pal = LocalPalette.current
|
||||
val title = stringResource(R.string.apps_appearance)
|
||||
var at by remember { mutableStateOf<Rect?>(null) }
|
||||
Box(Modifier.onGloballyPositioned { at = it.boundsInRoot() }) {
|
||||
HeaderIconButton(title, Icons.Filled.Palette, "apps-appearance") {
|
||||
val from = at ?: return@HeaderIconButton
|
||||
Steps.ask(StepAsk(
|
||||
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = 2, maxWidth = PanelWidth,
|
||||
handle = { Icon(Icons.Filled.Palette, null, tint = pal.signal, modifier = Modifier.size(18.dp)) },
|
||||
) {
|
||||
StepTitle(title)
|
||||
Column(
|
||||
Modifier.stepItem(1).fillMaxWidth().height(minOf(PanelHeight, (maxHeight - 64.dp).coerceAtLeast(44.dp))).verticalScroll(rememberScrollState()),
|
||||
) { AppearanceRows(a) }
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StepOutScope.AppearanceRows(a: FrontEndActions) {
|
||||
val ctx = LocalContext.current
|
||||
val host = rememberMenuHost()
|
||||
var packsOpen by remember { mutableStateOf(false) }
|
||||
var selected by remember { mutableStateOf(IconPack.selected(ctx)) }
|
||||
var appColors by remember { mutableStateOf(IconPack.appColors(ctx)) }
|
||||
val installed by produceState(emptyList<IconPack.Pack>()) {
|
||||
value = withContext(Dispatchers.IO) { runCatching { IconPack.installed(ctx) }.getOrDefault(emptyList()) }
|
||||
}
|
||||
val hasBack by produceState(false, selected) { value = withContext(Dispatchers.IO) { IconPack.active(ctx)?.hasBack == true } }
|
||||
CompositionLocalProvider(LocalCompactSettings provides true) {
|
||||
val packs = listOf(IconPack.Pack(IconPack.NONE, stringResource(R.string.apps_icon_pack_system))) + installed
|
||||
val current = packs.find { it.packageName == selected } ?: packs.first()
|
||||
Box(Modifier.focusRequester(first)) {
|
||||
LinkRow(
|
||||
stringResource(R.string.apps_icon_pack), current.label, "", "icon-pack",
|
||||
arrow = if (packsOpen) "▴" else "▾",
|
||||
) { packsOpen = !packsOpen }
|
||||
}
|
||||
if (packsOpen) packs.forEach { (value, text) ->
|
||||
MenuItem(text, checked = value == current.packageName) {
|
||||
selected = value
|
||||
IconPack.select(ctx, value)
|
||||
a.onAppIconsChanged()
|
||||
packsOpen = false
|
||||
runCatching { first.requestFocus() }
|
||||
}
|
||||
}
|
||||
SettingsRow(stringResource(R.string.apps_icon_size), null) {
|
||||
SegmentedTabs(
|
||||
listOf(
|
||||
AppsGrid.SMALL to stringResource(R.string.apps_icon_small),
|
||||
AppsGrid.MEDIUM to stringResource(R.string.apps_icon_medium),
|
||||
AppsGrid.LARGE to stringResource(R.string.apps_icon_large),
|
||||
),
|
||||
AppsGrid.iconDp, Modifier.width(TabsWidth),
|
||||
) { AppsGrid.setIconDp(ctx, it) }
|
||||
}
|
||||
SettingsRow(stringResource(R.string.apps_spacing), null) {
|
||||
SegmentedTabs(
|
||||
listOf(
|
||||
AppsGrid.TIGHT to stringResource(R.string.apps_spacing_tight),
|
||||
AppsGrid.NORMAL to stringResource(R.string.apps_spacing_normal),
|
||||
AppsGrid.ROOMY to stringResource(R.string.apps_spacing_roomy),
|
||||
),
|
||||
AppsGrid.spacing, Modifier.width(TabsWidth),
|
||||
) { AppsGrid.setSpacing(ctx, it) }
|
||||
}
|
||||
ToggleRow(host, "app-names", stringResource(R.string.apps_hide_names), null, !AppsGrid.labels) { AppsGrid.setLabels(ctx, !it) }
|
||||
if (hasBack) ToggleRow(host, "app-colors", stringResource(R.string.apps_icon_app_colors), null, appColors) {
|
||||
appColors = it
|
||||
IconPack.setAppColors(ctx, it)
|
||||
a.onAppIconsChanged()
|
||||
}
|
||||
if (HomeIcons.overrides.isNotEmpty()) ActionRow(stringResource(R.string.apps_icons_custom), null, stringResource(R.string.ctrl_reset), {
|
||||
HomeIcons.clearAll(ctx)
|
||||
runCatching { first.requestFocus() }
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -275,7 +275,7 @@ private fun Content(
|
||||
return
|
||||
}
|
||||
if (selected == "android-apps" && s.isHomeApp) {
|
||||
AndroidAppsPage(s, modifier, onAndroidAppClick)
|
||||
AndroidAppsPage(s, a, modifier, onAndroidAppClick)
|
||||
return
|
||||
}
|
||||
Column(modifier = modifier.verticalScroll(rememberScrollState()).padding(horizontal = padH, vertical = padV)) {
|
||||
|
||||
@@ -293,6 +293,7 @@ class FrontEndActions(
|
||||
val onLibraryChanged: () -> Unit = {},
|
||||
val onHomeApp: () -> Unit = {},
|
||||
val onHomeScreen: (Boolean) -> Unit = {},
|
||||
val onAppIconsChanged: () -> Unit = {},
|
||||
val onSteamIntegration: (com.droiddeck.launcher.core.SteamIntegration.Feature?) -> Unit = {},
|
||||
val onDismissIntegration: () -> Unit = {},
|
||||
val onIntegration: (com.droiddeck.launcher.core.SteamIntegration.Feature) -> Unit = {},
|
||||
|
||||
Reference in new issue
Block a user