diff options
author | Allan Wang <me@allanwang.ca> | 2017-09-24 16:56:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-24 16:56:11 -0400 |
commit | 1edb6e1ac1297f6feb229d8f89e07a88de1ae2e9 (patch) | |
tree | 5009d1486f2e1ccc0ddff88bbf0ad51b9d20e1e7 /core | |
parent | c465bd64a7da087447659b83ed515d87ee8d342f (diff) | |
download | kau-1edb6e1ac1297f6feb229d8f89e07a88de1ae2e9.tar.gz kau-1edb6e1ac1297f6feb229d8f89e07a88de1ae2e9.tar.bz2 kau-1edb6e1ac1297f6feb229d8f89e07a88de1ae2e9.zip |
v3.4.3 (#65)3.4.3
* fix/mediapicker (#50)
* Bring all glide request managers to one instance
* Switch to test implementation
* Check if parent is null for searchview
* Ensure open close runs on ui thread
* Make glide contract internal
* Update changelog
* Update version
Update changelog for previous prs
* v3.4.1 (#63)
* Check browser intent before launching (#54)
* Update changelog
* fix/misc (#55)
* Add kapt plugin
* Fix kau vector
* Debug lintRelease
* Revert debug
* Update dependencies
* Check context finishing state before showing dialog (#61)
* Keep copy of shared pref rather than application context (#60)
* Keep copy of shared pref rather than application context
* Add back preference name
* Add resolver checks (#62)
Squashed commit of the following:
commit 7fe57d4ab1dbfe8bfb4d4a15bd0fbf636da491fa
Author: Allan Wang <me@allanwang.ca>
Date: Sat Sep 23 15:25:18 2017 -0400
Add missing quote
commit ffc3ac99248c2250a7f14ef709f37d787cbe0d83
Author: Allan Wang <me@allanwang.ca>
Date: Sat Sep 23 15:20:54 2017 -0400
Update changelog
Update gradle
Update version name
* Fix bundle NPE for activity creation
Update changelog
* Feature/kpref time picker (#64)
* Init kpref time builder and open up other builders
* Enable self refresh
* Add readme
* Update changelog
* Update readme
Diffstat (limited to 'core')
-rw-r--r-- | core/README.md | 4 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 6 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 20 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt | 20 | ||||
-rw-r--r-- | core/src/main/res/values/ids.xml | 1 |
5 files changed, 33 insertions, 18 deletions
diff --git a/core/README.md b/core/README.md index 4cb68d0..39899dd 100644 --- a/core/README.md +++ b/core/README.md @@ -178,7 +178,7 @@ KAU's swipe is a Kotlin rewrite, along with support for all directions and weakl # Debounce Debouncing is a means of throttling a function so that it is called no more than once in a given instance of time. -An example where you'd like this behaviour is the searchview; you want to deliver search results quickly, +An example where you'd like this behaviour is the searchview: you want to deliver search results quickly, but you don't want to update your response with each new character. Instead, you can wait until a user finishes their query, then search for the results. @@ -210,7 +210,7 @@ Include your email and subject, along with other optional configurations such as ## Extension Functions > "[Extensions](https://kotlinlang.org/docs/reference/extensions.html) provide the ability to extend a class with new functionality without having to inherit from the class" -Note that since KAU depends on [ANKO](https://github.com/Kotlin/anko), all of the extensions in its core package is also in KAU. +<br/>Note that since KAU depends on [ANKO](https://github.com/Kotlin/anko), all of the extensions in its core package is also in KAU. KAU's vast collection of extensions is one of its strongest features. There are too many to explain here, but you may check out the [utils package](https://github.com/AllanWang/KAU/tree/master/core/src/main/kotlin/ca/allanwang/kau/utils) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt index 5631e70..33bdc62 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -32,9 +32,9 @@ fun Activity.startActivityForResult( bundle: Bundle? = null, intentBuilder: Intent.() -> Unit = {}) { val intent = Intent(this, clazz) - val fullBundle = if (transition && buildIsLollipopAndUp) - ActivityOptions.makeSceneTransitionAnimation(this).toBundle() - else Bundle() + val fullBundle = Bundle() + if (transition && buildIsLollipopAndUp) + fullBundle.with(ActivityOptions.makeSceneTransitionAnimation(this).toBundle()) if (bundle != null) fullBundle.putAll(bundle) intent.intentBuilder() startActivityForResult(intent, requestCode, if (fullBundle.isEmpty) null else fullBundle) 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 a72c7dd..0664dc6 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -43,9 +43,9 @@ fun Context.startActivity( intentBuilder: Intent.() -> Unit = {}) { val intent = Intent(this, clazz) if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) - val fullBundle = if (transition && this is Activity && buildIsLollipopAndUp) - ActivityOptions.makeSceneTransitionAnimation(this).toBundle() - else Bundle() + val fullBundle = Bundle() + if (transition && this is Activity && buildIsLollipopAndUp) + fullBundle.with(ActivityOptions.makeSceneTransitionAnimation(this).toBundle()) if (transition && this !is Activity) KL.d("Cannot make scene transition when context is not an instance of an Activity") if (bundle != null) fullBundle.putAll(bundle) intent.intentBuilder() @@ -57,9 +57,10 @@ fun Context.startActivity( * Bring in activity from the right */ fun Context.startActivitySlideIn(clazz: Class<out Activity>, clearStack: Boolean = false, intentBuilder: Intent.() -> Unit = {}, bundleBuilder: Bundle.() -> Unit = {}) { - val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_slide_in_right, R.anim.kau_fade_out).toBundle() - bundle.bundleBuilder() - startActivity(clazz, clearStack, intentBuilder = intentBuilder, bundle = bundle) + val fullBundle = Bundle() + fullBundle.with(ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_slide_in_right, R.anim.kau_fade_out).toBundle()) + fullBundle.bundleBuilder() + startActivity(clazz, clearStack, intentBuilder = intentBuilder, bundle = if (fullBundle.isEmpty) null else fullBundle) } /** @@ -69,9 +70,10 @@ fun Context.startActivitySlideIn(clazz: Class<out Activity>, clearStack: Boolean * Consequently, the stack will be cleared by default */ fun Context.startActivitySlideOut(clazz: Class<out Activity>, clearStack: Boolean = true, intentBuilder: Intent.() -> Unit = {}, bundleBuilder: Bundle.() -> Unit = {}) { - val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_fade_in, R.anim.kau_slide_out_right_top).toBundle() - bundle.bundleBuilder() - startActivity(clazz, clearStack, intentBuilder = intentBuilder, bundle = bundle) + val fullBundle = Bundle() + fullBundle.with(ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_fade_in, R.anim.kau_slide_out_right_top).toBundle()) + fullBundle.bundleBuilder() + startActivity(clazz, clearStack, intentBuilder = intentBuilder, bundle = if (fullBundle.isEmpty) null else fullBundle) } fun Context.startPlayStoreLink(@StringRes packageIdRes: Int) = startPlayStoreLink(string(packageIdRes)) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index 50a3c29..954bedc 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -6,6 +6,7 @@ import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable +import android.os.Bundle import android.os.Handler import android.os.Looper import android.support.annotation.IntRange @@ -53,14 +54,16 @@ annotation class KauUtils * Converts minute value to string * Whole hours and days will be converted as such, otherwise it will default to x minutes */ -@KauUtils fun Context.minuteToText(minutes: Long): String = with(minutes) { +@KauUtils +fun Context.minuteToText(minutes: Long): String = with(minutes) { if (this < 0L) string(R.string.kau_none) else if (this % 1440L == 0L) plural(R.plurals.kau_x_days, this / 1440L) else if (this % 60L == 0L) plural(R.plurals.kau_x_hours, this / 60L) else plural(R.plurals.kau_x_minutes, this) } -@KauUtils fun Number.round(@IntRange(from = 1L) decimalCount: Int): String { +@KauUtils +fun Number.round(@IntRange(from = 1L) decimalCount: Int): String { val expression = StringBuilder().append("#.") (1..decimalCount).forEach { expression.append("#") } val formatter = DecimalFormat(expression.toString()) @@ -72,7 +75,8 @@ annotation class KauUtils * Extracts the bitmap of a drawable, and applies a scale if given * For solid colors, a 1 x 1 pixel will be generated */ -@KauUtils fun Drawable.toBitmap(scaling: Float = 1f, config: Bitmap.Config = Bitmap.Config.ARGB_8888): Bitmap { +@KauUtils +fun Drawable.toBitmap(scaling: Float = 1f, config: Bitmap.Config = Bitmap.Config.ARGB_8888): Bitmap { if (this is BitmapDrawable && bitmap != null) { if (scaling == 1f) return bitmap val width = (bitmap.width * scaling).toInt() @@ -122,4 +126,12 @@ class KauException(message: String) : RuntimeException(message) fun String.withMaxLength(n: Int): String = if (length <= n) this - else substring(0, n-1) + KAU_ELLIPSIS
\ No newline at end of file + else substring(0, n - 1) + KAU_ELLIPSIS + +/** + * Similar to [Bundle.putAll], but checks for a null insert and returns the parent bundle + */ +fun Bundle.with(bundle: Bundle?): Bundle { + if (bundle != null) putAll(bundle) + return this +}
\ No newline at end of file diff --git a/core/src/main/res/values/ids.xml b/core/src/main/res/values/ids.xml index c4912e2..28ff9d9 100644 --- a/core/src/main/res/values/ids.xml +++ b/core/src/main/res/values/ids.xml @@ -14,6 +14,7 @@ <item name="kau_item_pref_plain_text" type="id"/> <item name="kau_item_pref_seekbar" type="id"/> <item name="kau_item_pref_sub_item" type="id"/> + <item name="kau_item_pref_time_picker" type="id"/> <item name="kau_item_pref_text" type="id"/> <item name="kau_item_search" type="id"/> <item name="kau_pref_inner_content" type="id"/> |