Skip to content
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
13 changes: 8 additions & 5 deletions ComposePrefs3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ plugins {
}

android {
compileSdk 33
compileSdk 34

defaultConfig {
minSdk 21
targetSdk 33
targetSdk 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -38,10 +38,13 @@ android {
}

dependencies {
implementation "androidx.compose.ui:ui:1.4.3"
implementation "androidx.compose.material3:material3:1.1.0"
implementation "androidx.compose.material3:material3-window-size-class:1.1.0"
implementation "androidx.compose.ui:ui:1.5.3"
implementation "androidx.compose.material3:material3:1.1.2"
implementation "androidx.compose.material3:material3-window-size-class:1.1.2"
implementation "androidx.datastore:datastore-preferences:1.0.0"

androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.5.3"
testImplementation 'junit:junit:4.13.2'
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import androidx.compose.ui.unit.dp
@Composable
fun Divider(
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colorScheme.onSurface.copy(alpha = DividerAlpha),
color: Color = MaterialTheme.colorScheme.onSurface.copy(alpha = DIVIDER_ALPHA),
thickness: Dp = 1.dp,
indent: Dp = 0.dp
) {
Expand All @@ -31,4 +31,4 @@ fun Divider(
)
}

private const val DividerAlpha = 0.12f
private const val DIVIDER_ALPHA = 0.12f
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ fun GroupHeader(
Box(
Modifier
.padding(
start = StartPadding,
start = startPadding,
)
.fillMaxWidth(),
contentAlignment = Alignment.CenterStart
) {
Text(
title,
color = color,
fontSize = LocalTextStyle.current.fontSize.times(FontSizeMultiplier),
fontSize = LocalTextStyle.current.fontSize.times(FONT_SIZE_MULTIPLIER),
fontWeight = FontWeight.SemiBold
)
}
}


private val StartPadding = 16.dp
private const val FontSizeMultiplier = 0.85f
private val startPadding = 16.dp
private const val FONT_SIZE_MULTIPLIER = 0.85f
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ fun PrefsListItem(
typography.titleMedium,
textColor,
when {
enabled || !darkenOnDisable -> AlphaHigh
else -> AlphaDisabled
enabled || !darkenOnDisable -> ALPHA_HIGH
else -> ALPHA_DISABLED
},
text
)!!
val styledSecondaryText = applyTextStyle(
typography.bodyMedium,
textColor,
when {
enabled || !darkenOnDisable -> AlphaMedium
else -> AlphaDisabled
enabled || !darkenOnDisable -> ALPHA_MEDIUM
else -> ALPHA_DISABLED
},
secondaryText
)
val styledTrailing = applyTextStyle(
typography.bodySmall,
textColor,
when {
enabled || !darkenOnDisable -> AlphaHigh
else -> AlphaDisabled
enabled || !darkenOnDisable -> ALPHA_HIGH
else -> ALPHA_DISABLED
},
trailing
)
Expand Down Expand Up @@ -139,6 +139,6 @@ private fun applyTextStyle(
}
}

private const val AlphaHigh = 1.0f
private const val AlphaMedium = 0.74f
private const val AlphaDisabled = 0.38f
private const val ALPHA_HIGH = 1.0f
private const val ALPHA_MEDIUM = 0.74f
private const val ALPHA_DISABLED = 0.38f
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import java.lang.Exception
* @param leadingIcon Icon which is positioned at the start of the Pref
*/

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CheckBoxPref(
key: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import kotlinx.coroutines.launch
* @param textColor Text colour of the [title] and [summary]
* @param enabled If false, this Pref cannot be clicked.
*/
@OptIn(ExperimentalMaterial3Api::class)
@ExperimentalComposeUiApi
@Composable
fun EditTextPref(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import java.lang.Exception
* @param enabled If false, this Pref cannot be clicked and the Dialog cannot be shown.
* @param entries Map of keys to values for entries that should be shown in the Dialog.
*/
@OptIn(ExperimentalMaterial3Api::class)
@ExperimentalComposeUiApi
@Composable
fun ListPref(
Expand Down Expand Up @@ -102,7 +101,7 @@ fun ListPref(
AlertDialog(
onDismissRequest = { showDialog = false },
text = {
Column() {
Column {
Text(modifier = Modifier.padding(vertical = 16.dp), text = title, style = MaterialTheme.typography.titleLarge)
LazyColumn {
items(entryList) { current ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import java.lang.Exception
* @param enabled If false, this Pref cannot be clicked and the Dialog cannot be shown.
* @param entries Map of keys to values for entries that should be shown in the Dialog.
*/
@OptIn(ExperimentalMaterial3Api::class)
@ExperimentalComposeUiApi
@Composable
fun MultiSelectListPref(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fun SliderPref(
val datastore = LocalPrefsDataStore.current
val prefs by remember { datastore.data }.collectAsState(initial = null)

var value by remember { mutableStateOf(defaultValue) }
var value by remember { mutableFloatStateOf(defaultValue) }

LaunchedEffect(Unit) {
prefs?.get(selectionKey)?.also { value = it }
Expand Down
24 changes: 12 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plugins {
}

android {
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.jamal.composeprefs3sample"
minSdk 26
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -48,19 +48,19 @@ android {

dependencies {

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'com.google.android.material:material:1.9.0'
implementation "androidx.compose.ui:ui:1.4.3"
implementation "androidx.compose.material3:material3:1.1.0"
implementation "androidx.compose.material3:material3-window-size-class:1.1.0"
implementation "androidx.compose.ui:ui-tooling-preview:1.4.3"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.activity:activity-compose:1.7.2'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'com.google.android.material:material:1.10.0'
implementation "androidx.compose.ui:ui:1.5.3"
implementation "androidx.compose.material3:material3:1.1.2"
implementation "androidx.compose.material3:material3-window-size-class:1.1.2"
implementation "androidx.compose.ui:ui-tooling-preview:1.5.3"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.8.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.4.3"
debugImplementation "androidx.compose.ui:ui-tooling:1.4.3"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.5.3"
debugImplementation "androidx.compose.ui:ui-tooling:1.5.3"

// ComposePrefs library
implementation project(':ComposePrefs3')
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<activity
android:name="com.jamal.composeprefs3sample.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.ComposePrefsSample.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.jamal.composeprefs3.ui.GroupHeader
import com.jamal.composeprefs3.ui.PrefsScreen
import com.jamal.composeprefs3.ui.prefs.*

@OptIn(ExperimentalMaterial3Api::class)
@ExperimentalComposeUiApi
@Composable
fun SettingsScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

private val DarkColorPalette = darkColorScheme(
private val darkColorPalette = darkColorScheme(
primary = Purple200,
primaryContainer = Purple700,
secondary = Teal200,
Expand All @@ -19,7 +19,7 @@ private val DarkColorPalette = darkColorScheme(
onSurface = Color.White,
)

private val LightColorPalette = lightColorScheme(
private val lightColorPalette = lightColorScheme(
primary = Purple500,
primaryContainer = Purple700,
secondary = Teal200,
Expand All @@ -37,9 +37,9 @@ fun ComposePrefsSampleTheme(
content: @Composable () -> Unit
) {
val colors = if (darkTheme) {
DarkColorPalette
darkColorPalette
} else {
LightColorPalette
lightColorPalette
}

MaterialTheme(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor" >?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
5 changes: 1 addition & 4 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor" >?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>

Expand All @@ -19,7 +19,4 @@
<item name="windowNoTitle">true</item>
</style>

<style name="Theme.ComposePrefsSample.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="Theme.ComposePrefsSample.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.code.style=official
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Dec 26 19:18:50 GMT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
7 changes: 4 additions & 3 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jdk:
- openjdk11
before_install:
- ./scripts/prepareJitpackEnvironment.sh
- source "$HOME/.sdkman/bin/sdkman-init.sh"
- sdk update
- sdk install java 17.0.7-tem
- sdk use java 17.0.7-tem
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "ComposePrefs3 Sample"
Expand Down