mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +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
@@ -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