Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: App list view #1170

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import de.mm20.launcher2.widgets.FavoritesWidget
import de.mm20.launcher2.widgets.WidgetRepository
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import org.koin.androidx.compose.inject

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fun SearchColumn(
) {

val columns = LocalGridSettings.current.columnCount
val showList = LocalGridSettings.current.showList
val context = LocalContext.current

val viewModel: SearchVM = viewModel()
Expand Down Expand Up @@ -193,6 +194,7 @@ fun SearchColumn(
columns = columns,
reverse = reverse,
showProfileLockControls = hasProfilesPermission,
showList = showList,
)
} else {
AppResults(
Expand All @@ -202,7 +204,8 @@ fun SearchColumn(
selectedAppProfileIndex = it
},
columns = columns,
reverse = reverse
reverse = reverse,
showList = showList,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand All @@ -22,7 +21,6 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.LeadingIconTab
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.PrimaryScrollableTabRow
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -50,8 +48,8 @@ fun LazyListScope.AppResults(
highlightedItem: Application? = null,
columns: Int,
reverse: Boolean,
showList: Boolean,
) {

GridResults(
key = "apps",
items = apps,
Expand Down Expand Up @@ -195,10 +193,12 @@ fun LazyListScope.AppResults(
GridItem(
item = it,
showLabels = LocalGridSettings.current.showLabels,
showListIcons = LocalGridSettings.current.showListIcons,
showList = showList,
highlight = it.key == highlightedItem?.key
)
},
reverse = reverse,
columns = columns,
columns = if (showList) 1 else columns,
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.mm20.launcher2.ui.launcher.search.common.grid

import android.util.Log
import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.MutableTransitionState
Expand All @@ -13,6 +12,7 @@ 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.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -86,6 +86,8 @@ fun GridItem(
modifier: Modifier = Modifier,
item: SavableSearchable,
showLabels: Boolean = true,
showList: Boolean = false,
showListIcons: Boolean = true,
labelMaxLines: Int = 1,
highlight: Boolean = false
) {
Expand All @@ -110,6 +112,7 @@ fun GridItem(

Column(
modifier = modifier
.padding(if (showList) 0.dp else 4.dp)
.combinedClickable(
onClick = {
if (!launchOnPress || !viewModel.launch(context, bounds)) {
Expand Down Expand Up @@ -154,52 +157,101 @@ fun GridItem(

val iconShape = LocalIconShape.current

Box(
modifier = if (highlight) {
Modifier
.background(
MaterialTheme.colorScheme.surfaceVariant,
iconShape
)
} else Modifier then if (showLabels) Modifier else Modifier
.semantics {
contentDescription = item.label
},
) {
ShapedLauncherIcon(
modifier = Modifier
.padding(4.dp)
.onGloballyPositioned {
bounds = it.boundsInWindow().roundToIntRect()
} then
if (highlight) Modifier.background(
MaterialTheme.colorScheme.surface,
if (!showList) {
Box(
modifier = if (highlight) {
Modifier
.background(
MaterialTheme.colorScheme.surfaceVariant,
iconShape
)
else Modifier,
size = LocalGridSettings.current.iconSize.dp,
badge = { badge },
icon = { icon },
)
}
if (showLabels) {
Text(
} else Modifier then if (showLabels) Modifier else Modifier
.semantics {
contentDescription = item.label
},
) {
ShapedLauncherIcon(
modifier = Modifier
.padding(4.dp)
.onGloballyPositioned {
bounds = it
.boundsInWindow()
.roundToIntRect()
} then
if (highlight) Modifier.background(
MaterialTheme.colorScheme.surface,
iconShape
)
else Modifier,
size = LocalGridSettings.current.iconSize.dp,
badge = { badge },
icon = { icon },
)
}
if (showLabels) {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
text = item.labelOverride ?: item.label,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodySmall,
maxLines = labelMaxLines,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colorScheme.onBackground,
)
}
} else {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
text = item.labelOverride ?: item.label,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodySmall,
maxLines = labelMaxLines,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colorScheme.onBackground,
)
}
.padding(start = 8.dp, end = 8.dp, bottom = 4.dp)
.semantics { contentDescription = item.label }
.onGloballyPositioned {
bounds = it
.boundsInWindow()
.roundToIntRect()
} then if (highlight) {
Modifier
.background(
MaterialTheme.colorScheme.surfaceVariant,
MaterialTheme.shapes.small
)
} else Modifier
) {
if (showListIcons) {
ShapedLauncherIcon(
modifier = Modifier
.padding(8.dp)
.onGloballyPositioned {
bounds = it
.boundsInWindow()
.roundToIntRect()
},
size = LocalGridSettings.current.iconSize.dp - 2.dp,
badge = { badge },
icon = { icon },
)
}

if (showPopup) {
ItemPopup(origin = bounds, searchable = item, onDismissRequest = { showPopup = false })
Text(
modifier = Modifier
.padding(vertical = 4.dp, horizontal = 6.dp)
.fillMaxWidth(),
text = item.labelOverride ?: item.label,
textAlign = TextAlign.Start,
style = MaterialTheme.typography.headlineLarge,
maxLines = labelMaxLines,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colorScheme.onBackground,
)
}
}
}

if (showPopup) {
ItemPopup(origin = bounds, searchable = item, onDismissRequest = { showPopup = false })
}
}

@Composable
Expand Down Expand Up @@ -398,7 +450,7 @@ private fun Modifier.placeOverlay(
constraints.maxHeight - placeable.height,
),
animationProgress.pow(2)
).toInt()
)
)
}
}
Expand All @@ -410,4 +462,4 @@ private fun lerp(start: Float, stop: Float, fraction: Float): Float {

private fun lerp(start: Int, stop: Int, fraction: Float): Int {
return start + (fraction * (stop - start)).toInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ fun <T : SavableSearchable> LazyListScope.GridResults(
.padding(
top = if (it == 0) 8.dp else 0.dp,
bottom = if (it == rows - 1) 8.dp else 0.dp,
start = 4.dp,
end = 4.dp,
start = if (columns == 1) 0.dp else 4.dp,
end = if (columns == 1) 0.dp else 4.dp,
)
) {
Row {
Expand All @@ -94,7 +94,6 @@ fun <T : SavableSearchable> LazyListScope.GridResults(
Box(
modifier = Modifier
.weight(1f)
.padding(4.dp)
) {
itemContent(item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ fun SearchResultGrid(
items: List<SavableSearchable>,
modifier: Modifier = Modifier,
showLabels: Boolean = LocalGridSettings.current.showLabels,
showList: Boolean = LocalGridSettings.current.showList,
showListIcons: Boolean = LocalGridSettings.current.showListIcons,
columns: Int = LocalGridSettings.current.columnCount,
reverse: Boolean = false,
highlightedItem: SavableSearchable? = null,
Expand Down Expand Up @@ -53,7 +55,9 @@ fun SearchResultGrid(
.weight(1f)
.padding(4.dp),
item = item,
showList = showList,
showLabels = showLabels,
showListIcons = showListIcons,
highlight = item.key == highlightedItem?.key
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun LazyListScope.SearchFavorites(
verticalArrangement = if (reverse) Arrangement.BottomReversed else Arrangement.Top
) {
if (favorites.isNotEmpty()) {
SearchResultGrid(favorites, transitionKey = selectedTag, reverse = reverse)
SearchResultGrid(favorites, transitionKey = selectedTag, reverse = reverse, showList = false)
} else {
Banner(
modifier = Modifier.padding(16.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class FavoritesPartProvider : PartProvider, KoinComponent {
showLabels = false,
columns = columns.coerceAtMost(favorites.size),
transitionKey = null,
showList = false,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.graphics.drawable.ColorDrawable
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -17,9 +16,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.FormatPaint
import androidx.compose.material.icons.rounded.Palette
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -116,6 +113,22 @@ fun IconsSettingsScreen() {
viewModel.setShowLabels(it)
}
)
SwitchPreference(
title = stringResource(R.string.preference_grid_list_style),
summary = stringResource(R.string.preference_grid_list_style_summary),
value = grid.showList,
onValueChanged = {
viewModel.setShowList(it)
}
)
SwitchPreference(
title = stringResource(R.string.preference_grid_list_icons),
summary = stringResource(R.string.preference_grid_list_icons_summary),
value = grid.showListIcons,
onValueChanged = {
viewModel.setShowListIcons(it)
}
)
SliderPreference(
title = stringResource(R.string.preference_grid_column_count),
value = grid.columnCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class IconsSettingsScreenVM(
uiSettings.setGridShowLabels(showLabels)
}

fun setShowList(showList: Boolean) {
uiSettings.setGridShowList(showList)
}

fun setShowListIcons(showIcons: Boolean) {
uiSettings.setGridShowListIcons(showIcons)
}

val iconShape = uiSettings.iconShape
fun setIconShape(iconShape: IconShape) {
uiSettings.setIconShape(iconShape)
Expand Down
6 changes: 5 additions & 1 deletion core/i18n/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,12 @@
<string name="preference_category_grid">Grid</string>
<string name="preference_grid_icon_size">Icon size</string>
<string name="preference_grid_column_count">Number of columns</string>
<string name="preference_grid_list_style">Show app results in a list</string>
<string name="preference_grid_list_icons">Show app icons in list</string>
<string name="preference_grid_labels">Show labels</string>
<string name="preference_grid_labels_summary">Show the app name below the icon</string>
<string name="preference_grid_list_style_summary">Show applications in a list view instead of grid</string>
<string name="preference_grid_list_icons_summary">Show icons in the list view</string>
<string name="preference_screen_debug">Debug</string>
<string name="preference_screen_debug_summary">Troubleshooting tools</string>
<string name="preference_category_widgets">Widgets</string>
Expand Down Expand Up @@ -1005,4 +1009,4 @@
<item quantity="other">%1$s lists selected</item>
</plurals>
<string name="reset_icon">Reset icon</string>
</resources>
</resources>
Loading