Modern Apps git

← Modern-Apps.git

launcher: optional list layout for the app drawer (#644)

Commit
174c7a8460cdd90c499849870dfb6d6c55c9289c
Author
vayun-mathur <[email protected]>
When
2026-09-07 00:59 UTC (3 months ago)
Parents
aa47900

Diff

launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.kt b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.ktindex f8cfc79341..511c602eea 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.kt@@ -208,6 +208,11 @@ data class DrawerUiState(     val loading: Boolean = false,     val showLabels: Boolean = true,     val iconScale: Float = 1f,+    /**+     * Draw the drawer as one app per row — icon, then name beside it — rather than as a grid of+     * tiles. Bigger targets and left-aligned names, which is what makes the list easier to read.+     */+    val listLayout: Boolean = false,     /**      * Whether the work profile is paused, or null when this build cannot pause it.      *@@ -339,6 +344,7 @@ data class SettingsUiState(     val hotseatSlots: Int = DefaultGrid.hotseatSlots,     val showLabels: Boolean = true,     val iconScale: Float = 1f,+    val drawerListLayout: Boolean = false,     val isDefaultHome: Boolean = false, ) @@ -348,6 +354,9 @@ interface SettingsActions {     fun setHotseatSlots(slots: Int) {}     fun setShowLabels(show: Boolean) {}     fun setIconScale(scale: Float) {}++    /** Switches the app drawer between the tile grid and one app per row. */+    fun setDrawerListLayout(list: Boolean) {}     fun pickWallpaper() {}     fun requestDefaultHome() {} 
launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.kt b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.ktindex dde9d421f6..2ef12dafb2 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.kt@@ -183,6 +183,7 @@ class LauncherViewModel(app: Application) : AndroidViewModel(app),         val hotseat = ds.getLong(KEY_HOTSEAT)?.toInt() ?: DefaultGrid.hotseatSlots         val showLabels = ds.getBoolean(KEY_SHOW_LABELS, true)         val iconScale = (ds.getDouble(KEY_ICON_SCALE) ?: 1.0).toFloat()+        val drawerListLayout = ds.getBoolean(KEY_DRAWER_LIST_LAYOUT, false)          _settings.value = SettingsUiState(             columns = columns,@@ -190,13 +191,18 @@ class LauncherViewModel(app: Application) : AndroidViewModel(app),             hotseatSlots = hotseat,             showLabels = showLabels,             iconScale = iconScale,+            drawerListLayout = drawerListLayout,         )         _home.value = _home.value.copy(             grid = GridSpec(columns, rows, hotseat),             showLabels = showLabels,             iconScale = iconScale,         )-        _drawer.value = _drawer.value.copy(showLabels = showLabels, iconScale = iconScale)+        _drawer.value = _drawer.value.copy(+            showLabels = showLabels,+            iconScale = iconScale,+            listLayout = drawerListLayout,+        )     }      private fun observeWorkspace() {@@ -877,6 +883,12 @@ class LauncherViewModel(app: Application) : AndroidViewModel(app),         viewModelScope.launch { ds.setDouble(KEY_ICON_SCALE, clamped.toDouble()) }     } +    override fun setDrawerListLayout(list: Boolean) {+        _settings.value = _settings.value.copy(drawerListLayout = list)+        _drawer.value = _drawer.value.copy(listLayout = list)+        viewModelScope.launch { ds.setBoolean(KEY_DRAWER_LIST_LAYOUT, list) }+    }+     override fun pickWallpaper() {         bridge?.pickWallpaper()     }@@ -935,6 +947,7 @@ class LauncherViewModel(app: Application) : AndroidViewModel(app),         private const val KEY_HOTSEAT = "launcher_hotseat_slots"         private const val KEY_SHOW_LABELS = "launcher_show_labels"         private const val KEY_ICON_SCALE = "launcher_icon_scale"+        private const val KEY_DRAWER_LIST_LAYOUT = "launcher_drawer_list_layout"         private const val KEY_LAUNCH_COUNTS = "launcher_launch_counts"          /** A single row of the drawer's grid, which is all a predictions row should ever be. */
launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerContent.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerContent.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerContent.ktindex 5140fe67a0..858289fee9 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerContent.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerContent.kt@@ -40,6 +40,7 @@ import androidx.compose.ui.geometry.Rect import androidx.compose.ui.geometry.Size import androidx.compose.ui.layout.layout import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import com.vayunmathur.launcher.domain.CellRect@@ -51,6 +52,7 @@ import com.vayunmathur.launcher.platform.DrawerUiState import com.vayunmathur.launcher.ui.components.DragPayload import com.vayunmathur.launcher.ui.components.FastScrollStrip import com.vayunmathur.launcher.ui.components.LauncherAppIcon+import com.vayunmathur.launcher.ui.components.LauncherIconSize import com.vayunmathur.launcher.ui.components.dragSource import com.vayunmathur.launcher.ui.components.onAppWindowBounds import com.vayunmathur.library.ui.Badge@@ -198,7 +200,12 @@ fun DrawerContent(              Box(modifier = Modifier.fillMaxSize()) {                 LazyVerticalGrid(-                    columns = GridCells.Adaptive(DRAWER_CELL_MIN),+                    // One column is what makes this a list: the same lazy grid, the same hoisted+                    // state, so the swipe-to-close gesture and the fast scroller carry over+                    // untouched rather than needing a second code path for a LazyColumn.+                    columns =+                        if (state.listLayout) GridCells.Fixed(1)+                        else GridCells.Adaptive(DRAWER_CELL_MIN),                     state = gridState,                     contentPadding = PaddingValues(Spacing.sm),                     modifier = Modifier.fillMaxSize(),@@ -209,6 +216,7 @@ fun DrawerContent(                             state = state,                             actions = actions,                             draggable = draggable,+                            listLayout = state.listLayout,                         )                     }                 }@@ -274,6 +282,7 @@ private fun DrawerCell(     draggable: Boolean,     modifier: Modifier = Modifier,     keyPrefix: String = "drawer",+    listLayout: Boolean = false, ) {     var bounds by remember { mutableStateOf(Rect.Zero) }     val icon = @Composable {@@ -281,9 +290,21 @@ private fun DrawerCell(             key = app.key,             label = app.label,             scale = state.iconScale,-            showLabel = state.showLabels,+            // A row whose name sits beside the icon would otherwise carry it twice. The name is+            // always drawn in list mode: an unlabelled list of icons is just a narrow grid.+            showLabel = state.showLabels && !listLayout,         )     }+    val badgedIcon = @Composable {+        if (app.isWorkProfile) {+            // The badge the system draws on a work icon is part of the icon bitmap, which the+            // drawer's own list cannot rely on when an icon fails to rasterise - so the profile is+            // marked here too, where it cannot be lost.+            BadgedBox(badge = { Badge() }) { icon() }+        } else {+            icon()+        }+    }      Box(         modifier = modifier@@ -315,13 +336,23 @@ private fun DrawerCell(             }             .padding(vertical = Spacing.sm),     ) {-        if (app.isWorkProfile) {-            // The badge the system draws on a work icon is part of the icon bitmap, which the-            // drawer's own list cannot rely on when an icon fails to rasterise - so the profile is-            // marked here too, where it cannot be lost.-            BadgedBox(badge = { Badge() }) { icon() }+        if (listLayout) {+            Row(+                modifier = Modifier.fillMaxWidth().padding(horizontal = Spacing.md),+                verticalAlignment = Alignment.CenterVertically,+            ) {+                Box(Modifier.width(LauncherIconSize * state.iconScale)) { badgedIcon() }+                Text(+                    app.label,+                    style = MaterialTheme.typography.bodyLarge,+                    color = MaterialTheme.colorScheme.onSurface,+                    maxLines = 1,+                    overflow = TextOverflow.Ellipsis,+                    modifier = Modifier.padding(start = Spacing.lg),+                )+            }         } else {-            icon()+            badgedIcon()         }     } }
launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.ktindex 562979fdfe..09c054ca5c 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.kt@@ -8,6 +8,8 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import com.vayunmathur.launcher.R import com.vayunmathur.launcher.platform.LauncherViewModel import com.vayunmathur.launcher.platform.SettingsActions import com.vayunmathur.launcher.platform.SettingsUiState@@ -15,6 +17,7 @@ import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.IconApps import com.vayunmathur.library.ui.IconGrid import com.vayunmathur.library.ui.IconHome+import com.vayunmathur.library.ui.IconList import com.vayunmathur.library.ui.IconWallpaper import com.vayunmathur.library.ui.IconWidgets import com.vayunmathur.library.ui.SettingsDivider@@ -120,6 +123,18 @@ fun SettingsContent(                         .padding(horizontal = Spacing.lg, vertical = Spacing.xs),                 )             }++            SettingsDivider()++            SettingsSection(title = stringResource(R.string.settings_app_drawer)) {+                SettingsSwitchRow(+                    title = stringResource(R.string.settings_drawer_list_title),+                    supportingText = stringResource(R.string.settings_drawer_list_summary),+                    checked = state.drawerListLayout,+                    onCheckedChange = actions::setDrawerListLayout,+                    leadingContent = { IconList() },+                )+            }         }     } }
launcher/src/main/res/values/strings.xml
diff --git a/launcher/src/main/res/values/strings.xml b/launcher/src/main/res/values/strings.xmlindex 78fbe65af5..2978e88fc8 100644--- a/launcher/src/main/res/values/strings.xml+++ b/launcher/src/main/res/values/strings.xml@@ -1,4 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <resources>     <string name="app_name">Launcher</string>+    <!-- Settings screen, section heading above the app drawer options. -->+    <string name="settings_app_drawer">App drawer</string>+    <!-- Settings screen, app drawer section, switch title. -->+    <string name="settings_drawer_list_title">List layout</string>+    <!-- Settings screen, app drawer section, text under the "List layout" switch. -->+    <string name="settings_drawer_list_summary">One app per row with its name beside the icon, instead of a grid of tiles</string> </resources>