From 84486c7f134159ce7031ccb93a95fcc5a53173be Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Sun, 11 Jun 2023 18:39:48 +0200 Subject: [PATCH] Ensure textview fields can be copy/pasted (#3707) The Android libraries have a bug where a TextView can forget that it contains selectable text, can be pasted in to, etc. See https://issuetracker.google.com/issues/37095917 Fix this with an extension method that toggles the selectable state to re-enable it, and use this on the profile fields when editing an account. Fixes https://github.com/tuskyapp/Tusky/issues/3706 --- .../tusky/adapter/AccountFieldEditAdapter.kt | 5 +++++ .../com/keylesspalace/tusky/util/ViewExtensions.kt | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountFieldEditAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountFieldEditAdapter.kt index fc258f08..96774ac0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountFieldEditAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountFieldEditAdapter.kt @@ -22,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView import com.keylesspalace.tusky.databinding.ItemEditFieldBinding import com.keylesspalace.tusky.entity.StringField import com.keylesspalace.tusky.util.BindingHolder +import com.keylesspalace.tusky.util.fixTextSelection class AccountFieldEditAdapter : RecyclerView.Adapter>() { @@ -87,6 +88,10 @@ class AccountFieldEditAdapter : RecyclerView.Adapter fieldData[holder.bindingAdapterPosition].second = newText.toString() } + + // Ensure the textview contents are selectable + holder.binding.accountFieldNameText.fixTextSelection() + holder.binding.accountFieldValueText.fixTextSelection() } class MutableStringPair(var first: String, var second: String) diff --git a/app/src/main/java/com/keylesspalace/tusky/util/ViewExtensions.kt b/app/src/main/java/com/keylesspalace/tusky/util/ViewExtensions.kt index dc55ea52..392f65b7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/ViewExtensions.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/ViewExtensions.kt @@ -18,6 +18,7 @@ package com.keylesspalace.tusky.util import android.util.Log import android.view.View +import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.widget.ViewPager2 @@ -66,3 +67,14 @@ fun ViewPager2.reduceSwipeSensitivity() { Log.w("reduceSwipeSensitivity", e) } } + +/** + * TextViews with an ancestor RecyclerView can forget that they are selectable. Toggling + * calls to [TextView.setTextIsSelectable] fixes this. + * + * @see https://issuetracker.google.com/issues/37095917 + */ +fun TextView.fixTextSelection() { + setTextIsSelectable(false) + post { setTextIsSelectable(true) } +}