diff options
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 10 |
1 files changed, 9 insertions, 1 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 21021e2..bc01919 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -2,6 +2,8 @@ package ca.allanwang.kau.utils import android.app.Activity import android.app.ActivityOptions +import android.content.ClipData +import android.content.ClipboardManager import android.content.Context import android.content.Intent import android.content.pm.PackageManager @@ -162,4 +164,10 @@ inline val Context.isNavBarOnBottom: Boolean return !canMove || dm.widthPixels < dm.heightPixels } -fun Context.hasPermission(permissions: String) = !buildIsMarshmallowAndUp || ContextCompat.checkSelfPermission(this, permissions) == PackageManager.PERMISSION_GRANTED
\ No newline at end of file +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) { + val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + clipboard.primaryClip = ClipData.newPlainText(label, text) + if (showToast) toast(R.string.kau_text_copied) +}
\ No newline at end of file |