summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-03-28 12:40:47 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-28 15:22:06 -0600
commitd2f435b265d9fb532a824d2e29edf01257638f62 (patch)
tree26c99d20c38dc4939e683fe1d1038123f536b20d /ui/src/main
parent3a163acd6d0f7d533af4475d1f1a020cef4a1412 (diff)
ClipboardUtils: Update to handle TextInputEditText
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'ui/src/main')
-rw-r--r--ui/src/main/java/com/wireguard/android/util/ClipboardUtils.kt21
1 files changed, 12 insertions, 9 deletions
diff --git a/ui/src/main/java/com/wireguard/android/util/ClipboardUtils.kt b/ui/src/main/java/com/wireguard/android/util/ClipboardUtils.kt
index c1ddaa4c..51f6486f 100644
--- a/ui/src/main/java/com/wireguard/android/util/ClipboardUtils.kt
+++ b/ui/src/main/java/com/wireguard/android/util/ClipboardUtils.kt
@@ -6,10 +6,11 @@ package com.wireguard.android.util
import android.content.ClipData
import android.content.ClipboardManager
-import android.content.Context
import android.view.View
import android.widget.TextView
+import androidx.core.content.getSystemService
import com.google.android.material.snackbar.Snackbar
+import com.google.android.material.textfield.TextInputEditText
/**
* Standalone utilities for interacting with the system clipboard.
@@ -17,14 +18,16 @@ import com.google.android.material.snackbar.Snackbar
object ClipboardUtils {
@JvmStatic
fun copyTextView(view: View) {
- if (view !is TextView)
+ val data = when (view) {
+ is TextInputEditText -> Pair(view.editableText, view.hint)
+ is TextView -> Pair(view.text, view.contentDescription)
+ else -> return
+ }
+ if (data.first == null || data.first.isEmpty()) {
return
- val text = view.text
- if (text == null || text.length == 0) return
- val service = view.getContext().getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
- ?: return
- val description = view.getContentDescription()
- service.setPrimaryClip(ClipData.newPlainText(description, text))
- Snackbar.make(view, "$description copied to clipboard", Snackbar.LENGTH_LONG).show()
+ }
+ val service = view.context.getSystemService<ClipboardManager>() ?: return
+ service.setPrimaryClip(ClipData.newPlainText(data.second, data.first))
+ Snackbar.make(view, "${data.second} copied to clipboard", Snackbar.LENGTH_LONG).show()
}
}