From a83dd51f545dda905194ea84caed6e2906b0f06f Mon Sep 17 00:00:00 2001 From: AllanWang Date: Sun, 9 Sep 2018 13:06:49 -0400 Subject: Add initial progress animator change --- docs/Migration.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/Migration.md') diff --git a/docs/Migration.md b/docs/Migration.md index 721cd0d..c9e39b8 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -8,6 +8,9 @@ Along with the update to support Android Studio 3.1, a lot of changes have occur * Resource ids can be negatives due to the bit overflow. Instead, `INVALID_ID` has been introduced to signify an unset or invalid id. Methods such as `Context.string(id, fallback)` now check against `INVALID_ID` through equality rather than using an inequality to address this. +* Kotterknife has been deprecated in favour of `kotlin-android-extensions`. See [official docs](https://kotlinlang.org/docs/tutorials/android-plugin.html#view-binding). +* `ProgressAnimator` has been completely rewritten to be an extension of `ValueAnimator`. +This for the most part is not a breaking change, apart from the fact that creating an animator will not start it immediately. # v3.6.0 -- cgit v1.2.3 From 3ac791b744a56138501c9530fa6df8dcb0756739 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 26 Sep 2018 10:21:30 -0400 Subject: Update kpref tests and migration --- .../kotlin/ca/allanwang/kau/kpref/KPrefTest.kt | 26 ++++++++++++++-------- .../kotlin/ca/allanwang/kau/email/EmailBuilder.kt | 7 +++++- .../kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt | 4 ++-- .../ca/allanwang/kau/kpref/KPrefTransaction.kt | 8 +++---- docs/Migration.md | 1 + 5 files changed, 30 insertions(+), 16 deletions(-) (limited to 'docs/Migration.md') 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 e806a3f..2a9263a 100644 --- a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt +++ b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt @@ -16,40 +16,46 @@ import kotlin.test.assertTrue */ @RunWith(AndroidJUnit4::class) @MediumTest -class ChangelogTest { +class KPrefTest { lateinit var pref: TestPref class TestPref : KPref() { + init { initialize(InstrumentationRegistry.getTargetContext(), "kpref_test_${System.currentTimeMillis()}") } - var one: Int by kpref("one", 1) + var one by kpref("one", 1) + + var two by kpref("two", 2f) - var `true`: Boolean by kpref("true", true) + var `true` by kpref("true", true) - var hello: String by kpref("hello", "hello") + var hello by kpref("hello", "hello") - var set: StringSet by kpref("set", setOf("po", "ta", "to")) + var set by kpref("set", setOf("po", "ta", "to")) - val oneShot: Boolean by kprefSingle("asdf") + val oneShot by kprefSingle("asdf") } @Before fun init() { pref = TestPref() + pref.sp.edit().clear().commit() } @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") } @Test @@ -60,6 +66,7 @@ class ChangelogTest { pref.hello = "goodbye" assertEquals("goodbye", pref.hello) assertEquals(pref.hello, pref.sp.getString("hello", "hello")) + assertEquals(2, pref.sp.all.size) } @SuppressLint("CommitPrefEdits") @@ -67,12 +74,13 @@ class ChangelogTest { 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) + assertEquals(2, pref.one, "Kpref did not properly fetch from shared prefs") pref.sp.edit().putInt("one", -1).commit() - assertEquals(2, pref.one) //our lazy delegate still retains the old value + assertEquals(2, pref.one, "Lazy kpref should still retain old value") pref.reset() - assertEquals(-1, pref.one) //back in sync with sp + assertEquals(-1, pref.one, "Kpref did not refetch from shared prefs upon reset") } diff --git a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt index c94b06d..dbdcf09 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -69,9 +69,14 @@ class EmailBuilder(val email: String, val subject: String) { if (appInfo) { try { val appInfo = context.packageManager.getPackageInfo(context.packageName, 0) + val versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + appInfo.longVersionCode.toString() + } else { + appInfo.versionCode.toString() + } emailBuilder.append("\nApp: ").append(context.packageName) .append("\nApp Version Name: ").append(appInfo.versionName) - .append("\nApp Version Code: ").append(appInfo.longVersionCode).append("\n") + .append("\nApp Version Code: ").append(versionCode).append("\n") } catch (e: PackageManager.NameNotFoundException) { KL.e { "EmailBuilder packageInfo not found" } } 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 2630884..b80479e 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt @@ -21,8 +21,8 @@ fun KPref.kpref(key: String, fallback: Int, postSetter: (value: Int) -> Unit = { 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(it ?: emptySet()) } +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) 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 d02cf06..773d208 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefTransaction.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefTransaction.kt @@ -52,11 +52,11 @@ internal object KPrefStringTransaction : KPrefTransaction { } } -internal object KPrefSetTransaction : KPrefTransaction?> { - override fun get(prefs: SharedPreferences, key: String, fallback: Set?) = - prefs.getStringSet(key, fallback) +internal object KPrefSetTransaction : KPrefTransaction> { + override fun get(prefs: SharedPreferences, key: String, fallback: Set) = + prefs.getStringSet(key, fallback)!! - override fun set(editor: SharedPreferences.Editor, key: String, data: Set?) { + override fun set(editor: SharedPreferences.Editor, key: String, data: Set) { editor.putStringSet(key, data) } } diff --git a/docs/Migration.md b/docs/Migration.md index c9e39b8..ce27225 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -11,6 +11,7 @@ Methods such as `Context.string(id, fallback)` now check against `INVALID_ID` th * Kotterknife has been deprecated in favour of `kotlin-android-extensions`. See [official docs](https://kotlinlang.org/docs/tutorials/android-plugin.html#view-binding). * `ProgressAnimator` has been completely rewritten to be an extension of `ValueAnimator`. This for the most part is not a breaking change, apart from the fact that creating an animator will not start it immediately. +* KPref has been slightly refactored internally. Preferences backed by `StringSet` can now go back to `Set` # v3.6.0 -- cgit v1.2.3 From be1d7bef2299824ebf9f4f6250838c3d215913cd Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 8 Oct 2018 15:52:39 -0400 Subject: Update migration doc --- docs/Migration.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'docs/Migration.md') diff --git a/docs/Migration.md b/docs/Migration.md index fe04270..e112850 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -11,10 +11,6 @@ Along with the update to support Android Studio 3.1, a lot of changes have occur Resource ids can be negatives due to the bit overflow. Instead, `INVALID_ID` has been introduced to signify an unset or invalid id. Methods such as `Context.string(id, fallback)` now check against `INVALID_ID` through equality rather than using an inequality to address this. -* Kotterknife has been deprecated in favour of `kotlin-android-extensions`. See [official docs](https://kotlinlang.org/docs/tutorials/android-plugin.html#view-binding). -* `ProgressAnimator` has been completely rewritten to be an extension of `ValueAnimator`. -This for the most part is not a breaking change, apart from the fact that creating an animator will not start it immediately. -* KPref has been slightly refactored internally. Preferences backed by `StringSet` can now go back to `Set` ## Deprecate Kotterknife @@ -26,6 +22,11 @@ See [official docs](https://kotlinlang.org/docs/tutorials/android-plugin.html#vi KPref has been slightly refactored internally. Preferences backed by `StringSet` can now go back to `Set` +## Update ProgressAnimator + +`ProgressAnimator` has been completely rewritten to be an extension of `ValueAnimator`. +This for the most part is not a breaking change, apart from the fact that creating an animator will not start it immediately. + # v3.6.0 ## startActivity -- cgit v1.2.3 From 81739fa76510003b2acc51822d1e9258ddc8d536 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 8 Oct 2018 15:56:52 -0400 Subject: Move progress animator migration to 4.0.0 --- docs/Migration.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'docs/Migration.md') diff --git a/docs/Migration.md b/docs/Migration.md index e112850..ea30c0d 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -2,6 +2,13 @@ Below are some highlights on major refactoring/breaking changes +# v4.0.0 + +## Update ProgressAnimator + +`ProgressAnimator` has been completely rewritten to be an extension of `ValueAnimator`. +This for the most part is not a breaking change, apart from the fact that creating an animator will not start it immediately. + # v3.8.0 Along with the update to support Android Studio 3.1, a lot of changes have occurred with other dependencies and with lint. @@ -22,11 +29,6 @@ See [official docs](https://kotlinlang.org/docs/tutorials/android-plugin.html#vi KPref has been slightly refactored internally. Preferences backed by `StringSet` can now go back to `Set` -## Update ProgressAnimator - -`ProgressAnimator` has been completely rewritten to be an extension of `ValueAnimator`. -This for the most part is not a breaking change, apart from the fact that creating an animator will not start it immediately. - # v3.6.0 ## startActivity -- cgit v1.2.3