Fix Copying link from a message shouldn't open context menu

This commit is contained in:
Valere 2019-07-15 19:03:52 +02:00 committed by Benoit Marty
parent 927cd7285d
commit 22dc2a6790
5 changed files with 21 additions and 6 deletions

View File

@ -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:
-

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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<MessageTextItem.Holder>() {
@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
}
}
}

View File

@ -36,4 +36,7 @@
<string name="labs_swipe_to_reply_in_timeline">Enable swipe to reply in timeline</string>
<string name="link_copied_to_clipboard">Link copied to clipboard</string>
</resources>