diff --git a/ComposePrefs3/build.gradle b/ComposePrefs3/build.gradle deleted file mode 100644 index d235d84..0000000 --- a/ComposePrefs3/build.gradle +++ /dev/null @@ -1,60 +0,0 @@ -plugins { - id 'com.android.library' - id 'kotlin-android' - id 'maven-publish' -} - -android { - compileSdk 33 - - defaultConfig { - minSdk 21 - targetSdk 33 - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles "consumer-rules.pro" - } - - buildTypes { - release { - minifyEnabled 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.4.7" - } - namespace 'com.jamal.composeprefs3' -} - -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.datastore:datastore-preferences:1.0.0" -} - - -afterEvaluate { - publishing { - publications { - release(MavenPublication) { - from components.release - - groupId = 'com.github.jamalmulla' - artifactId = 'ComposePrefs3' - version = '1.0.5' - } - } - } -} diff --git a/ComposePrefs3/build.gradle.kts b/ComposePrefs3/build.gradle.kts new file mode 100644 index 0000000..aedef70 --- /dev/null +++ b/ComposePrefs3/build.gradle.kts @@ -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("release") { + from(components["release"]) + + groupId = "com.github.jamalmulla" + artifactId = "ComposePrefs3" + version = "1.0.5" + } + } + } +} diff --git a/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/CheckBoxPref.kt b/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/CheckBoxPref.kt index 9d5e60a..369cbbd 100644 --- a/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/CheckBoxPref.kt +++ b/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/CheckBoxPref.kt @@ -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, @@ -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, diff --git a/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/SwitchPref.kt b/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/SwitchPref.kt index a3728aa..c6fdf70 100644 --- a/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/SwitchPref.kt +++ b/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/SwitchPref.kt @@ -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, @@ -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, diff --git a/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/TextPref.kt b/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/TextPref.kt index dd67464..bdc8e56 100644 --- a/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/TextPref.kt +++ b/ComposePrefs3/src/main/java/com/jamal/composeprefs3/ui/prefs/TextPref.kt @@ -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 ) { diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 7921631..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,68 +0,0 @@ -plugins { - id 'com.android.application' - id 'kotlin-android' -} - -android { - compileSdk 33 - - defaultConfig { - applicationId "com.jamal.composeprefs3sample" - minSdk 26 - targetSdk 33 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - vectorDrawables { - useSupportLibrary true - } - } - - buildTypes { - release { - minifyEnabled 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.4.7" - } - packagingOptions { - resources { - excludes += '/META-INF/{AL2.0,LGPL2.1}' - } - } - namespace 'com.jamal.composeprefs3sample' -} - -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' - 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" - - // ComposePrefs library - implementation project(':ComposePrefs3') - implementation "androidx.datastore:datastore-preferences:1.0.0" -} \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..26054f2 --- /dev/null +++ b/app/build.gradle.kts @@ -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) +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 481bb43..ff59496 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -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 diff --git a/app/src/main/java/com/jamal/composeprefs3sample/SettingsScreen.kt b/app/src/main/java/com/jamal/composeprefs3sample/SettingsScreen.kt index e353e89..ba51047 100644 --- a/app/src/main/java/com/jamal/composeprefs3sample/SettingsScreen.kt +++ b/app/src/main/java/com/jamal/composeprefs3sample/SettingsScreen.kt @@ -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.* @@ -36,6 +38,8 @@ fun SettingsScreen() { TextPref( title = "Just some text", summary = "But enabled this time", + dependencyKey = booleanPreferencesKey("cb2"), + darkenOnDisable = true, enabled = true ) } @@ -67,6 +71,15 @@ 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 @@ -74,7 +87,7 @@ fun SettingsScreen() { } prefsItem { CheckBoxPref( - key = "cb4", + key = "cb5", title = "Simple checkbox", summary = "But with a leading icon", leadingIcon = { Icon(Icons.Filled.Person, "Person") }) @@ -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") }) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index a372cea..0000000 --- a/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - - repositories { - google() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:7.3.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..e3f8a07 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,6 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + alias(libs.plugins.android.application) apply false + alias(libs.plugins.jetbrains.kotlin.android) apply false + alias(libs.plugins.android.library) apply false +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..1e9c10c --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,44 @@ +[versions] +agp = "8.5.1" +kotlin = "1.9.24" +coreKtx = "1.13.1" +junit = "4.13.2" +junitVersion = "1.2.1" +espressoCore = "3.6.1" +appcompat = "1.7.0" +material = "1.12.0" +lifecycleRuntimeKtx = "2.8.4" +activityCompose = "1.9.1" +composeBom = "2024.06.00" +datastorePref = "1.1.1" + +[libraries] + +androidx-ui = { group = "androidx.compose.ui", name = "ui" } +androidx-material3 = { group = "androidx.compose.material3", name = "material3" } +androidx-compose-materialWindow = { module = "androidx.compose.material3:material3-window-size-class" } +androidx-datastore-pref = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "datastorePref" } + + +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +junit = { group = "junit", name = "junit", version.ref = "junit" } +androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } +androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } +androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } +material = { group = "com.google.android.material", name = "material", version.ref = "material" } +androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" } +androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } +androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } +androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } +androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } +androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } +androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } +androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } + + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +android-library = { id = "com.android.library", version.ref = "agp" } +maven-publish = { id = "com.vanniktech.maven.publish", version = "0.25.3" } + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b13af1c..dd800b8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Dec 26 19:18:50 GMT 2021 +#Wed Jul 31 14:43:20 KST 2024 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 31e0d5d..0000000 --- a/settings.gradle +++ /dev/null @@ -1,11 +0,0 @@ -dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - google() - mavenCentral() - jcenter() // Warning: this repository is going to shut down soon - } -} -rootProject.name = "ComposePrefs3 Sample" -include ':app' -include ':ComposePrefs3' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..bab36e8 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,25 @@ +pluginManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + maven("https://jitpack.io") + } +} + +rootProject.name = "ComposePrefs3 Sample" +include(":app") +include(":ComposePrefs3")