Fix: operate clipboard on main thread

This commit is contained in:
kr328 2022-05-16 20:00:48 +08:00
parent b472580ca6
commit a405372f6a
2 changed files with 8 additions and 13 deletions

View File

@ -76,11 +76,8 @@ class AccessControlActivity : BaseActivity<AccessControlDesign>() {
val data = clipboard?.primaryClip
if (data != null && data.itemCount > 0) {
val all = withContext(Dispatchers.IO) {
val packages = data.getItemAt(0).text.split("\n").toSet()
design.apps.map(AppInfo::packageName).intersect(packages)
}
val packages = data.getItemAt(0).text.split("\n").toSet()
val all = design.apps.map(AppInfo::packageName).intersect(packages)
selected.clear()
selected.addAll(all)
@ -91,14 +88,12 @@ class AccessControlActivity : BaseActivity<AccessControlDesign>() {
AccessControlDesign.Request.Export -> {
val clipboard = getSystemService<ClipboardManager>()
withContext(Dispatchers.IO) {
val data = ClipData.newPlainText(
"packages",
selected.joinToString("\n")
)
val data = ClipData.newPlainText(
"packages",
selected.joinToString("\n")
)
clipboard?.setPrimaryClip(data)
}
clipboard?.setPrimaryClip(data)
}
}
}

View File

@ -26,7 +26,7 @@ class LogcatDesign(
private val binding = DesignLogcatBinding
.inflate(context.layoutInflater, context.root, false)
private val adapter = LogMessageAdapter(context) {
launch(Dispatchers.IO) {
launch {
val data = ClipData.newPlainText("log_message", it.message)
context.getSystemService<ClipboardManager>()?.setPrimaryClip(data)