From c21813a8b5fa58412e88b5ece494598840e9ce71 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Fri, 28 Apr 2023 20:08:35 +0600 Subject: [PATCH] Add an icon to "Item Per Row" on library sheet (#9414) Also cleanup `SettingsItems.kt` --- .../library/LibrarySettingsDialog.kt | 7 +- .../core/components/SettingsItems.kt | 102 ++++++++++-------- 2 files changed, 61 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt b/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt index 8848180af..94399faf0 100644 --- a/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt @@ -5,6 +5,8 @@ import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Apps import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -25,9 +27,9 @@ import tachiyomi.domain.library.model.display import tachiyomi.domain.library.model.sort import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.manga.model.TriStateFilter -import tachiyomi.presentation.core.components.BasicItem import tachiyomi.presentation.core.components.CheckboxItem import tachiyomi.presentation.core.components.HeadingItem +import tachiyomi.presentation.core.components.IconItem import tachiyomi.presentation.core.components.RadioItem import tachiyomi.presentation.core.components.SortItem @@ -206,8 +208,9 @@ private fun ColumnScope.DisplayPage( } if (category.display != LibraryDisplayMode.List) { - BasicItem( + IconItem( label = stringResource(R.string.pref_library_columns), + icon = Icons.Outlined.Apps, onClick = { showColumnsDialog = true }, ) } diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt index e4c05afea..00040026b 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt @@ -4,6 +4,7 @@ import androidx.annotation.StringRes import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -20,6 +21,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import tachiyomi.presentation.core.theme.header @@ -50,13 +52,20 @@ fun HeadingItem( } @Composable -fun BasicItem( +fun IconItem( label: String, + icon: ImageVector, onClick: () -> Unit, ) { - SortItem( + BaseSettingsItem( label = label, - sortDescending = null, + widget = { + Icon( + imageVector = icon, + contentDescription = null, + tint = MaterialTheme.colorScheme.primary, + ) + }, onClick = onClick, ) } @@ -73,28 +82,21 @@ fun SortItem( null -> null } - Row( - modifier = Modifier - .clickable(onClick = onClick) - .fillMaxWidth() - .padding(horizontal = SettingsItemsPaddings.Horizontal, vertical = SettingsItemsPaddings.Vertical), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(24.dp), - ) { - if (arrowIcon != null) { - Icon( - imageVector = arrowIcon, - contentDescription = null, - tint = MaterialTheme.colorScheme.primary, - ) - } else { - Spacer(modifier = Modifier.size(24.dp)) - } - Text( - text = label, - style = MaterialTheme.typography.bodyMedium, - ) - } + BaseSettingsItem( + label = label, + widget = { + if (arrowIcon != null) { + Icon( + imageVector = arrowIcon, + contentDescription = null, + tint = MaterialTheme.colorScheme.primary, + ) + } else { + Spacer(modifier = Modifier.size(24.dp)) + } + }, + onClick = onClick, + ) } @Composable @@ -103,23 +105,16 @@ fun CheckboxItem( checked: Boolean, onClick: () -> Unit, ) { - Row( - modifier = Modifier - .clickable(onClick = onClick) - .fillMaxWidth() - .padding(horizontal = SettingsItemsPaddings.Horizontal, vertical = SettingsItemsPaddings.Vertical), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(24.dp), - ) { - Checkbox( - checked = checked, - onCheckedChange = null, - ) - Text( - text = label, - style = MaterialTheme.typography.bodyMedium, - ) - } + BaseSettingsItem( + label = label, + widget = { + Checkbox( + checked = checked, + onCheckedChange = null, + ) + }, + onClick = onClick, + ) } @Composable @@ -127,6 +122,24 @@ fun RadioItem( label: String, selected: Boolean, onClick: () -> Unit, +) { + BaseSettingsItem( + label = label, + widget = { + RadioButton( + selected = selected, + onClick = null, + ) + }, + onClick = onClick, + ) +} + +@Composable +private fun BaseSettingsItem( + label: String, + widget: @Composable RowScope.() -> Unit, + onClick: () -> Unit, ) { Row( modifier = Modifier @@ -136,10 +149,7 @@ fun RadioItem( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(24.dp), ) { - RadioButton( - selected = selected, - onClick = null, - ) + widget(this) Text( text = label, style = MaterialTheme.typography.bodyMedium,