Make grid icon size customizable

This commit is contained in:
MM20 2022-04-09 16:58:21 +02:00
parent df9760ddd1
commit 0711d02dbf
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
14 changed files with 73 additions and 9 deletions

View File

@ -470,6 +470,7 @@
<string name="preference_about_license">This app is free software.</string> <string name="preference_about_license">This app is free software.</string>
<string name="preference_about_license_summary">Licensed under the GNU General Public License 3.0</string> <string name="preference_about_license_summary">Licensed under the GNU General Public License 3.0</string>
<string name="preference_category_grid">Grid</string> <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_column_count">Number of columns</string>
<string name="preference_screen_debug">Debug</string> <string name="preference_screen_debug">Debug</string>
<string name="preference_screen_debug_summary">Troubleshooting tools</string> <string name="preference_screen_debug_summary">Troubleshooting tools</string>

View File

@ -6,10 +6,7 @@ import androidx.datastore.core.DataStore
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
import androidx.datastore.dataStore import androidx.datastore.dataStore
import de.mm20.launcher2.crashreporter.CrashReporter import de.mm20.launcher2.crashreporter.CrashReporter
import de.mm20.launcher2.preferences.migrations.FactorySettingsMigration import de.mm20.launcher2.preferences.migrations.*
import de.mm20.launcher2.preferences.migrations.Migration_1_2
import de.mm20.launcher2.preferences.migrations.Migration_2_3
import de.mm20.launcher2.preferences.migrations.Migration_3_4
typealias LauncherDataStore = DataStore<Settings> typealias LauncherDataStore = DataStore<Settings>
@ -22,6 +19,7 @@ internal val Context.dataStore: LauncherDataStore by dataStore(
Migration_1_2(), Migration_1_2(),
Migration_2_3(), Migration_2_3(),
Migration_3_4(), Migration_3_4(),
Migration_4_5(),
) )
}, },
corruptionHandler = ReplaceFileCorruptionHandler { corruptionHandler = ReplaceFileCorruptionHandler {
@ -31,4 +29,4 @@ internal val Context.dataStore: LauncherDataStore by dataStore(
} }
) )
internal const val SchemaVersion = 4 internal const val SchemaVersion = 5

View File

