aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/README.md4
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt6
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt20
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt20
-rw-r--r--core/src/main/res/values/ids.xml1
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"/>