From 0b055cc34f4dc55ff42ce6ed4b07b68bd049b5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9luchu?= Date: Tue, 30 Jan 2024 13:12:00 +0100 Subject: [PATCH] Update Material 3 Library to RC01 and Improve UI components --- gradle/libs.versions.toml | 4 +-- .../preferences/PreferenceSingleChoiceItem.kt | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fa1731d4..1a623306 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -24,7 +24,7 @@ androidx-compose-foundation = { module = "androidx.compose.foundation:foundation androidx-compose-foundation-foundation-layout = { module = "androidx.compose.foundation:foundation-layout", version.ref = "androidx-compose-foundation" } androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "androidx-compose-material" } androidx-compose-material-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "androidx-compose-material" } -androidx-compose-material3 = "androidx.compose.material3:material3:1.1.2" +androidx-compose-material3 = "androidx.compose.material3:material3:1.2.0-rc01" androidx-compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "androidx-compose-runtime" } androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidx-compose-ui" } androidx-compose-ui-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose-ui" } @@ -36,7 +36,7 @@ androidx-lifecycle-lifecycle-livedata-core-ktx = { module = "androidx.lifecycle: androidx-lifecycle-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" } androidx-navigation-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" } androidx-preference = "androidx.preference:preference-ktx:1.2.1" -com-android-tools-build-gradle = "com.android.tools.build:gradle:8.2.1" +com-android-tools-build-gradle = "com.android.tools.build:gradle:8.2.2" com-google-accompanist-accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "com-google-accompanist" } com-google-android-gms-play-services-base = "com.google.android.gms:play-services-base:18.3.0" com-google-code-gson = "com.google.code.gson:gson:2.10.1" diff --git a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/preferences/PreferenceSingleChoiceItem.kt b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/preferences/PreferenceSingleChoiceItem.kt index ef9ff060..e6b45c48 100644 --- a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/preferences/PreferenceSingleChoiceItem.kt +++ b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/preferences/PreferenceSingleChoiceItem.kt @@ -12,32 +12,37 @@ import androidx.compose.material3.RadioButtonDefaults import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.Immutable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Shape import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import com.jeluchu.jchucomponents.ui.themes.artichoke +import com.jeluchu.jchucomponents.ui.extensions.modifier.cornerRadius @Composable fun PreferenceSingleChoiceItem( modifier: Modifier = Modifier, text: String, - color: Color = MaterialTheme.colorScheme.onSurface, - style: TextStyle = MaterialTheme.typography.titleLarge, selected: Boolean, - radioButtonColor: Color = artichoke, + shape: Shape = 15.cornerRadius(), + style: TextStyle = MaterialTheme.typography.titleLarge, + colors: PreferenceChoiceColors = PreferenceChoiceColors(), contentPadding: PaddingValues = PaddingValues(horizontal = 8.dp, vertical = 18.dp), onClick: () -> Unit ) = Surface( modifier = Modifier.selectable( selected = selected, onClick = onClick - ) + ), + shape = shape, + contentColor = colors.contentColor, + color = colors.containerColor ) { Row( modifier = modifier @@ -54,7 +59,6 @@ fun PreferenceSingleChoiceItem( text = text, maxLines = 1, style = style.copy(fontSize = 16.sp), - color = color, overflow = TextOverflow.Ellipsis ) } @@ -62,8 +66,8 @@ fun PreferenceSingleChoiceItem( selected = selected, onClick = onClick, colors = RadioButtonDefaults.colors( - selectedColor = radioButtonColor, - unselectedColor = radioButtonColor + selectedColor = colors.selectedRadioColor, + unselectedColor = colors.unselectedRadioColor ), modifier = Modifier .padding() @@ -72,6 +76,15 @@ fun PreferenceSingleChoiceItem( } } +@Immutable +class PreferenceChoiceColors( + val selectedRadioColor: Color = Color.DarkGray, + val unselectedRadioColor: Color = Color.DarkGray, + val containerColor: Color = Color.White, + val contentColor: Color = Color.DarkGray +) + + @Preview @Composable fun PreferenceSingleChoiceItemPreview() = PreferenceSingleChoiceItem(