aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-07-23 13:13:36 -0700
committerGitHub <noreply@github.com>2017-07-23 13:13:36 -0700
commit4706b8f6a8d08a6961da6ab34d15881b63356d79 (patch)
tree3d1e611e43bd589a98a5f1840c5b6f52ff254468 /core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
parent61d87976e8b29ed25061ae98743a6cf4f4274542 (diff)
downloadkau-4706b8f6a8d08a6961da6ab34d15881b63356d79.tar.gz
kau-4706b8f6a8d08a6961da6ab34d15881b63356d79.tar.bz2
kau-4706b8f6a8d08a6961da6ab34d15881b63356d79.zip
Update kpref-activity's min-sdk and other minor changes (#11)3.1.0
* 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
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt7
1 files changed, 4 insertions, 3 deletions
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)