@ -109,6 +109,7 @@ fun createFactorySettings(context: Context): Settings {
.setGrid( .setGrid(
Settings.GridSettings.newBuilder() Settings.GridSettings.newBuilder()
.setColumnCount(context.resources.getInteger(R.integer.config_columnCount)) .setColumnCount(context.resources.getInteger(R.integer.config_columnCount))
.setIconSize(48)
.build() .build()
) )
.setSearchBar( .setSearchBar(

View File

@ -0,0 +1,13 @@
package de.mm20.launcher2.preferences.migrations
import de.mm20.launcher2.preferences.Settings
class Migration_4_5: VersionedMigration(4, 5) {
override suspend fun applyMigrations(builder: Settings.Builder): Settings.Builder {
return builder.setGrid(
builder.grid.toBuilder()
.setIconSize(48)
.build()
)
}
}

View File

@ -127,6 +127,7 @@ message Settings {
message GridSettings { message GridSettings {
uint32 column_count = 1; uint32 column_count = 1;
uint32 icon_size = 2;
} }
GridSettings grid = 19; GridSettings grid = 19;

View File

@ -1,12 +1,14 @@
package de.mm20.launcher2.ui.base package de.mm20.launcher2.ui.base
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.unit.dp
import de.mm20.launcher2.preferences.LauncherDataStore import de.mm20.launcher2.preferences.LauncherDataStore
import de.mm20.launcher2.preferences.Settings import de.mm20.launcher2.preferences.Settings
import de.mm20.launcher2.ui.component.ProvideIconShape import de.mm20.launcher2.ui.component.ProvideIconShape
import de.mm20.launcher2.ui.locals.LocalCardStyle import de.mm20.launcher2.ui.locals.LocalCardStyle
import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled
import de.mm20.launcher2.ui.locals.LocalGridColumns import de.mm20.launcher2.ui.locals.LocalGridColumns
import de.mm20.launcher2.ui.locals.LocalGridIconSize
import de.mm20.launcher2.widgets.WidgetRepository import de.mm20.launcher2.widgets.WidgetRepository
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
@ -44,10 +46,15 @@ fun ProvideSettings(
dataStore.data.map { it.grid.columnCount }.distinctUntilChanged() dataStore.data.map { it.grid.columnCount }.distinctUntilChanged()
}.collectAsState(5) }.collectAsState(5)
val gridIconSize by remember {
dataStore.data.map { it.grid.iconSize.dp }.distinctUntilChanged()
}.collectAsState(48.dp)
CompositionLocalProvider( CompositionLocalProvider(
LocalCardStyle provides cardStyle, LocalCardStyle provides cardStyle,
LocalFavoritesEnabled provides favoritesEnabled, LocalFavoritesEnabled provides favoritesEnabled,
LocalGridColumns provides gridColumns, LocalGridColumns provides gridColumns,
LocalGridIconSize provides gridIconSize,
) { ) {
ProvideIconShape(iconShape) { ProvideIconShape(iconShape) {
content() content()

View File

@ -26,6 +26,7 @@ import de.mm20.launcher2.ui.component.*
import de.mm20.launcher2.ui.ktx.toDp import de.mm20.launcher2.ui.ktx.toDp
import de.mm20.launcher2.ui.ktx.toPixels import de.mm20.launcher2.ui.ktx.toPixels
import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled
import de.mm20.launcher2.ui.locals.LocalGridIconSize
import de.mm20.launcher2.ui.modifier.scale import de.mm20.launcher2.ui.modifier.scale
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlin.math.min import kotlin.math.min
@ -321,7 +322,7 @@ fun AppItemGridPopup(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.scale( .scale(
1 - (1 - 48.dp / 84.dp) * (1 - animationProgress), 1 - (1 - LocalGridIconSize.current / 84.dp) * (1 - animationProgress),
transformOrigin = TransformOrigin(1f, 0f) transformOrigin = TransformOrigin(1f, 0f)
) )
.offset( .offset(

View File

@ -35,8 +35,10 @@ import de.mm20.launcher2.ui.launcher.search.files.FileItemGridPopup
import de.mm20.launcher2.ui.launcher.search.shortcut.ShortcutItemGridPopup import de.mm20.launcher2.ui.launcher.search.shortcut.ShortcutItemGridPopup
import de.mm20.launcher2.ui.launcher.search.website.WebsiteItemGridPopup import de.mm20.launcher2.ui.launcher.search.website.WebsiteItemGridPopup
import de.mm20.launcher2.ui.launcher.search.wikipedia.WikipediaItemGridPopup import de.mm20.launcher2.ui.launcher.search.wikipedia.WikipediaItemGridPopup
import de.mm20.launcher2.ui.locals.LocalGridIconSize
import de.mm20.launcher2.ui.locals.LocalWindowPosition import de.mm20.launcher2.ui.locals.LocalWindowPosition
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlin.math.pow
@OptIn(ExperimentalFoundationApi::class) @OptIn(ExperimentalFoundationApi::class)
@ -49,7 +51,7 @@ fun GridItem(modifier: Modifier = Modifier, item: Searchable, showLabels: Boolea
var bounds by remember { mutableStateOf(Rect.Zero) } var bounds by remember { mutableStateOf(Rect.Zero) }
Column(modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally) { Column(modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally) {
val badge by viewModel.badge.collectAsState(null) val badge by viewModel.badge.collectAsState(null)
val iconSize = 48.dp.toPixels() val iconSize = LocalGridIconSize.current.toPixels()
val icon by remember(item.key) { viewModel.getIcon(iconSize.toInt()) }.collectAsState(null) val icon by remember(item.key) { viewModel.getIcon(iconSize.toInt()) }.collectAsState(null)
// If item is one of these types, try to launch them on click; show details otherwise // If item is one of these types, try to launch them on click; show details otherwise
@ -61,7 +63,7 @@ fun GridItem(modifier: Modifier = Modifier, item: Searchable, showLabels: Boolea
.onGloballyPositioned { .onGloballyPositioned {
bounds = it.boundsInWindow() bounds = it.boundsInWindow()
}, },
size = 48.dp, size = LocalGridIconSize.current,
badge = badge, badge = badge,
icon = icon, icon = icon,
onClick = { onClick = {

View File

@ -20,6 +20,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Rect import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
@ -34,6 +35,8 @@ import de.mm20.launcher2.ui.icons.WhatsApp
import de.mm20.launcher2.ui.ktx.toDp import de.mm20.launcher2.ui.ktx.toDp
import de.mm20.launcher2.ui.ktx.toPixels import de.mm20.launcher2.ui.ktx.toPixels
import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled
import de.mm20.launcher2.ui.locals.LocalGridIconSize
import de.mm20.launcher2.ui.modifier.scale
@OptIn(ExperimentalUnitApi::class) @OptIn(ExperimentalUnitApi::class)
@Composable @Composable
@ -306,6 +309,10 @@ fun ContactItemGridPopup(
ContactItem( ContactItem(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.scale(
1 - (1 - LocalGridIconSize.current / 48.dp) * (1 - animationProgress),
transformOrigin = TransformOrigin(0f, 0f)
)
.offset( .offset(
x = -16.dp * (1 - animationProgress), x = -16.dp * (1 - animationProgress),
y = -16.dp * (1 - animationProgress) y = -16.dp * (1 - animationProgress)

View File

@ -16,6 +16,7 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Rect import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
@ -31,6 +32,8 @@ import de.mm20.launcher2.ui.component.ToolbarAction
import de.mm20.launcher2.ui.ktx.toDp import de.mm20.launcher2.ui.ktx.toDp
import de.mm20.launcher2.ui.ktx.toPixels import de.mm20.launcher2.ui.ktx.toPixels
import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled
import de.mm20.launcher2.ui.locals.LocalGridIconSize
import de.mm20.launcher2.ui.modifier.scale
import java.text.DecimalFormat import java.text.DecimalFormat
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -279,6 +282,10 @@ fun FileItemGridPopup(
FileItem( FileItem(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.scale(
1 - (1 - LocalGridIconSize.current / 48.dp) * (1 - animationProgress),
transformOrigin = TransformOrigin(1f, 0f)
)
.offset( .offset(
x = 16.dp * (1 - animationProgress), x = 16.dp * (1 - animationProgress),
y = -16.dp * (1 - animationProgress) y = -16.dp * (1 - animationProgress)

View File

@ -30,6 +30,7 @@ import de.mm20.launcher2.ui.component.ToolbarAction
import de.mm20.launcher2.ui.ktx.toDp import de.mm20.launcher2.ui.ktx.toDp
import de.mm20.launcher2.ui.ktx.toPixels import de.mm20.launcher2.ui.ktx.toPixels
import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled import de.mm20.launcher2.ui.locals.LocalFavoritesEnabled
import de.mm20.launcher2.ui.locals.LocalGridIconSize
import de.mm20.launcher2.ui.modifier.scale import de.mm20.launcher2.ui.modifier.scale
import kotlin.math.pow import kotlin.math.pow
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -189,7 +190,7 @@ fun ShortcutItemGridPopup(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.scale( .scale(
1 - (1 - 48.dp / 84.dp) * (1 - animationProgress), 1 - (1 - LocalGridIconSize.current / 84.dp) * (1 - animationProgress),
transformOrigin = TransformOrigin(1f, 0f) transformOrigin = TransformOrigin(1f, 0f)
) )
.offset( .offset(

View File

@ -4,6 +4,7 @@ import android.appwidget.AppWidgetHost
import androidx.compose.runtime.compositionLocalOf import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.geometry.Size import androidx.compose.ui.geometry.Size
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController import androidx.navigation.NavController
import de.mm20.launcher2.preferences.Settings import de.mm20.launcher2.preferences.Settings
@ -19,6 +20,8 @@ val LocalFavoritesEnabled = compositionLocalOf { true }
val LocalGridColumns = compositionLocalOf { 5 } val LocalGridColumns = compositionLocalOf { 5 }
val LocalGridIconSize = compositionLocalOf { 48.dp }
/** /**
* Workaround a bug in Jetpack Compose which incorrectly places popups * Workaround a bug in Jetpack Compose which incorrectly places popups
* that are nested inside other popups. * that are nested inside other popups.

View File

@ -85,6 +85,17 @@ fun AppearanceSettingsScreen() {
) )
} }
PreferenceCategory(title = stringResource(R.string.preference_category_grid)) { PreferenceCategory(title = stringResource(R.string.preference_category_grid)) {
val iconSize by viewModel.iconSize.observeAsState(48)
SliderPreference(
title = stringResource(R.string.preference_grid_icon_size),
value = iconSize,
step = 8,
min = 32,
max = 64,
onValueChanged = {
viewModel.setIconSize(it)
}
)
val columnCount by viewModel.columnCount.observeAsState(5) val columnCount by viewModel.columnCount.observeAsState(5)
SliderPreference( SliderPreference(
title = stringResource(R.string.preference_grid_column_count), title = stringResource(R.string.preference_grid_column_count),

View File

@ -54,6 +54,17 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
} }
} }
val iconSize = dataStore.data.map { it.grid.iconSize }.asLiveData()
fun setIconSize(iconSize: Int) {
viewModelScope.launch {
dataStore.updateData {
it.toBuilder()
.setGrid(it.grid.toBuilder().setIconSize(iconSize))
.build()
}
}
}
val dimWallpaper = dataStore.data.map { it.appearance.dimWallpaper }.asLiveData() val dimWallpaper = dataStore.data.map { it.appearance.dimWallpaper }.asLiveData()
fun setDimWallpaper(dimWallpaper: Boolean) { fun setDimWallpaper(dimWallpaper: Boolean) {
viewModelScope.launch { viewModelScope.launch {