From 34f7caa0fc4a0d9b4fcc4dfd69dc9cb52f11bf38 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 16 Jul 2023 09:11:49 -0400 Subject: [PATCH] Use Material3 chips --- .../library/LibrarySettingsDialog.kt | 8 +-- .../manga/components/MangaInfoHeader.kt | 6 -- .../reader/settings/ColorFilterPage.kt | 8 +-- .../reader/settings/GeneralSettingsPage.kt | 8 +-- .../core/components/SettingsItems.kt | 2 +- .../core/components/material/Chip.kt | 60 ------------------- 6 files changed, 13 insertions(+), 79 deletions(-) delete mode 100644 presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Chip.kt 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 1db4c0f183..4236d21dc6 100644 --- a/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt @@ -6,6 +6,7 @@ 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.material3.FilterChip import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -30,7 +31,6 @@ import tachiyomi.presentation.core.components.SettingsFlowRow import tachiyomi.presentation.core.components.SliderItem import tachiyomi.presentation.core.components.SortItem import tachiyomi.presentation.core.components.TriStateItem -import tachiyomi.presentation.core.components.material.ChoiceChip @Composable fun LibrarySettingsDialog( @@ -183,10 +183,10 @@ private fun ColumnScope.DisplayPage( val displayMode by screenModel.libraryPreferences.libraryDisplayMode().collectAsState() SettingsFlowRow(R.string.action_display_mode) { displayModes.map { (titleRes, mode) -> - ChoiceChip( - isSelected = displayMode == mode, + FilterChip( + selected = displayMode == mode, onClick = { screenModel.setDisplayMode(mode) }, - content = { Text(stringResource(titleRes)) }, + label = { Text(stringResource(titleRes)) }, ) } } diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt index 887019e327..a66861a227 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt @@ -43,7 +43,6 @@ import androidx.compose.material3.LocalMinimumInteractiveComponentEnforcement import androidx.compose.material3.MaterialTheme import androidx.compose.material3.ProvideTextStyle import androidx.compose.material3.SuggestionChip -import androidx.compose.material3.SuggestionChipDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider @@ -652,11 +651,6 @@ private fun TagsChip( modifier = modifier, onClick = onClick, label = { Text(text = text, style = MaterialTheme.typography.bodySmall) }, - border = null, - colors = SuggestionChipDefaults.suggestionChipColors( - containerColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.12f), - labelColor = MaterialTheme.colorScheme.onSurface, - ), ) } } diff --git a/app/src/main/java/eu/kanade/presentation/reader/settings/ColorFilterPage.kt b/app/src/main/java/eu/kanade/presentation/reader/settings/ColorFilterPage.kt index 78f20cb8f9..0497986cf7 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/settings/ColorFilterPage.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/settings/ColorFilterPage.kt @@ -2,6 +2,7 @@ package eu.kanade.presentation.reader.settings import android.os.Build import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.material3.FilterChip import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -18,7 +19,6 @@ import tachiyomi.core.preference.getAndSet import tachiyomi.presentation.core.components.CheckboxItem import tachiyomi.presentation.core.components.SettingsFlowRow import tachiyomi.presentation.core.components.SliderItem -import tachiyomi.presentation.core.components.material.ChoiceChip @Composable internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel) { @@ -126,10 +126,10 @@ internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel) val colorFilterMode by screenModel.preferences.colorFilterMode().collectAsState() SettingsFlowRow(R.string.pref_color_filter_mode) { colorFilterModes.mapIndexed { index, it -> - ChoiceChip( - isSelected = colorFilterMode == index, + FilterChip( + selected = colorFilterMode == index, onClick = { screenModel.preferences.colorFilterMode().set(index) }, - content = { Text(it) }, + label = { Text(it) }, ) } } diff --git a/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt b/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt index 990a1423dc..263831f740 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt @@ -1,6 +1,7 @@ package eu.kanade.presentation.reader.settings import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.material3.FilterChip import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -11,7 +12,6 @@ import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import tachiyomi.presentation.core.components.CheckboxItem import tachiyomi.presentation.core.components.SettingsFlowRow -import tachiyomi.presentation.core.components.material.ChoiceChip private val themes = listOf( R.string.black_background to 1, @@ -25,10 +25,10 @@ internal fun ColumnScope.GeneralPage(screenModel: ReaderSettingsScreenModel) { val readerTheme by screenModel.preferences.readerTheme().collectAsState() SettingsFlowRow(R.string.pref_reader_theme) { themes.map { (labelRes, value) -> - ChoiceChip( - isSelected = readerTheme == value, + FilterChip( + selected = readerTheme == value, onClick = { screenModel.preferences.readerTheme().set(value) }, - content = { Text(stringResource(labelRes)) }, + label = { Text(stringResource(labelRes)) }, ) } } 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 d40a7747bd..a055d8d5db 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 @@ -331,7 +331,7 @@ fun SettingsFlowRow( end = SettingsItemsPaddings.Horizontal, bottom = SettingsItemsPaddings.Vertical, ), - horizontalArrangement = Arrangement.spacedBy(4.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp), content = content, ) } diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Chip.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Chip.kt deleted file mode 100644 index 55d988f521..0000000000 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Chip.kt +++ /dev/null @@ -1,60 +0,0 @@ -package tachiyomi.presentation.core.components.material - -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.requiredHeight -import androidx.compose.foundation.layout.widthIn -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.ProvideTextStyle -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.dp - -@Composable -fun Chip( - modifier: Modifier = Modifier, - backgroundColor: Color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.15f), - contentColor: Color = MaterialTheme.colorScheme.onSurface, - onClick: () -> Unit = {}, - content: @Composable () -> Unit, -) { - Surface( - modifier = Modifier, - shape = CircleShape, - color = backgroundColor, - contentColor = contentColor, - onClick = {}, - ) { - Row( - modifier = modifier.clickable(onClick = onClick) - .widthIn(min = 56.dp) - .requiredHeight(32.dp) - .padding(horizontal = 12.dp), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.Center, - ) { - ProvideTextStyle(MaterialTheme.typography.bodySmall, content) - } - } -} - -@Composable -fun ChoiceChip( - modifier: Modifier = Modifier, - isSelected: Boolean, - onClick: () -> Unit = {}, - selectedBackgroundColor: Color = MaterialTheme.colorScheme.primary, - selectedContentColor: Color = MaterialTheme.colorScheme.onPrimary, - content: @Composable () -> Unit, -) { - if (isSelected) { - Chip(modifier, selectedBackgroundColor, selectedContentColor, onClick, content) - } else { - Chip(modifier, onClick = onClick, content = content) - } -}