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
60 changes: 0 additions & 60 deletions ComposePrefs3/build.gradle

This file was deleted.

63 changes: 63 additions & 0 deletions ComposePrefs3/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.maven.publish)
}

android {
namespace = "com.jamal.composeprefs3"
compileSdk = 34

defaultConfig {
minSdk = 21
targetSdk = 34

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.14"
}
}

dependencies {
implementation(platform(libs.androidx.compose.bom))

implementation(libs.androidx.ui)
implementation(libs.androidx.material3)
implementation(libs.androidx.compose.materialWindow)
implementation(libs.androidx.datastore.pref)
}
afterEvaluate {
publishing {
publications {
create<MavenPublication>("release") {
from(components["release"])

groupId = "com.github.jamalmulla"
artifactId = "ComposePrefs3"
version = "1.0.5"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ fun CheckBoxPref(
title: String,
modifier: Modifier = Modifier,
summary: String? = null,
summaryOn: String? = null,
summaryOff: String? = null,
defaultChecked: Boolean = false,
onCheckedChange: ((Boolean) -> Unit)? = null,
textColor: Color = MaterialTheme.colorScheme.onBackground,
Expand Down Expand Up @@ -70,7 +72,7 @@ fun CheckBoxPref(
title = title,
modifier = modifier,
textColor = textColor,
summary = summary,
summary = if (summaryOn != null && summaryOff != null) { if (checked) summaryOn else summaryOff } else summary,
leadingIcon = leadingIcon,
enabled = enabled,
darkenOnDisable = darkenOnDisable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ fun SwitchPref(
title: String,
modifier: Modifier = Modifier,
summary: String? = null,
summaryOn: String? = null,
summaryOff: String? = null,
defaultChecked: Boolean = false, // only used if it doesn't already exist in the datastore
onCheckedChange: ((Boolean) -> Unit)? = null,
textColor: Color = MaterialTheme.colorScheme.onBackground,
Expand Down Expand Up @@ -63,7 +65,7 @@ fun SwitchPref(
title = title,
modifier = modifier,
textColor = textColor,
summary = summary,
summary = if (summaryOn != null && summaryOff != null) { if (checked) summaryOn else summaryOff } else summary,
darkenOnDisable = true,
leadingIcon = leadingIcon,
enabled = enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun TextPref(
minimalHeight: Boolean = false,
onClick: () -> Unit = {},
textColor: Color = MaterialTheme.colorScheme.onBackground,
enabled: Boolean = false,
enabled: Boolean = true,
leadingIcon: @Composable (() -> Unit)? = null,
trailingContent: @Composable (() -> Unit)? = null
) {
Expand Down
68 changes: 0 additions & 68 deletions app/build.gradle

This file was deleted.

75 changes: 75 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
}

android {
namespace = "com.jamal.composeprefs3sample"
compileSdk = 34

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

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.14"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}

}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(platform(libs.androidx.compose.bom))

implementation(libs.material)
implementation(libs.androidx.ui)
implementation(libs.androidx.material3)
implementation(libs.androidx.compose.materialWindow)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)

// ComposePrefs library
implementation(project(":ComposePrefs3"))
implementation(libs.androidx.datastore.pref)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.androidx.ui.test.junit4)
androidTestImplementation(platform(libs.androidx.compose.bom))
debugImplementation(libs.androidx.ui.tooling)
}
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
26 changes: 24 additions & 2 deletions app/src/main/java/com/jamal/composeprefs3sample/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import com.jamal.composeprefs3.ui.GroupHeader
import com.jamal.composeprefs3.ui.PrefsScreen
import com.jamal.composeprefs3.ui.prefs.*
Expand All @@ -36,6 +38,8 @@ fun SettingsScreen() {
TextPref(
title = "Just some text",
summary = "But enabled this time",
dependencyKey = booleanPreferencesKey("cb2"),
darkenOnDisable = true,
enabled = true
)
}
Expand Down Expand Up @@ -67,14 +71,23 @@ fun SettingsScreen() {
CheckBoxPref(
key = "cb3",
title = "Simple checkbox",
summary = "But it has some summary on off text",
summaryOn = "But it has some summary on text",
summaryOff = "But it has some summary off text",
)
}
prefsItem {
CheckBoxPref(
key = "cb4",
title = "Simple checkbox",
summary = "But it's disabled",
enabled = false,
darkenOnDisable = true
)
}
prefsItem {
CheckBoxPref(
key = "cb4",
key = "cb5",
title = "Simple checkbox",
summary = "But with a leading icon",
leadingIcon = { Icon(Icons.Filled.Person, "Person") })
Expand All @@ -94,13 +107,22 @@ fun SettingsScreen() {
SwitchPref(
key = "sw3",
title = "Simple switch",
summary = "But it has some summary on off text",
summaryOn = "But it has some summary on text",
summaryOff = "But it has some summary off text",
)
}
prefsItem {
SwitchPref(
key = "sw4",
title = "Simple switch",
summary = "But it's disabled",
enabled = false
)
}
prefsItem {
SwitchPref(
key = "sw4",
key = "sw5",
title = "Simple switch",
summary = "But with a leading icon",
leadingIcon = { Icon(Icons.Filled.Home, "Home") })
Expand Down
Loading