From 66b76adbb22203069f5526accc3501cbdb5e4936 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Wed, 6 Apr 2016 09:38:12 +0800 Subject: [PATCH] improved link click --- .../util/TwitterDateConverterTest.java | 39 ------------------- .../hotmobi/util/TwidereDataUtils.java | 2 - .../twidere/fragment/StatusFragment.java | 4 -- .../twidere/fragment/UserFragment.java | 4 -- .../twidere/text/TwidereURLSpan.java | 5 +-- .../twidere/util/OnLinkClickHandler.java | 4 -- .../twidere/util/TwidereLinkify.java | 29 +------------- 7 files changed, 3 insertions(+), 84 deletions(-) delete mode 100644 twidere/src/androidTest/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverterTest.java diff --git a/twidere/src/androidTest/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverterTest.java b/twidere/src/androidTest/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverterTest.java deleted file mode 100644 index 4c676b5e9..000000000 --- a/twidere/src/androidTest/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverterTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.mariotaku.twidere.api.twitter.util; - -import org.junit.Test; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Locale; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * Created by mariotaku on 16/1/29. - */ -public class TwitterDateConverterTest { - - private final TwitterDateConverter converter = new TwitterDateConverter(); - private final SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss ZZZZZ yyyy", Locale.ENGLISH); - - @Test - public void testGetFromString() throws Exception { - testDate("Fri Jan 29 04:12:49 +0100 2016"); - testDate("Thu Jan 28 11:08:47 +0000 2016"); - testDate("Sat Oct 03 16:05:32 +0000 2015"); - testDate("Tue Jan 26 18:30:19 +0100 2016"); - assertNull(converter.getFromString("Tue Jan 26 18:30:19 +0100")); - assertNull(converter.getFromString("Tue")); - assertNull(converter.getFromString("++++")); - } - - private void testDate(String s) throws ParseException { - assertEquals(converter.getFromString(s), format.parse(s)); - } - - @Test - public void testConvertToString() throws Exception { - - } -} \ No newline at end of file diff --git a/twidere/src/main/java/edu/tsinghua/hotmobi/util/TwidereDataUtils.java b/twidere/src/main/java/edu/tsinghua/hotmobi/util/TwidereDataUtils.java index e7b67734d..da485e622 100644 --- a/twidere/src/main/java/edu/tsinghua/hotmobi/util/TwidereDataUtils.java +++ b/twidere/src/main/java/edu/tsinghua/hotmobi/util/TwidereDataUtils.java @@ -43,8 +43,6 @@ public class TwidereDataUtils { return "urlLink"; case TwidereLinkify.LINK_TYPE_LIST: return "userList"; - case TwidereLinkify.LINK_TYPE_STATUS: - return "status"; case TwidereLinkify.LINK_TYPE_USER_ID: return "userID"; case TwidereLinkify.LINK_TYPE_HASHTAG: diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/StatusFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/StatusFragment.java index a6a8dda97..f9d7ec89f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/StatusFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/StatusFragment.java @@ -1614,10 +1614,6 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac expandOrOpenMedia(current); return; } - if (type == TwidereLinkify.LINK_TYPE_STATUS && TextUtils.equals(status.id, link)) { - expandOrOpenMedia(null); - return; - } super.onLinkClick(link, orig, accountKey, extraId, type, sensitive, start, end); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/UserFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/UserFragment.java index 1f78fed41..e8ed3cde0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/UserFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/UserFragment.java @@ -1379,10 +1379,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } break; } - case TwidereLinkify.LINK_TYPE_STATUS: { - IntentUtils.openStatus(getActivity(), accountKey, link); - break; - } } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java b/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java index 1e9bc944f..ebf98ed1d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java +++ b/twidere/src/main/java/org/mariotaku/twidere/text/TwidereURLSpan.java @@ -33,7 +33,7 @@ public class TwidereURLSpan extends URLSpan implements Constants { private final int type, highlightStyle; private final UserKey accountKey; private final long extraId; - private final String url, orig; + private final String orig; private final boolean sensitive; private final OnLinkClickListener listener; private final int start, end; @@ -42,7 +42,6 @@ public class TwidereURLSpan extends URLSpan implements Constants { final int type, final boolean sensitive, final int highlightStyle, int start, int end, final OnLinkClickListener listener) { super(url); - this.url = url; this.orig = orig; this.accountKey = accountKey; this.extraId = extraId; @@ -57,7 +56,7 @@ public class TwidereURLSpan extends URLSpan implements Constants { @Override public void onClick(@NonNull final View widget) { if (listener != null) { - listener.onLinkClick(url, orig, accountKey, extraId, type, sensitive, start, end); + listener.onLinkClick(getURL(), orig, accountKey, extraId, type, sensitive, start, end); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java index 4306ea81e..8df8144a6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/OnLinkClickHandler.java @@ -136,10 +136,6 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants { UserFragment.Referral.USER_MENTION); break; } - case TwidereLinkify.LINK_TYPE_STATUS: { - IntentUtils.openStatus(context, accountKey, link); - break; - } } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereLinkify.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereLinkify.java index 245f5071a..f56afae4c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereLinkify.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereLinkify.java @@ -68,10 +68,9 @@ public final class TwidereLinkify implements Constants { public static final int LINK_TYPE_LIST = 6; public static final int LINK_TYPE_CASHTAG = 7; public static final int LINK_TYPE_USER_ID = 8; - public static final int LINK_TYPE_STATUS = 9; public static final int[] ALL_LINK_TYPES = new int[]{LINK_TYPE_ENTITY_URL, LINK_TYPE_LINK_IN_TEXT, - LINK_TYPE_MENTION, LINK_TYPE_HASHTAG, LINK_TYPE_STATUS, LINK_TYPE_CASHTAG}; + LINK_TYPE_MENTION, LINK_TYPE_HASHTAG, LINK_TYPE_CASHTAG}; public static final String AVAILABLE_URL_SCHEME_PREFIX = "(https?://)?"; @@ -83,15 +82,8 @@ public final class TwidereLinkify implements Constants { public static final Pattern PATTERN_TWITTER_PROFILE_IMAGES = Pattern.compile(STRING_PATTERN_TWITTER_PROFILE_IMAGES, Pattern.CASE_INSENSITIVE); - public static final int GROUP_ID_TWITTER_STATUS_SCREEN_NAME = 4; - public static final int GROUP_ID_TWITTER_STATUS_STATUS_ID = 6; public static final int GROUP_ID_TWITTER_LIST_SCREEN_NAME = 4; public static final int GROUP_ID_TWITTER_LIST_LIST_NAME = 5; - private static final String STRING_PATTERN_TWITTER_STATUS_NO_SCHEME = "((mobile|www)\\.)?twitter\\.com/(?:#!/)?(\\w+)/status(es)?/(\\d+)(/photo/\\d)?/?"; - private static final String STRING_PATTERN_TWITTER_STATUS = AVAILABLE_URL_SCHEME_PREFIX - + STRING_PATTERN_TWITTER_STATUS_NO_SCHEME; - public static final Pattern PATTERN_TWITTER_STATUS = Pattern.compile(STRING_PATTERN_TWITTER_STATUS, - Pattern.CASE_INSENSITIVE); private static final String STRING_PATTERN_TWITTER_LIST_NO_SCHEME = "((mobile|www)\\.)?twitter\\.com/(?:#!/)?(\\w+)/lists/(.+)/?"; private static final String STRING_PATTERN_TWITTER_LIST = AVAILABLE_URL_SCHEME_PREFIX + STRING_PATTERN_TWITTER_LIST_NO_SCHEME; @@ -257,25 +249,6 @@ public final class TwidereLinkify implements Constants { } break; } - case LINK_TYPE_STATUS: { - if (accountKey == null || !USER_TYPE_TWITTER_COM.equals(accountKey.getHost())) { - break; - } - final int length = string.length(); - final URLSpan[] spans = string.getSpans(0, length, URLSpan.class); - for (final URLSpan span : spans) { - final Matcher matcher = PATTERN_TWITTER_STATUS.matcher(span.getURL()); - if (matcher.matches()) { - final int start = string.getSpanStart(span); - final int end = string.getSpanEnd(span); - final String url = matcherGroup(matcher, GROUP_ID_TWITTER_STATUS_STATUS_ID); - string.removeSpan(span); - applyLink(url, null, start, end, string, accountKey, extraId, - LINK_TYPE_STATUS, sensitive, highlightOption, listener); - } - } - break; - } case LINK_TYPE_CASHTAG: { addCashtagLinks(string, accountKey, extraId, listener, highlightOption); break;