From 5f051a97667f9e1b546363121a890443cb36e005 Mon Sep 17 00:00:00 2001 From: Alexander-- Date: Thu, 14 Nov 2019 20:50:35 +0659 Subject: [PATCH] More fixes to comment focus handling --- .../holder/CommentsMiniInfoItemHolder.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java index e7b09f3e2..198766069 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java @@ -126,14 +126,28 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { } private void allowLinkFocus() { + itemContentView.setMovementMethod(LinkMovementMethod.getInstance()); + } + + private void denyLinkFocus() { + itemContentView.setMovementMethod(null); + } + + private boolean shouldFocusLinks() { if (itemView.isInTouchMode()) { - return; + return false; } URLSpan[] urls = itemContentView.getUrls(); - if (urls != null && urls.length != 0) { - itemContentView.setMovementMethod(LinkMovementMethod.getInstance()); + return urls != null && urls.length != 0; + } + + private void determineLinkFocus() { + if (shouldFocusLinks()) { + allowLinkFocus(); + } else { + denyLinkFocus(); } } @@ -151,8 +165,10 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { linkify(); - if (!hasEllipsis) { - allowLinkFocus(); + if (hasEllipsis) { + denyLinkFocus(); + } else { + determineLinkFocus(); } } @@ -168,13 +184,11 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { itemContentView.setMaxLines(commentExpandedLines); itemContentView.setText(commentText); linkify(); - allowLinkFocus(); + determineLinkFocus(); } private void linkify(){ Linkify.addLinks(itemContentView, Linkify.WEB_URLS); Linkify.addLinks(itemContentView, pattern, null, null, timestampLink); - - itemContentView.setMovementMethod(null); } }