From 10a54de9a6a95f67bb33e908a80dfd61c95df871 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Mar 2021 22:12:26 +0100 Subject: [PATCH 01/28] Bump dokka-gradle-plugin from 1.4.20 to 1.4.30 (#115) Bumps [dokka-gradle-plugin](https://github.com/Kotlin/dokka) from 1.4.20 to 1.4.30. - [Release notes](https://github.com/Kotlin/dokka/releases) - [Commits](https://github.com/Kotlin/dokka/compare/v1.4.20...v1.4.30) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3f4e4786..54c744ea 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.20.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' - classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.20' + classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.30' } } From 2e3b4ec2e56b6acf5b8b038b4008b1a2d0039098 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Mar 2021 09:43:16 +0100 Subject: [PATCH 02/28] Bump gradle from 4.1.2 to 4.1.3 (#116) Bumps gradle from 4.1.2 to 4.1.3. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 54c744ea..c4aea88a 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.2' + classpath 'com.android.tools.build:gradle:4.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.20.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' From bd69b08d1ff1a9dcc5aef43c62eb24eaf1453696 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Mar 2021 11:45:10 +0100 Subject: [PATCH 03/28] Bump fastadapter from 5.3.2 to 5.3.5 (#118) Bumps [fastadapter](https://github.com/mikepenz/FastAdapter) from 5.3.2 to 5.3.5. - [Release notes](https://github.com/mikepenz/FastAdapter/releases) - [Changelog](https://github.com/mikepenz/FastAdapter/blob/develop/CHANGELOG.md) - [Commits](https://github.com/mikepenz/FastAdapter/compare/v5.3.2...v5.3.5) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- simplesettings/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplesettings/build.gradle b/simplesettings/build.gradle index 8b273a6c..8c245443 100644 --- a/simplesettings/build.gradle +++ b/simplesettings/build.gradle @@ -50,7 +50,7 @@ dependencies { // External dependencies api 'com.mikepenz:aboutlibraries-core:8.8.0' api 'com.mikepenz:aboutlibraries:8.8.0@aar' - api 'com.mikepenz:fastadapter:5.3.2' + api 'com.mikepenz:fastadapter:5.3.5' api 'com.github.ibrahimsn98:live-preferences:1.9' api 'com.github.skydoves:colorpickerpreference:2.0.5' From 9a6c23a3b3b691ca718baea874bb823e4c9fb1a6 Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Mon, 22 Mar 2021 13:35:41 +0100 Subject: [PATCH 04/28] Add Jitpack repository due to build errors without it --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e73c49e4..84571564 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ allprojects { repositories { ... maven { url "https://repo.chillibits.com/artifactory/android" } + maven { url "https://jitpack.io" } } } ``` From 6d569e71d92106d87cee3b589b56ac5f62968f04 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Mar 2021 12:23:43 +0100 Subject: [PATCH 05/28] Bump kotlin_version from 1.4.31 to 1.4.32 (#119) Bumps `kotlin_version` from 1.4.31 to 1.4.32. Updates `kotlin-gradle-plugin` from 1.4.31 to 1.4.32 - [Release notes](https://github.com/JetBrains/kotlin/releases) - [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md) - [Commits](https://github.com/JetBrains/kotlin/commits) Updates `kotlin-stdlib-jdk7` from 1.4.31 to 1.4.32 - [Release notes](https://github.com/JetBrains/kotlin/releases) - [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md) - [Commits](https://github.com/JetBrains/kotlin/commits) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c4aea88a..635e0891 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { ext.library_version = '1.2.0' ext.library_version_code = 1200 - ext.kotlin_version = '1.4.31' + ext.kotlin_version = '1.4.32' repositories { google() jcenter() From 059e12212f02cc6a9a7499500299a5107a0d1b11 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 25 Mar 2021 14:20:30 +0100 Subject: [PATCH 06/28] Bump appcompat from 1.3.0-beta01 to 1.3.0-rc01 (#122) Bumps appcompat from 1.3.0-beta01 to 1.3.0-rc01. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- app/build.gradle | 2 +- simplesettings/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8755d4a1..899d1881 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,7 +35,7 @@ dependencies { // Base dependencies implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.3.0-beta01' + implementation 'androidx.appcompat:appcompat:1.3.0-rc01' implementation 'androidx.core:core-ktx:1.5.0-beta03' // Google dependencies diff --git a/simplesettings/build.gradle b/simplesettings/build.gradle index 8c245443..bd601aa1 100644 --- a/simplesettings/build.gradle +++ b/simplesettings/build.gradle @@ -36,7 +36,7 @@ android { dependencies { // Base dependencies implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.appcompat:appcompat:1.3.0-rc01' implementation 'androidx.core:core-ktx:1.5.0-beta03' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4' From 9bf31e1f48774aeb889c1ed9f42d3d8d28c11585 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 25 Mar 2021 14:27:56 +0100 Subject: [PATCH 07/28] Bump activity-ktx from 1.3.0-alpha04 to 1.3.0-alpha05 (#120) Bumps activity-ktx from 1.3.0-alpha04 to 1.3.0-alpha05. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- simplesettings/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplesettings/build.gradle b/simplesettings/build.gradle index bd601aa1..fbf78da7 100644 --- a/simplesettings/build.gradle +++ b/simplesettings/build.gradle @@ -41,7 +41,7 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4' implementation 'androidx.navigation:navigation-ui-ktx:2.3.4' - implementation 'androidx.activity:activity-ktx:1.3.0-alpha04' + implementation 'androidx.activity:activity-ktx:1.3.0-alpha05' // Google dependencies api 'com.google.android.material:material:1.3.0' From 7c49fa9ecf1a8f3f8308a35a01b8f06f2a9787a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 30 Mar 2021 22:47:54 +0200 Subject: [PATCH 08/28] Bump aboutlibraries from 8.8.0 to 8.8.4 (#123) Bumps [aboutlibraries](https://github.com/mikepenz/AboutLibraries) from 8.8.0 to 8.8.4. - [Release notes](https://github.com/mikepenz/AboutLibraries/releases) - [Changelog](https://github.com/mikepenz/AboutLibraries/blob/develop/gradle-release.gradle) - [Commits](https://github.com/mikepenz/AboutLibraries/compare/v8.8.0...v8.8.4) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- simplesettings/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplesettings/build.gradle b/simplesettings/build.gradle index fbf78da7..805912ac 100644 --- a/simplesettings/build.gradle +++ b/simplesettings/build.gradle @@ -48,7 +48,7 @@ dependencies { api 'androidx.preference:preference-ktx:1.1.1' // External dependencies - api 'com.mikepenz:aboutlibraries-core:8.8.0' + api 'com.mikepenz:aboutlibraries-core:8.8.4' api 'com.mikepenz:aboutlibraries:8.8.0@aar' api 'com.mikepenz:fastadapter:5.3.5' api 'com.github.ibrahimsn98:live-preferences:1.9' From dbdef863b4ef8cef80aec694753dabb6f4534e9f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 Mar 2021 08:27:12 +0200 Subject: [PATCH 09/28] Bump aboutlibraries from 8.8.0 to 8.8.4 (#124) Bumps [aboutlibraries](https://github.com/mikepenz/AboutLibraries) from 8.8.0 to 8.8.4. - [Release notes](https://github.com/mikepenz/AboutLibraries/releases) - [Changelog](https://github.com/mikepenz/AboutLibraries/blob/develop/gradle-release.gradle) - [Commits](https://github.com/mikepenz/AboutLibraries/compare/v8.8.0...v8.8.4) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- simplesettings/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplesettings/build.gradle b/simplesettings/build.gradle index 805912ac..5a7b5899 100644 --- a/simplesettings/build.gradle +++ b/simplesettings/build.gradle @@ -49,7 +49,7 @@ dependencies { // External dependencies api 'com.mikepenz:aboutlibraries-core:8.8.4' - api 'com.mikepenz:aboutlibraries:8.8.0@aar' + api 'com.mikepenz:aboutlibraries:8.8.4@aar' api 'com.mikepenz:fastadapter:5.3.5' api 'com.github.ibrahimsn98:live-preferences:1.9' api 'com.github.skydoves:colorpickerpreference:2.0.5' From 04dba9883b6b118afb35a4a91270d87bf64f0c13 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Apr 2021 09:08:03 +0200 Subject: [PATCH 10/28] Bump activity-ktx from 1.3.0-alpha05 to 1.3.0-alpha06 (#127) Bumps activity-ktx from 1.3.0-alpha05 to 1.3.0-alpha06. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- simplesettings/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplesettings/build.gradle b/simplesettings/build.gradle index 5a7b5899..71028bf8 100644 --- a/simplesettings/build.gradle +++ b/simplesettings/build.gradle @@ -41,7 +41,7 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4' implementation 'androidx.navigation:navigation-ui-ktx:2.3.4' - implementation 'androidx.activity:activity-ktx:1.3.0-alpha05' + implementation 'androidx.activity:activity-ktx:1.3.0-alpha06' // Google dependencies api 'com.google.android.material:material:1.3.0' From a47532f38926fcf748af23b6c4d6e188ed62faa0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Apr 2021 10:26:07 +0200 Subject: [PATCH 11/28] Bump navigation-fragment-ktx from 2.3.4 to 2.3.5 (#126) Bumps navigation-fragment-ktx from 2.3.4 to 2.3.5. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- simplesettings/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplesettings/build.gradle b/simplesettings/build.gradle index 71028bf8..1d951383 100644 --- a/simplesettings/build.gradle +++ b/simplesettings/build.gradle @@ -39,7 +39,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.3.0-rc01' implementation 'androidx.core:core-ktx:1.5.0-beta03' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4' + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' implementation 'androidx.navigation:navigation-ui-ktx:2.3.4' implementation 'androidx.activity:activity-ktx:1.3.0-alpha06' From 69a75c019d8c91c49ae3aa4993c7f8df4e9dbd27 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Apr 2021 10:34:40 +0200 Subject: [PATCH 12/28] Bump navigation-ui-ktx from 2.3.4 to 2.3.5 (#125) Bumps navigation-ui-ktx from 2.3.4 to 2.3.5. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- simplesettings/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplesettings/build.gradle b/simplesettings/build.gradle index 1d951383..5ac0d917 100644 --- a/simplesettings/build.gradle +++ b/simplesettings/build.gradle @@ -40,7 +40,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.5.0-beta03' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' - implementation 'androidx.navigation:navigation-ui-ktx:2.3.4' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' implementation 'androidx.activity:activity-ktx:1.3.0-alpha06' // Google dependencies From 947e0cfbb23119d8deae998f6c09da3d5220c25a Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Fri, 9 Apr 2021 15:29:57 +0200 Subject: [PATCH 13/28] Migrate demo app to Jetpack Compose (#128) * First Jetpack Compose migrations * Finalize UI structure * Add methods to receive LiveData without observer --- README.md | 6 + app/build.gradle | 41 ++++-- app/src/main/AndroidManifest.xml | 15 +- .../simplesettingssample/MainActivity.kt | 135 +++++++++++++----- .../simplesettingssample/Theming.kt | 35 +++++ app/src/main/res/layout/activity_main.xml | 85 ----------- app/src/main/res/values-night/colors.xml | 9 ++ app/src/main/res/values/colors.xml | 7 - app/src/main/res/values/styles.xml | 17 +-- build.gradle | 3 +- gradle.properties | 24 ++-- gradle/wrapper/gradle-wrapper.properties | 10 +- simplesettings/build.gradle | 7 +- .../tool/SimpleSettingsStore.kt | 111 +++++++++++++- 14 files changed, 313 insertions(+), 192 deletions(-) create mode 100644 app/src/main/java/com/chillibits/simplesettingssample/Theming.kt delete mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/values-night/colors.xml diff --git a/README.md b/README.md index 84571564..a0172544 100644 --- a/README.md +++ b/README.md @@ -223,10 +223,16 @@ As you can see, this works for the types `String`, `Int`, `Boolean`, `Float`, `L ### Retrieval as LiveData Furthermore, the library offers a feature to observe preference values as LiveData as follows: ```kotlin +val inputPref = getPreferenceLiveData(this@MainActivity, "listpreference") +``` + +or you can retrieve it directly as an LiveData Observer: +```kotlin getPrefObserver(this@MainActivity, "listpreference", Observer { value -> textField.text = value }) ``` + Like above, this works for the types `String`, `Int`, `Boolean`, `Float`, `Long`, `StringSet`.
*Note: This extension functions are only available for the classes, which implement `LifecycleOwner`.* diff --git a/app/build.gradle b/app/build.gradle index 899d1881..abb16390 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,13 +2,15 @@ * Copyright © Marc Auberer 2020-2021. All rights reserved */ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'kotlin-android-extensions' +} android { compileSdkVersion 30 - buildToolsVersion "30.0.2" + buildToolsVersion "30.0.3" defaultConfig { applicationId "com.chillibits.simplesettingssample" @@ -18,7 +20,6 @@ android { versionName library_version testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } - buildTypes { release { minifyEnabled true @@ -26,7 +27,24 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } - + kotlinOptions { + jvmTarget = '11' + useIR = true + } + buildFeatures { + compose true + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + composeOptions { + kotlinCompilerExtensionVersion compose_version + kotlinCompilerVersion '1.4.30' + } } dependencies { @@ -34,14 +52,21 @@ dependencies { implementation project(':simplesettings') // Base dependencies - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.3.0-rc01' - implementation 'androidx.core:core-ktx:1.5.0-beta03' + implementation 'androidx.core:core-ktx:1.5.0-rc01' // Google dependencies implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + // Jetpack Compose + implementation "androidx.compose.ui:ui:$compose_version" + implementation "androidx.compose.ui:ui-tooling:$compose_version" + implementation "androidx.compose.material:material:$compose_version" + implementation "androidx.compose.runtime:runtime-livedata:$compose_version" + implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha05' + implementation 'androidx.activity:activity-compose:1.3.0-alpha06' + // Test dependencies testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3a8d5da7..d0bff5a4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,12 +1,7 @@ - - - + android:installLocation="auto" > - - + android:exported="true"> @@ -29,4 +21,5 @@ + \ No newline at end of file diff --git a/app/src/main/java/com/chillibits/simplesettingssample/MainActivity.kt b/app/src/main/java/com/chillibits/simplesettingssample/MainActivity.kt index 366b02e7..5ef0d658 100644 --- a/app/src/main/java/com/chillibits/simplesettingssample/MainActivity.kt +++ b/app/src/main/java/com/chillibits/simplesettingssample/MainActivity.kt @@ -7,16 +7,33 @@ package com.chillibits.simplesettingssample import android.content.Context import android.content.Intent import android.net.Uri -import android.os.Build import android.os.Bundle import android.view.Menu import android.view.MenuItem -import android.view.View +import android.widget.NumberPicker import android.widget.Toast +import androidx.activity.compose.setContent import androidx.annotation.IdRes import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.Observer +import androidx.compose.foundation.layout.* +import androidx.compose.material.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.livedata.observeAsState +import androidx.compose.ui.Alignment.Companion.CenterHorizontally +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.layoutId +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.constraintlayout.compose.ConstraintLayout +import androidx.constraintlayout.compose.ConstraintSet +import androidx.core.view.WindowCompat +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.preference.Preference import com.chillibits.simplesettings.clicklistener.DialogClickListener import com.chillibits.simplesettings.clicklistener.LibsClickListener @@ -26,37 +43,21 @@ import com.chillibits.simplesettings.core.SimpleSettings import com.chillibits.simplesettings.core.SimpleSettingsConfig import com.chillibits.simplesettings.item.SimpleSwitchPreference import com.chillibits.simplesettings.tool.* -import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.android.synthetic.main.toolbar.* class MainActivity : AppCompatActivity(), SimpleSettingsConfig.OptionsItemSelectedCallback, SimpleSettingsConfig.PreferenceCallback, DialogClickListener.DialogResultCallback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + WindowCompat.setDecorFitsSystemWindows(window, true) - // Initialize toolbar - setSupportActionBar(toolbar) + val inputPref = getPreferenceLiveData(this, "inputpreference", "Default") - // Set window insets - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - window.decorView.setOnApplyWindowInsetsListener { v, insets -> - v.setPadding(0, 0, insets.systemWindowInsetRight, insets.systemWindowInsetBottom) - toolbar.setPadding(0, insets.systemWindowInsetTop, 0, 0) - insets.consumeSystemWindowInsets() + setContent { + AppTheme { + MainView(inputPref = inputPref) } } - - // Initialize number picker - numberPicker.apply { - minValue = 1 - maxValue = 10 - value = 3 - } - - subscribeToPreferenceValues() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -71,10 +72,78 @@ class MainActivity : AppCompatActivity(), SimpleSettingsConfig.OptionsItemSelect return super.onOptionsItemSelected(item) } - fun openSettingsCodeConfig(view: View) { - // Get number from number picker - val numberOfSwitchPreferences = numberPicker.value + @Preview(name = "MainView", showSystemUi = true) + @Composable + private fun MainView(inputPref: LiveData = MutableLiveData()) { + val context = LocalContext.current + val inputPrefState by inputPref.observeAsState() + + ConstraintLayout( + constraintSet = ConstraintSet { + val layout = createRefFor("layout") + constrain(layout) { + top.linkTo(parent.top) + bottom.linkTo(parent.bottom) + start.linkTo(parent.start) + end.linkTo(parent.end) + } + }, + modifier = Modifier + .fillMaxSize() + ) { + Column(modifier = Modifier.layoutId("layout")) { + val componentModifiers = Modifier + .align(CenterHorizontally) + .padding(6.dp) + lateinit var picker: NumberPicker + Row(modifier = componentModifiers) { + Text(stringResource(R.string.number_of_switch_preferences)) + picker = NumberPicker(context).apply { + minValue = 1 + maxValue = 10 + value = 3 + } + } + Button( + onClick = { openSettingsCodeConfig(picker.value) }, + modifier = componentModifiers, + ) { + Text( + text = stringResource(R.string.open_settings_code), + color = MaterialTheme.colors.onPrimary + ) + } + Button( + onClick = { openSettingsXmlConfig() }, + modifier = componentModifiers + ) { + Text( + text = stringResource(R.string.open_settings_xml), + color = MaterialTheme.colors.onPrimary + ) + } + Button( + onClick = { openSettingsPaged() }, + modifier = componentModifiers + ) { + Text( + text = stringResource(R.string.open_settings_paged), + color = MaterialTheme.colors.onPrimary + ) + } + Spacer(Modifier.height(50.dp)) + Text( + text = stringResource(R.string.value_input_preference_, inputPrefState.orEmpty()), + modifier = componentModifiers, + textAlign = TextAlign.Center, + color = MaterialTheme.colors.onBackground + ) + } + } + } + + private fun openSettingsCodeConfig(numberOfSwitchPreferences: Int) { val config = SimpleSettingsConfig.Builder() .displayHomeAsUpEnabled(true) .setOptionsMenu(R.menu.menu_settings, this) @@ -170,7 +239,7 @@ class MainActivity : AppCompatActivity(), SimpleSettingsConfig.OptionsItemSelect overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right) } - fun openSettingsXmlConfig(view: View) { + private fun openSettingsXmlConfig() { val config = SimpleSettingsConfig.Builder() .displayHomeAsUpEnabled(true) .setOptionsMenu(R.menu.menu_settings, this) @@ -188,7 +257,7 @@ class MainActivity : AppCompatActivity(), SimpleSettingsConfig.OptionsItemSelect overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right) } - fun openSettingsPaged(view: View) { + private fun openSettingsPaged() { val config = SimpleSettingsConfig.Builder() .displayHomeAsUpEnabled(true) .setOptionsMenu(R.menu.menu_settings, this) @@ -266,12 +335,6 @@ class MainActivity : AppCompatActivity(), SimpleSettingsConfig.OptionsItemSelect } } - private fun subscribeToPreferenceValues() { - getPrefObserver( this, "inputpreference", Observer { - inputPreferenceValue.text = getString(R.string.value_input_preference_, it) - }) - } - override fun onPreferenceClick(context: Context, key: String): Preference.OnPreferenceClickListener? { return when(key) { "preference" -> WebsiteClickListener(this, getString(R.string.github_link)) @@ -309,4 +372,4 @@ class MainActivity : AppCompatActivity(), SimpleSettingsConfig.OptionsItemSelect data = Uri.parse(getString(R.string.github_link)) }) } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/chillibits/simplesettingssample/Theming.kt b/app/src/main/java/com/chillibits/simplesettingssample/Theming.kt new file mode 100644 index 00000000..ebe8f8ab --- /dev/null +++ b/app/src/main/java/com/chillibits/simplesettingssample/Theming.kt @@ -0,0 +1,35 @@ +package com.chillibits.simplesettingssample + +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material.MaterialTheme +import androidx.compose.material.darkColors +import androidx.compose.material.lightColors +import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color + +private val LightColors = lightColors( + primary = Color(0xFF3DDC84), + primaryVariant = Color(0xFF32B56C), + secondary = Color(0xFFFF9800), + secondaryVariant = Color(0xFFFF9800) +) + +private val DarkColors = darkColors( + primary = Color(0xFF313131), + primaryVariant = Color(0xFF202020), + secondary = Color(0xFFBD7000), + secondaryVariant = Color(0xFFBD7000), + onPrimary = Color.White, + onBackground = Color.White +) + +@Composable +fun AppTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + content: @Composable () -> Unit +) { + MaterialTheme( + colors = if (darkTheme) DarkColors else LightColors, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index f8c9a319..00000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - - - - -