From 4706b8f6a8d08a6961da6ab34d15881b63356d79 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 23 Jul 2017 13:13:36 -0700 Subject: Update kpref-activity's min-sdk and other minor changes (#11) * Move some resources to public * Lower kpref minsdk * Remove excess kauUtils annotations * Allow nullable throwable * Do not throw null throwable * Make image picker base abstract again * Migrate about strings to private * Update readme * Update readme * Update sample tagging * Update adapter readme --- .../ca/allanwang/kau/logging/TimberLogger.kt | 2 +- .../kotlin/ca/allanwang/kau/utils/AnimUtils.kt | 24 +++++++++++----------- .../kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 7 ++++--- core/src/main/res/values/strings.xml | 4 ++++ 4 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 core/src/main/res/values/strings.xml (limited to 'core/src') diff --git a/core/src/main/kotlin/ca/allanwang/kau/logging/TimberLogger.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/TimberLogger.kt index 5969fd5..e0f6cae 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/logging/TimberLogger.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/logging/TimberLogger.kt @@ -11,7 +11,7 @@ import timber.log.Timber open class TimberLogger(tag: String) { internal val TAG = "$tag: %s" fun e(s: String) = Timber.e(TAG, s) - fun e(t: Throwable, s: String = "error") = Timber.e(t, TAG, s) + fun e(t: Throwable?, s: String = "error") = if (t == null) e(s) else Timber.e(t, TAG, s) fun d(s: String) = Timber.d(TAG, s) fun i(s: String) = Timber.i(TAG, s) fun v(s: String) = Timber.v(TAG, s) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt index ed4b7bd..112c8ec 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt @@ -32,13 +32,13 @@ import android.widget.TextView val anim = ViewAnimationUtils.createCircularReveal(this, x, y, 0f, r).setDuration(duration) anim.startDelay = offset anim.addListener(object : AnimatorListenerAdapter() { - override @KauUtils fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator?) { visible() onStart?.invoke() } - override @KauUtils fun onAnimationEnd(animation: Animator?) = onFinish?.invoke() ?: Unit - override @KauUtils fun onAnimationCancel(animation: Animator?) = onFinish?.invoke() ?: Unit + override fun onAnimationEnd(animation: Animator?) = onFinish?.invoke() ?: Unit + override fun onAnimationCancel(animation: Animator?) = onFinish?.invoke() ?: Unit }) anim.start() } @@ -59,14 +59,14 @@ import android.widget.TextView val anim = ViewAnimationUtils.createCircularReveal(this, x, y, r, 0f).setDuration(duration) anim.startDelay = offset anim.addListener(object : AnimatorListenerAdapter() { - override @KauUtils fun onAnimationStart(animation: Animator?) = onStart?.invoke() ?: Unit + override fun onAnimationStart(animation: Animator?) = onStart?.invoke() ?: Unit - override @KauUtils fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator?) { invisible() onFinish?.invoke() ?: Unit } - override @KauUtils fun onAnimationCancel(animation: Animator?) = onFinish?.invoke() ?: Unit + override fun onAnimationCancel(animation: Animator?) = onFinish?.invoke() ?: Unit }) anim.start() } @@ -82,9 +82,9 @@ import android.widget.TextView anim.startOffset = offset anim.duration = duration anim.setAnimationListener(object : Animation.AnimationListener { - override @KauUtils fun onAnimationRepeat(animation: Animation?) {} - override @KauUtils fun onAnimationEnd(animation: Animation?) = onFinish?.invoke() ?: Unit - override @KauUtils fun onAnimationStart(animation: Animation?) { + override fun onAnimationRepeat(animation: Animation?) {} + override fun onAnimationEnd(animation: Animation?) = onFinish?.invoke() ?: Unit + override fun onAnimationStart(animation: Animation?) { visible() onStart?.invoke() } @@ -103,13 +103,13 @@ import android.widget.TextView anim.startOffset = offset anim.duration = duration anim.setAnimationListener(object : Animation.AnimationListener { - override @KauUtils fun onAnimationRepeat(animation: Animation?) {} - override @KauUtils fun onAnimationEnd(animation: Animation?) { + override fun onAnimationRepeat(animation: Animation?) {} + override fun onAnimationEnd(animation: Animation?) { invisible() onFinish?.invoke() } - override @KauUtils fun onAnimationStart(animation: Animation?) { + override fun onAnimationStart(animation: Animation?) { onStart?.invoke() } }) 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 bf30a91..7a92665 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -169,13 +169,14 @@ inline val Context.isNavBarOnBottom: Boolean fun Context.hasPermission(permissions: String) = !buildIsMarshmallowAndUp || ContextCompat.checkSelfPermission(this, permissions) == PackageManager.PERMISSION_GRANTED -fun Context.copyToClipboard(text: String, label: String = "Copied Text", showToast: Boolean = true) { +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.primaryClip = ClipData.newPlainText(label, text ?: "") if (showToast) toast(R.string.kau_text_copied) } -fun Context.shareText(text: String) { +fun Context.shareText(text: String?) { + if (text == null) return toast(R.string.kau_text_is_null) val intent = Intent(Intent.ACTION_SEND) intent.type = "text/plain" intent.putExtra(Intent.EXTRA_TEXT, text) diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml new file mode 100644 index 0000000..d8b2993 --- /dev/null +++ b/core/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + Text is null + \ No newline at end of file -- cgit v1.2.3