diff --git a/CHANGES.md b/CHANGES.md index 5b598a57..fbd38522 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ Features: Improvements: - Handle click on redacted events: view source and create permalink - Improve long tap menu: reply on top, more compact (#368) - - Quick reply in timeline with swipe gesture + - Quick reply in timeline with swipe gesture (#167) - Improve edit of replies Other changes: @@ -19,6 +19,7 @@ Bugfix: - Fix crash reported by the PlayStore (#341) - Fix Chat composer separator color in dark/black theme - Fix bad layout for room directory filter (#349) + - Fix Copying link from a message shouldn't open context menu (#364) Translations: - diff --git a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt index f387b296..9c7b7938 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt @@ -28,6 +28,7 @@ import android.os.Build import android.os.PowerManager import android.provider.Settings import android.widget.Toast +import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import im.vector.riotx.R @@ -81,11 +82,11 @@ fun requestDisablingBatteryOptimization(activity: Activity, fragment: Fragment?, * @param context the context * @param text the text to copy */ -fun copyToClipboard(context: Context, text: CharSequence, showToast: Boolean = true) { +fun copyToClipboard(context: Context, text: CharSequence, showToast: Boolean = true, @StringRes toastMessage : Int = R.string.copied_to_clipboard) { val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager clipboard.primaryClip = ClipData.newPlainText("", text) if (showToast) { - context.toast(R.string.copied_to_clipboard) + context.toast(toastMessage) } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index e0f67aaf..c8e2d944 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -602,7 +602,7 @@ class RoomDetailFragment : override fun onUrlLongClicked(url: String): Boolean { // Copy the url to the clipboard - copyToClipboard(requireContext(), url) + copyToClipboard(requireContext(), url, true, R.string.link_copied_to_clipboard) return true } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt index b5074882..fc867b12 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt @@ -16,6 +16,7 @@ package im.vector.riotx.features.home.room.detail.timeline.item +import android.view.MotionEvent import androidx.appcompat.widget.AppCompatTextView import androidx.core.text.PrecomputedTextCompat import androidx.core.text.toSpannable @@ -40,14 +41,23 @@ abstract class MessageTextItem : AbsMessageItem() { @EpoxyAttribute var urlClickCallback: TimelineEventController.UrlClickCallback? = null + // Better link movement methods fixes the issue when + // long pressing to open the context menu on a TextView also triggers an autoLink click. private val mvmtMethod = BetterLinkMovementMethod.newInstance().also { it.setOnLinkClickListener { _, url -> //Return false to let android manage the click on the link, or true if the link is handled by the application urlClickCallback?.onUrlClicked(url) == true } - it.setOnLinkLongClickListener { _, url -> + //We need also to fix the case when long click on link will trigger long click on cell + it.setOnLinkLongClickListener { tv, url -> //Long clicks are handled by parent, return true to block android to do something with url - urlClickCallback?.onUrlLongClicked(url) == true + if (urlClickCallback?.onUrlLongClicked(url) == true) { + tv.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0f, 0f, 0)) + true + } else { + false + } + } } diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index a777e85f..f6ec4892 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -36,4 +36,7 @@ Enable swipe to reply in timeline + + Link copied to clipboard + \ No newline at end of file