From 6f97fd5f7c528594899e66d2d8b502a20ade6f53 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 13 Jun 2019 13:29:07 -0700 Subject: Revert iconics updates for now --- docs/Migration.md | 4 ---- 1 file changed, 4 deletions(-) (limited to 'docs') diff --git a/docs/Migration.md b/docs/Migration.md index 58667ca..a7162fa 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -29,10 +29,6 @@ For instance, instead of using `kauDependencies`, we now use `kau.Dependencies`. There is also no longer a need to use `apply plugin 'ca.allanwang.kau'`; adding the plugin to the classpath suffices. -## Iconics - -With an iconics update, most of the package names have changed. - # v4.0.1-alpha02 * `kauParseFaq` is now synchronous. -- cgit v1.2.3 From e1849c9c633047979d8017262041e925ec3bd219 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 13 Jun 2019 13:51:52 -0700 Subject: Update to sdk 29 and update changelog --- buildSrc/src/main/kotlin/kau/Versions.kt | 4 ++-- core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefTransaction.kt | 2 +- core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 2 +- docs/Changelog.md | 3 +++ sample/src/main/res/xml/kau_changelog.xml | 5 +++-- 5 files changed, 10 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/buildSrc/src/main/kotlin/kau/Versions.kt b/buildSrc/src/main/kotlin/kau/Versions.kt index 7133ed5..515f702 100644 --- a/buildSrc/src/main/kotlin/kau/Versions.kt +++ b/buildSrc/src/main/kotlin/kau/Versions.kt @@ -3,10 +3,10 @@ package kau object Versions { const val coreMinSdk = 19 const val minSdk = 21 - const val targetSdk = 28 + const val targetSdk = 29 // https://developer.android.com/studio/releases/build-tools - const val buildTools = "28.0.3" + const val buildTools = "29.0.0" // https://mvnrepository.com/artifact/androidx.appcompat/appcompat?repo=google const val appcompat = "1.0.2" diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefTransaction.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefTransaction.kt index 1070e11..3f8fe28 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefTransaction.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefTransaction.kt @@ -60,7 +60,7 @@ internal object KPrefFloatTransaction : KPrefTransaction { internal object KPrefStringTransaction : KPrefTransaction { override fun get(prefs: SharedPreferences, key: String, fallback: String) = - prefs.getString(key, fallback) + prefs.getString(key, fallback) ?: "" override fun set(editor: SharedPreferences.Editor, key: String, data: String) { editor.putString(key, data) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt index e8680dc..d002fb8 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -239,7 +239,7 @@ fun Context.hasPermission(permissions: String) = !buildIsMarshmallowAndUp || Con fun Context.copyToClipboard(text: String?, label: String = "Copied Text", showToast: Boolean = true) { val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - clipboard.primaryClip = ClipData.newPlainText(label, text ?: "") + clipboard.setPrimaryClip(ClipData.newPlainText(label, text ?: "")) if (showToast) toast(R.string.kau_text_copied) } diff --git a/docs/Changelog.md b/docs/Changelog.md index 61e5fb7..689fbd9 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,8 +1,11 @@ # Changelog ## v5.0.0 +* Update Android SDK to 29 and Kotlin to 1.3.31 * :core: Update Material Dialogs to 3.x +* :core: Change ProgressAnimator API * :colorpicker: Strip down to just the interface; unless you require the accent palette, it may be fine to just use MD's color extension +* :gradle-plugin: Convert to kotlin, rework dependencies, and remove extension hooks ## v4.1.0 * :core: Deprecate NetworkUtils, as the underlying functions are deprecated diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index 53265d0..b5ec47c 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -7,10 +7,11 @@ --> + + - - + -- cgit v1.2.3 From c84edb5a6656cf3fcd10dfb05727b0f3bad5a37d Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 13 Jun 2019 20:28:37 -0700 Subject: Update changelog --- docs/Changelog.md | 1 + sample/src/main/res/xml/kau_changelog.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/Changelog.md b/docs/Changelog.md index 689fbd9..795b860 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -4,6 +4,7 @@ * Update Android SDK to 29 and Kotlin to 1.3.31 * :core: Update Material Dialogs to 3.x * :core: Change ProgressAnimator API +* :core: Remove cursor tinting in EditText as it used reflection * :colorpicker: Strip down to just the interface; unless you require the accent palette, it may be fine to just use MD's color extension * :gradle-plugin: Convert to kotlin, rework dependencies, and remove extension hooks diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index b5ec47c..d6e3d99 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -10,10 +10,10 @@ + - -- cgit v1.2.3 From 8725ae5647e15a38281ca6778b33413490dff91b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 13 Jun 2019 21:36:04 -0700 Subject: Translations (#207) * New translations strings_about.xml (Arabic) * New translations strings_colorpicker.xml (Arabic) * New translations strings_commons.xml (Arabic) * New translations strings_mediapicker.xml (Arabic) * New translations strings_about.xml (Afrikaans) * New translations strings_colorpicker.xml (Russian) * New translations strings_about.xml (Russian) * New translations strings_mediapicker.xml (Romanian) * New translations strings_commons.xml (Romanian) * New translations strings_colorpicker.xml (Romanian) * New translations strings_about.xml (Romanian) * New translations strings_mediapicker.xml (Russian) * New translations strings_mediapicker.xml (Japanese) * New translations strings_commons.xml (Japanese) * New translations strings_colorpicker.xml (Japanese) * New translations strings_commons.xml (Russian) * New translations strings_mediapicker.xml (Tagalog) * New translations strings_commons.xml (Tagalog) * New translations strings_colorpicker.xml (Tagalog) * New translations strings_about.xml (Tagalog) * New translations strings_about.xml (Japanese) * New translations strings_colorpicker.xml (Afrikaans) * New translations strings_mediapicker.xml (Czech) * New translations strings_commons.xml (Czech) * New translations strings_colorpicker.xml (Czech) * New translations strings_about.xml (Czech) * New translations strings_about.xml (Finnish) * New translations strings_mediapicker.xml (Catalan) * New translations strings_commons.xml (Catalan) * New translations strings_colorpicker.xml (Catalan) * New translations strings_about.xml (Catalan) * New translations strings_mediapicker.xml (Afrikaans) * New translations strings_commons.xml (Afrikaans) * New translations strings_colorpicker.xml (Finnish) * New translations strings_commons.xml (Greek) * New translations strings_mediapicker.xml (Hebrew) * New translations strings_commons.xml (Hebrew) * New translations strings_colorpicker.xml (Hebrew) * New translations strings_about.xml (Hebrew) * New translations strings_mediapicker.xml (Greek) * New translations strings_colorpicker.xml (Greek) * New translations strings_commons.xml (Finnish) * New translations strings_about.xml (Greek) * New translations strings_mediapicker.xml (Finnish) * New translations strings_about.xml (Tamil) * New translations strings_colorpicker.xml (Tamil) * New translations strings_commons.xml (Tamil) * New translations strings_mediapicker.xml (Tamil) * New translations strings_mediapicker.xml (Arabic) * New translations strings_commons.xml (Arabic) * New translations strings_about.xml (Arabic) * Add credits * Delete blank translations * Update changelog --- README.md | 1 + about/src/main/res/values-ar-rSA/strings_about.xml | 6 +++ .../res-public/values-ar-rSA/strings_commons.xml | 55 ++++++++++++++++++++++ docs/Changelog.md | 1 + files/translation_migration.sh | 0 .../main/res/values-ar-rSA/strings_mediapicker.xml | 11 +++++ sample/src/main/res/xml/kau_changelog.xml | 1 + 7 files changed, 75 insertions(+) create mode 100644 about/src/main/res/values-ar-rSA/strings_about.xml create mode 100644 core/src/main/res-public/values-ar-rSA/strings_commons.xml mode change 100644 => 100755 files/translation_migration.sh create mode 100644 mediapicker/src/main/res/values-ar-rSA/strings_mediapicker.xml (limited to 'docs') diff --git a/README.md b/README.md index 0059e47..2c72eb1 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ Special thanks to the following awesome people for translating significant porti | Language | Contributors | |----------|--------------| +| Arabic | [Mohammed Qubati](https://crowdin.com/profile/Mrkqubati) | | Chinese (Simplified) | [Alcatelia](https://crowdin.com/profile/Alcatelia) | | Chinese (Traditional) | [yipinghuang](https://crowdin.com/profile/yipinghuang) • [Su, Jun-Ming](https://crowdin.com/profile/sujunmin) • [Wei](https://crowdin.com/profile/wei4green) | | Danish | [mhtorp](https://crowdin.com/profile/mhtorp) | diff --git a/about/src/main/res/values-ar-rSA/strings_about.xml b/about/src/main/res/values-ar-rSA/strings_about.xml new file mode 100644 index 0000000..f80ee4d --- /dev/null +++ b/about/src/main/res/values-ar-rSA/strings_about.xml @@ -0,0 +1,6 @@ + + + + لن يتم تمكين هذا التطبيق بدون المكتبات الكبيرة التالية. + الأسئلة الشائعة + diff --git a/core/src/main/res-public/values-ar-rSA/strings_commons.xml b/core/src/main/res-public/values-ar-rSA/strings_commons.xml new file mode 100644 index 0000000..efaa623 --- /dev/null +++ b/core/src/main/res-public/values-ar-rSA/strings_commons.xml @@ -0,0 +1,55 @@ + + + + + عن التطبيق + حول %s + إضافة حساب + العودة + إلغاء + سجل التغييرات + إغلاق + التواصل معنا + نسخ + مخصص + مظلم + الافتراضي + لا تظهر مجدداً + تم + خطأ + خروج + هل أنت متأكد بأنك تريد الخروج؟ + هل أنت متأكد بأنك تريد الخروج %s؟ + زجاجي + فهمت + رائع + إخفاء + فاتح + تسجيل الدخول + تسجيل الخروج + هل أنت متأكد بأنك تريد تسجيل الخروج %s؟ + إدارة الحساب + ربما + القائمة + لا + لم يتم العثور على نتائج + لا يوجد + حسناً + Google play + تقييم + الإبلاغ عن خطأ + البحث + إرسال ملاحظات + الإرسال عبر + الاعدادات + المشاركة + تم نسخ النص إلى الحافظة. + شكراً + أوبس + تحذير + نعم + الإذن مرفوض + diff --git a/docs/Changelog.md b/docs/Changelog.md index 795b860..c68629f 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -2,6 +2,7 @@ ## v5.0.0 * Update Android SDK to 29 and Kotlin to 1.3.31 +* Update translations * :core: Update Material Dialogs to 3.x * :core: Change ProgressAnimator API * :core: Remove cursor tinting in EditText as it used reflection diff --git a/files/translation_migration.sh b/files/translation_migration.sh old mode 100644 new mode 100755 diff --git a/mediapicker/src/main/res/values-ar-rSA/strings_mediapicker.xml b/mediapicker/src/main/res/values-ar-rSA/strings_mediapicker.xml new file mode 100644 index 0000000..c05d161 --- /dev/null +++ b/mediapicker/src/main/res/values-ar-rSA/strings_mediapicker.xml @@ -0,0 +1,11 @@ + + + + لم يتم العثور على أي عنصر + لم يتم إختيار أي عنصر + لم يتم تحميل أي عنصر + لا توجد كاميرا + يرجى تثبيت تطبيق كاميرا والمحاولة مجدداً. + فشل في حفظ صورة مؤقتة. + اختيار وسائط + diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index d6e3d99..d59ce53 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -8,6 +8,7 @@ + -- cgit v1.2.3 From b360c95e93afc39f2c8043d6087035e1c661e478 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 17 Jun 2019 23:45:13 -0700 Subject: Update triple t contents --- docs/Changelog.md | 3 +++ sample/src/main/play/contact-email.txt | 1 + sample/src/main/play/contactEmail | 1 - sample/src/main/play/default-language.txt | 1 + sample/src/main/play/defaultLanguage | 1 - sample/src/main/play/en-CA/listing/fulldescription | 3 --- sample/src/main/play/en-CA/listing/shortdescription | 1 - sample/src/main/play/en-CA/listing/title | 1 - sample/src/main/play/en-CA/whatsnew | 1 - sample/src/main/play/listings/en-CA/listing/full-description.txt | 3 +++ sample/src/main/play/listings/en-CA/listing/short-description.txt | 1 + sample/src/main/play/listings/en-CA/listing/title-txt | 1 + sample/src/main/play/release-notes/en-CA/default.txt | 1 + sample/src/main/res/xml/kau_changelog.xml | 7 +++++++ 14 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 sample/src/main/play/contact-email.txt delete mode 100644 sample/src/main/play/contactEmail create mode 100644 sample/src/main/play/default-language.txt delete mode 100644 sample/src/main/play/defaultLanguage delete mode 100644 sample/src/main/play/en-CA/listing/fulldescription delete mode 100644 sample/src/main/play/en-CA/listing/shortdescription delete mode 100644 sample/src/main/play/en-CA/listing/title delete mode 100644 sample/src/main/play/en-CA/whatsnew create mode 100644 sample/src/main/play/listings/en-CA/listing/full-description.txt create mode 100644 sample/src/main/play/listings/en-CA/listing/short-description.txt create mode 100644 sample/src/main/play/listings/en-CA/listing/title-txt create mode 100644 sample/src/main/play/release-notes/en-CA/default.txt (limited to 'docs') diff --git a/docs/Changelog.md b/docs/Changelog.md index c68629f..2c653e0 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,5 +1,8 @@ # Changelog +## v5.0.1 +* :adapter: Moved fastadapter elements to new module, :fastadapter:. To migrate, simply rename the dependency. If you don't use fast adapter, no changes are necessary + ## v5.0.0 * Update Android SDK to 29 and Kotlin to 1.3.31 * Update translations diff --git a/sample/src/main/play/contact-email.txt b/sample/src/main/play/contact-email.txt new file mode 100644 index 0000000..3e03392 --- /dev/null +++ b/sample/src/main/play/contact-email.txt @@ -0,0 +1 @@ +pitchedapps@gmail.com \ No newline at end of file diff --git a/sample/src/main/play/contactEmail b/sample/src/main/play/contactEmail deleted file mode 100644 index 3e03392..0000000 --- a/sample/src/main/play/contactEmail +++ /dev/null @@ -1 +0,0 @@ -pitchedapps@gmail.com \ No newline at end of file diff --git a/sample/src/main/play/default-language.txt b/sample/src/main/play/default-language.txt new file mode 100644 index 0000000..ffdd217 --- /dev/null +++ b/sample/src/main/play/default-language.txt @@ -0,0 +1 @@ +en-CA \ No newline at end of file diff --git a/sample/src/main/play/defaultLanguage b/sample/src/main/play/defaultLanguage deleted file mode 100644 index ffdd217..0000000 --- a/sample/src/main/play/defaultLanguage +++ /dev/null @@ -1 +0,0 @@ -en-CA \ No newline at end of file diff --git a/sample/src/main/play/en-CA/listing/fulldescription b/sample/src/main/play/en-CA/listing/fulldescription deleted file mode 100644 index 2d9fe89..0000000 --- a/sample/src/main/play/en-CA/listing/fulldescription +++ /dev/null @@ -1,3 +0,0 @@ -This app aims to demonstrate the features available in KAU, or Kotlin Android Utils. - -The project is open sourced on github \ No newline at end of file diff --git a/sample/src/main/play/en-CA/listing/shortdescription b/sample/src/main/play/en-CA/listing/shortdescription deleted file mode 100644 index 9424ee8..0000000 --- a/sample/src/main/play/en-CA/listing/shortdescription +++ /dev/null @@ -1 +0,0 @@ -A simple showcase for Kotlin Android Utils \ No newline at end of file diff --git a/sample/src/main/play/en-CA/listing/title b/sample/src/main/play/en-CA/listing/title deleted file mode 100644 index c3c5422..0000000 --- a/sample/src/main/play/en-CA/listing/title +++ /dev/null @@ -1 +0,0 @@ -KAU - Library Showcase \ No newline at end of file diff --git a/sample/src/main/play/en-CA/whatsnew b/sample/src/main/play/en-CA/whatsnew deleted file mode 100644 index 1d15ce2..0000000 --- a/sample/src/main/play/en-CA/whatsnew +++ /dev/null @@ -1 +0,0 @@ -A full changelog is available in the app \ No newline at end of file diff --git a/sample/src/main/play/listings/en-CA/listing/full-description.txt b/sample/src/main/play/listings/en-CA/listing/full-description.txt new file mode 100644 index 0000000..2d9fe89 --- /dev/null +++ b/sample/src/main/play/listings/en-CA/listing/full-description.txt @@ -0,0 +1,3 @@ +This app aims to demonstrate the features available in KAU, or Kotlin Android Utils. + +The project is open sourced on github \ No newline at end of file diff --git a/sample/src/main/play/listings/en-CA/listing/short-description.txt b/sample/src/main/play/listings/en-CA/listing/short-description.txt new file mode 100644 index 0000000..9424ee8 --- /dev/null +++ b/sample/src/main/play/listings/en-CA/listing/short-description.txt @@ -0,0 +1 @@ +A simple showcase for Kotlin Android Utils \ No newline at end of file diff --git a/sample/src/main/play/listings/en-CA/listing/title-txt b/sample/src/main/play/listings/en-CA/listing/title-txt new file mode 100644 index 0000000..c3c5422 --- /dev/null +++ b/sample/src/main/play/listings/en-CA/listing/title-txt @@ -0,0 +1 @@ +KAU - Library Showcase \ No newline at end of file diff --git a/sample/src/main/play/release-notes/en-CA/default.txt b/sample/src/main/play/release-notes/en-CA/default.txt new file mode 100644 index 0000000..1d15ce2 --- /dev/null +++ b/sample/src/main/play/release-notes/en-CA/default.txt @@ -0,0 +1 @@ +A full changelog is available in the app \ No newline at end of file diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index d59ce53..301193a 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -6,6 +6,13 @@ --> + + + + + + + -- cgit v1.2.3 From 1f9198a1c05223edc7abb095f483d02cda5f1122 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 1 Jul 2019 14:39:46 -0700 Subject: Add in memory kpref variant --- .../kotlin/ca/allanwang/kau/kpref/KPrefTest.kt | 75 +++++++++-------- .../main/kotlin/ca/allanwang/kau/kpref/KPref.kt | 10 ++- .../kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt | 75 +++++++++++++++++ .../kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt | 96 ++++++++++++++-------- .../ca/allanwang/kau/kpref/KPrefSingleDelegate.kt | 58 +++++++++++-- docs/Changelog.md | 1 + 6 files changed, 237 insertions(+), 78 deletions(-) create mode 100644 core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt (limited to 'docs') diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt index 29f5af1..735302c 100644 --- a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt +++ b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt @@ -24,8 +24,6 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue /** * Created by Allan Wang on 2017-08-01. @@ -34,9 +32,10 @@ import kotlin.test.assertTrue @MediumTest class KPrefTest { - lateinit var pref: TestPref + lateinit var androidPref: TestPref + lateinit var memPref: TestPref - class TestPref : KPref() { + class TestPref(builder: KPrefBuilder) : KPref(builder) { init { initialize(ApplicationProvider.getApplicationContext(), "kpref_test_${System.currentTimeMillis()}") @@ -57,51 +56,61 @@ class KPrefTest { @Before fun init() { - pref = TestPref() - pref.sp.edit().clear().commit() + androidPref = TestPref(KPrefBuilderAndroid) + androidPref.sp.edit().clear().commit() + memPref = TestPref(KPrefBuilderInMemory) + } + + private fun pref(action: TestPref.() -> Unit) { + androidPref.action() + memPref.action() + } + + private fun assertPrefEquals(expected: T, actual: TestPref.() -> T, message: String? = null) { + assertEquals(expected, androidPref.actual(), "Android KPrefs: $message") + assertEquals(expected, memPref.actual(), "In Mem KPrefs: $message") } @Test fun getDefaults() { - assertEquals(1, pref.one) - assertEquals(2f, pref.two) - assertEquals(true, pref.`true`) - assertEquals("hello", pref.hello) - assertEquals(3, pref.set.size) - assertTrue(pref.set.contains("po")) - assertTrue(pref.set.contains("ta")) - assertTrue(pref.set.contains("to")) - assertEquals(0, pref.sp.all.size, "Defaults should not be set automatically") + assertPrefEquals(1, { one }) + assertPrefEquals(2f, { two }) + assertPrefEquals(true, { `true` }) + assertPrefEquals("hello", { hello }) + assertPrefEquals(3, { set.size }) + assertPrefEquals(setOf("po", "ta", "to"), { set }) + assertEquals(0, androidPref.sp.all.size, "Defaults should not be set automatically") } @Test fun setter() { - assertEquals(1, pref.one) - pref.one = 2 - assertEquals(2, pref.one) - pref.hello = "goodbye" - assertEquals("goodbye", pref.hello) - assertEquals(pref.hello, pref.sp.getString("hello", "hello")) - assertEquals(2, pref.sp.all.size) + assertPrefEquals(1, { one }) + pref { one = 2 } + assertPrefEquals(2, { one }) + pref { hello = "goodbye" } + assertPrefEquals("goodbye", { hello }) + assertEquals(androidPref.hello, androidPref.sp.getString("hello", "badfallback")) + assertEquals(2, androidPref.sp.all.size) } @SuppressLint("CommitPrefEdits") @Test fun reset() { - pref.one = 2 - assertEquals(2, pref.one) - assertEquals(6, pref.prefMap.size, "Prefmap does not have all elements") - pref.reset() //only invalidates our lazy delegate; doesn't change the actual pref - assertEquals(2, pref.one, "Kpref did not properly fetch from shared prefs") - pref.sp.edit().putInt("one", -1).commit() - assertEquals(2, pref.one, "Lazy kpref should still retain old value") - pref.reset() - assertEquals(-1, pref.one, "Kpref did not refetch from shared prefs upon reset") + pref { one = 2 } + assertPrefEquals(2, { one }) + assertPrefEquals(6, { prefMap.size }, "Prefmap does not have all elements") + pref { reset() } //only invalidates our lazy delegate; doesn't change the actual pref + assertPrefEquals(2, { one }, "Kpref did not properly fetch from shared prefs") + // Android pref only + androidPref.sp.edit().putInt("one", -1).commit() + assertEquals(2, androidPref.one, "Lazy kpref should still retain old value") + androidPref.reset() + assertEquals(-1, androidPref.one, "Kpref did not refetch from shared prefs upon reset") } @Test fun single() { - assertTrue(pref.oneShot) - assertFalse(pref.oneShot) + assertPrefEquals(true, { oneShot }) + assertPrefEquals(false, { androidPref.oneShot }) } } diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt index 7a6330f..fc7a76a 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt @@ -36,14 +36,18 @@ import ca.allanwang.kau.logging.KL * You may optionally override [deleteKeys]. This will be called on initialization * And delete all keys returned from that method */ -open class KPref { +open class KPref(builder: KPrefBuilder = KPrefBuilderAndroid) : KPrefBuilder by builder { lateinit var PREFERENCE_NAME: String lateinit var sp: SharedPreferences - fun initialize(c: Context, preferenceName: String) { + fun initialize( + c: Context, + preferenceName: String, + sharedPrefs: SharedPreferences = c.applicationContext.getSharedPreferences(preferenceName, Context.MODE_PRIVATE) + ) { PREFERENCE_NAME = preferenceName - sp = c.applicationContext.getSharedPreferences(preferenceName, Context.MODE_PRIVATE) + sp = sharedPrefs KL.d { "Shared Preference $preferenceName has been initialized" } val toDelete = deleteKeys() if (toDelete.isNotEmpty()) { diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt new file mode 100644 index 0000000..4dd3012 --- /dev/null +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt @@ -0,0 +1,75 @@ +package ca.allanwang.kau.kpref + +interface KPrefBuilder { + fun KPref.kpref(key: String, fallback: Boolean, postSetter: (value: Boolean) -> Unit = {}): KPrefDelegate + + fun KPref.kpref(key: String, fallback: Float, postSetter: (value: Float) -> Unit = {}): KPrefDelegate + + @Deprecated( + "Double is not supported in SharedPreferences; cast to float yourself", + ReplaceWith("kpref(key, fallback.toFloat(), postSetter)"), + DeprecationLevel.WARNING + ) + fun KPref.kpref(key: String, fallback: Double, postSetter: (value: Float) -> Unit = {}): KPrefDelegate = + kpref(key, fallback.toFloat(), postSetter) + + fun KPref.kpref(key: String, fallback: Int, postSetter: (value: Int) -> Unit = {}): KPrefDelegate + + fun KPref.kpref(key: String, fallback: Long, postSetter: (value: Long) -> Unit = {}): KPrefDelegate + + fun KPref.kpref( + key: String, + fallback: Set, + postSetter: (value: Set) -> Unit = {} + ): KPrefDelegate> + + fun KPref.kpref(key: String, fallback: String, postSetter: (value: String) -> Unit = {}): KPrefDelegate + + fun KPref.kprefSingle(key: String): KPrefSingleDelegate +} + +object KPrefBuilderAndroid : KPrefBuilder { + + override fun KPref.kpref(key: String, fallback: Boolean, postSetter: (value: Boolean) -> Unit) = + KPrefDelegateAndroid(key, fallback, this, KPrefBooleanTransaction, postSetter) + + override fun KPref.kpref(key: String, fallback: Float, postSetter: (value: Float) -> Unit) = + KPrefDelegateAndroid(key, fallback, this, KPrefFloatTransaction, postSetter) + + override fun KPref.kpref(key: String, fallback: Int, postSetter: (value: Int) -> Unit) = + KPrefDelegateAndroid(key, fallback, this, KPrefIntTransaction, postSetter) + + override fun KPref.kpref(key: String, fallback: Long, postSetter: (value: Long) -> Unit) = + KPrefDelegateAndroid(key, fallback, this, KPrefLongTransaction, postSetter) + + override fun KPref.kpref(key: String, fallback: Set, postSetter: (value: Set) -> Unit) = + KPrefDelegateAndroid(key, fallback, this, KPrefSetTransaction, postSetter) + + override fun KPref.kpref(key: String, fallback: String, postSetter: (value: String) -> Unit) = + KPrefDelegateAndroid(key, fallback, this, KPrefStringTransaction, postSetter) + + override fun KPref.kprefSingle(key: String) = KPrefSingleDelegateAndroid(key, this) +} + +object KPrefBuilderInMemory : KPrefBuilder { + + override fun KPref.kpref(key: String, fallback: Boolean, postSetter: (value: Boolean) -> Unit) = + KPrefDelegateInMemory(key, fallback, this, postSetter) + + override fun KPref.kpref(key: String, fallback: Float, postSetter: (value: Float) -> Unit) = + KPrefDelegateInMemory(key, fallback, this, postSetter) + + override fun KPref.kpref(key: String, fallback: Int, postSetter: (value: Int) -> Unit) = + KPrefDelegateInMemory(key, fallback, this, postSetter) + + override fun KPref.kpref(key: String, fallback: Long, postSetter: (value: Long) -> Unit) = + KPrefDelegateInMemory(key, fallback, this, postSetter) + + override fun KPref.kpref(key: String, fallback: Set, postSetter: (value: Set) -> Unit) = + KPrefDelegateInMemory(key, fallback, this, postSetter) + + override fun KPref.kpref(key: String, fallback: String, postSetter: (value: String) -> Unit) = + KPrefDelegateInMemory(key, fallback, this, postSetter) + + override fun KPref.kprefSingle(key: String) = KPrefSingleDelegateInMemory(key, this) +} \ No newline at end of file diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt index 9813f24..684b139 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt @@ -17,32 +17,6 @@ package ca.allanwang.kau.kpref import ca.allanwang.kau.kotlin.ILazyResettable -fun KPref.kpref(key: String, fallback: Boolean, postSetter: (value: Boolean) -> Unit = {}) = - KPrefDelegate(key, fallback, this, KPrefBooleanTransaction, postSetter) - -fun KPref.kpref(key: String, fallback: Float, postSetter: (value: Float) -> Unit = {}) = - KPrefDelegate(key, fallback, this, KPrefFloatTransaction, postSetter) - -@Deprecated( - "Double is not supported in SharedPreferences; cast to float yourself", - ReplaceWith("kpref(key, fallback.toFloat(), postSetter)"), - DeprecationLevel.WARNING -) -fun KPref.kpref(key: String, fallback: Double, postSetter: (value: Float) -> Unit = {}) = - kpref(key, fallback.toFloat(), postSetter) - -fun KPref.kpref(key: String, fallback: Int, postSetter: (value: Int) -> Unit = {}) = - KPrefDelegate(key, fallback, this, KPrefIntTransaction, postSetter) - -fun KPref.kpref(key: String, fallback: Long, postSetter: (value: Long) -> Unit = {}) = - KPrefDelegate(key, fallback, this, KPrefLongTransaction, postSetter) - -fun KPref.kpref(key: String, fallback: Set, postSetter: (value: Set) -> Unit = {}) = - KPrefDelegate(key, fallback, this, KPrefSetTransaction, postSetter) - -fun KPref.kpref(key: String, fallback: String, postSetter: (value: String) -> Unit = {}) = - KPrefDelegate(key, fallback, this, KPrefStringTransaction, postSetter) - /** * Created by Allan Wang on 2017-06-07. * @@ -50,13 +24,20 @@ fun KPref.kpref(key: String, fallback: String, postSetter: (value: String) -> Un * Contains a unique key for the shared preference as well as a nonnull fallback item * Also contains an optional mutable postSetter that will be called every time a new value is given */ -class KPrefDelegate internal constructor( + +interface KPrefDelegate : ILazyResettable { + operator fun setValue(any: Any, property: kotlin.reflect.KProperty<*>, t: T) +} + +class KPrefException(message: String) : IllegalAccessException(message) + +class KPrefDelegateAndroid internal constructor( private val key: String, private val fallback: T, private val pref: KPref, private val transaction: KPrefTransaction, private var postSetter: (value: T) -> Unit = {} -) : ILazyResettable { +) : KPrefDelegate { private object UNINITIALIZED @@ -67,28 +48,26 @@ class KPrefDelegate internal constructor( init { if (pref.prefMap.containsKey(key)) throw KPrefException("$key is already used elsewhere in preference ${pref.PREFERENCE_NAME}") - pref.prefMap[key] = this@KPrefDelegate + pref.prefMap[key] = this@KPrefDelegateAndroid } override fun invalidate() { _value = UNINITIALIZED } + @Suppress("UNCHECKED_CAST") override val value: T get() { val _v1 = _value if (_v1 !== UNINITIALIZED) - @Suppress("UNCHECKED_CAST") return _v1 as T return synchronized(lock) { val _v2 = _value if (_v2 !== UNINITIALIZED) { - @Suppress("UNCHECKED_CAST") _v2 as T } else { _value = transaction.get(pref.sp, key, fallback) - @Suppress("UNCHECKED_CAST") _value as T } } @@ -98,7 +77,7 @@ class KPrefDelegate internal constructor( override fun toString(): String = if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet." - operator fun setValue(any: Any, property: kotlin.reflect.KProperty<*>, t: T) { + override operator fun setValue(any: Any, property: kotlin.reflect.KProperty<*>, t: T) { _value = t val editor = pref.sp.edit() transaction.set(editor, key, t) @@ -107,4 +86,53 @@ class KPrefDelegate internal constructor( } } -class KPrefException(message: String) : IllegalAccessException(message) +class KPrefDelegateInMemory internal constructor( + private val key: String, + private val fallback: T, + private val pref: KPref, + private var postSetter: (value: T) -> Unit = {} +) : KPrefDelegate { + + private object UNINITIALIZED + + @Volatile + private var _value: Any? = UNINITIALIZED + private val lock = this + + init { + if (pref.prefMap.containsKey(key)) + throw KPrefException("$key is already used elsewhere in preference ${pref.PREFERENCE_NAME}") + pref.prefMap[key] = this + } + + override fun invalidate() { + // No op + } + + @Suppress("UNCHECKED_CAST") + override val value: T + get() { + val _v1 = _value + if (_v1 !== UNINITIALIZED) + return _v1 as T + + return synchronized(lock) { + val _v2 = _value + if (_v2 !== UNINITIALIZED) { + _v2 as T + } else { + _value = fallback + _value as T + } + } + } + + override fun isInitialized(): Boolean = _value !== UNINITIALIZED + + override fun toString(): String = if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet." + + override operator fun setValue(any: Any, property: kotlin.reflect.KProperty<*>, t: T) { + _value = t + postSetter(t) + } +} diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt index 204e07e..ef59e78 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt @@ -17,8 +17,6 @@ package ca.allanwang.kau.kpref import ca.allanwang.kau.kotlin.ILazyResettable -fun KPref.kprefSingle(key: String) = KPrefSingleDelegate(key, this) - /** * Created by Allan Wang on 2017-06-07. * @@ -27,17 +25,21 @@ fun KPref.kprefSingle(key: String) = KPrefSingleDelegate(key, this) * All subsequent retrievals will be [false] * This is useful for one time toggles such as showcasing items */ -class KPrefSingleDelegate internal constructor(private val key: String, private val pref: KPref, lock: Any? = null) : - ILazyResettable { +interface KPrefSingleDelegate : ILazyResettable + +class KPrefSingleDelegateAndroid internal constructor( + private val key: String, + private val pref: KPref +) : KPrefSingleDelegate { @Volatile private var _value: Boolean? = null - private val lock = lock ?: this + private val lock = this init { if (pref.prefMap.containsKey(key)) throw KPrefException("$key is already used elsewhere in preference ${pref.PREFERENCE_NAME}") - pref.prefMap.put(key, this@KPrefSingleDelegate) + pref.prefMap[key] = this } override fun invalidate() { @@ -47,9 +49,9 @@ class KPrefSingleDelegate internal constructor(private val key: String, private override val value: Boolean get() { val _v1 = _value - if (_v1 != null) + if (_v1 != null) { return _v1 - + } return synchronized(lock) { val _v2 = _value if (_v2 != null) { @@ -69,3 +71,43 @@ class KPrefSingleDelegate internal constructor(private val key: String, private override fun toString(): String = if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet." } + +class KPrefSingleDelegateInMemory internal constructor( + private val key: String, + private val pref: KPref +) : KPrefSingleDelegate { + @Volatile + private var _value: Boolean? = null + private val lock = this + + init { + if (pref.prefMap.containsKey(key)) + throw KPrefException("$key is already used elsewhere in preference ${pref.PREFERENCE_NAME}") + pref.prefMap[key] = this + } + + override fun invalidate() { + // No op + } + + override val value: Boolean + get() { + val _v1 = _value + if (_v1 != null) { + return _v1 + } + return synchronized(lock) { + val _v2 = _value + if (_v2 != null) { + _v2 + } else { + _value = false + true + } + } + } + + override fun isInitialized(): Boolean = _value != null + + override fun toString(): String = if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet." +} \ No newline at end of file diff --git a/docs/Changelog.md b/docs/Changelog.md index 2c653e0..0ccf69c 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -2,6 +2,7 @@ ## v5.0.1 * :adapter: Moved fastadapter elements to new module, :fastadapter:. To migrate, simply rename the dependency. If you don't use fast adapter, no changes are necessary +* :adapter: Make NoAnimatorChange an object; previously a class ## v5.0.0 * Update Android SDK to 29 and Kotlin to 1.3.31 -- cgit v1.2.3 From 39bda3064e75a8a4be100afa4f5e7adee33c2f17 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 1 Jul 2019 14:44:34 -0700 Subject: Update changelog and add post setter test --- .../androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt | 12 +++++++++++- docs/Changelog.md | 2 ++ sample/src/main/res/xml/kau_changelog.xml | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'docs') diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt index 735302c..143b83f 100644 --- a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt +++ b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt @@ -41,11 +41,15 @@ class KPrefTest { initialize(ApplicationProvider.getApplicationContext(), "kpref_test_${System.currentTimeMillis()}") } + var postSetterCount: Int = 0 + var one by kpref("one", 1) var two by kpref("two", 2f) - var `true` by kpref("true", true) + var `true` by kpref("true", true, postSetter = { + postSetterCount++ + }) var hello by kpref("hello", "hello") @@ -113,4 +117,10 @@ class KPrefTest { assertPrefEquals(true, { oneShot }) assertPrefEquals(false, { androidPref.oneShot }) } + + @Test + fun postSetter() { + pref { `true` = true } + assertPrefEquals(1, { postSetterCount }, "Post setter was not called") + } } diff --git a/docs/Changelog.md b/docs/Changelog.md index 0ccf69c..b282830 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -3,6 +3,8 @@ ## v5.0.1 * :adapter: Moved fastadapter elements to new module, :fastadapter:. To migrate, simply rename the dependency. If you don't use fast adapter, no changes are necessary * :adapter: Make NoAnimatorChange an object; previously a class +* :core: KPref now supports in memory only variants for testing; pass KPrefBuilderInMemory to KPref constructor +* :core: KPref initializer takes in SharedPreferences so user can configure it ## v5.0.0 * Update Android SDK to 29 and Kotlin to 1.3.31 diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index 0e38015..6144685 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -9,8 +9,8 @@ - - + + -- cgit v1.2.3 From 6154ad0708be6b09acf8a3ff81b822fbf985e8d9 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 1 Jul 2019 14:52:52 -0700 Subject: Run release tests only --- .travis.yml | 2 +- docs/Changelog.md | 2 +- sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt | 1 - sample/src/main/res/xml/kau_changelog.xml | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/.travis.yml b/.travis.yml index 7f4d045..69dabb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ script: - chmod +x gradlew - "./gradlew --quiet androidGitVersion" - if [[ "$TRAVIS_BRANCH" == "master" ]]; then ./gradlew lintRelease publishRelease; - else ./gradlew lintRelease test; fi + else ./gradlew lintRelease testReleaseUnitTest; fi branches: except: - gh-pages diff --git a/docs/Changelog.md b/docs/Changelog.md index b282830..f8287ca 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,6 +1,6 @@ # Changelog -## v5.0.1 +## v5.1.0 * :adapter: Moved fastadapter elements to new module, :fastadapter:. To migrate, simply rename the dependency. If you don't use fast adapter, no changes are necessary * :adapter: Make NoAnimatorChange an object; previously a class * :core: KPref now supports in memory only variants for testing; pass KPrefBuilderInMemory to KPref constructor diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt index 0f20880..80a75bf 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt @@ -17,7 +17,6 @@ package ca.allanwang.kau.sample import android.graphics.Color import ca.allanwang.kau.kpref.KPref -import ca.allanwang.kau.kpref.kpref /** * Created by Allan Wang on 2017-06-07. diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index 6144685..62614ed 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -6,7 +6,7 @@ --> - + -- cgit v1.2.3