32 lines
No EOL
926 B
Kotlin
32 lines
No EOL
926 B
Kotlin
package com.tangem.devkit.extensions
|
|
|
|
import android.content.ClipData
|
|
import android.content.ClipboardManager
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.fragment.app.Fragment
|
|
|
|
/**
|
|
[REDACTED_AUTHOR]
|
|
*/
|
|
fun Context.copyToClipboard(value: Any, label: String = "") {
|
|
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager ?: return
|
|
|
|
val clip: ClipData = ClipData.newPlainText(label, value.toString())
|
|
clipboard.setPrimaryClip(clip)
|
|
}
|
|
|
|
fun Fragment.shareText(text: String) {
|
|
requireActivity().shareText(text)
|
|
}
|
|
|
|
fun ComponentActivity.shareText(text: String) {
|
|
val sendIntent: Intent = Intent().apply {
|
|
action = Intent.ACTION_SEND
|
|
putExtra(Intent.EXTRA_TEXT, text)
|
|
type = "text/plain"
|
|
}
|
|
val shareIntent = Intent.createChooser(sendIntent, null)
|
|
startActivity(shareIntent)
|
|
} |