improved link click
This commit is contained in:
parent
a2ddb653d3
commit
66b76adbb2
|
@ -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 {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -43,8 +43,6 @@ public class TwidereDataUtils {
|
||||||
return "urlLink";
|
return "urlLink";
|
||||||
case TwidereLinkify.LINK_TYPE_LIST:
|
case TwidereLinkify.LINK_TYPE_LIST:
|
||||||
return "userList";
|
return "userList";
|
||||||
case TwidereLinkify.LINK_TYPE_STATUS:
|
|
||||||
return "status";
|
|
||||||
case TwidereLinkify.LINK_TYPE_USER_ID:
|
case TwidereLinkify.LINK_TYPE_USER_ID:
|
||||||
return "userID";
|
return "userID";
|
||||||
case TwidereLinkify.LINK_TYPE_HASHTAG:
|
case TwidereLinkify.LINK_TYPE_HASHTAG:
|
||||||
|
|
|
@ -1614,10 +1614,6 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||||
expandOrOpenMedia(current);
|
expandOrOpenMedia(current);
|
||||||
return;
|
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);
|
super.onLinkClick(link, orig, accountKey, extraId, type, sensitive, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1379,10 +1379,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TwidereLinkify.LINK_TYPE_STATUS: {
|
|
||||||
IntentUtils.openStatus(getActivity(), accountKey, link);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class TwidereURLSpan extends URLSpan implements Constants {
|
||||||
private final int type, highlightStyle;
|
private final int type, highlightStyle;
|
||||||
private final UserKey accountKey;
|
private final UserKey accountKey;
|
||||||
private final long extraId;
|
private final long extraId;
|
||||||
private final String url, orig;
|
private final String orig;
|
||||||
private final boolean sensitive;
|
private final boolean sensitive;
|
||||||
private final OnLinkClickListener listener;
|
private final OnLinkClickListener listener;
|
||||||
private final int start, end;
|
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 int type, final boolean sensitive, final int highlightStyle, int start, int end,
|
||||||
final OnLinkClickListener listener) {
|
final OnLinkClickListener listener) {
|
||||||
super(url);
|
super(url);
|
||||||
this.url = url;
|
|
||||||
this.orig = orig;
|
this.orig = orig;
|
||||||
this.accountKey = accountKey;
|
this.accountKey = accountKey;
|
||||||
this.extraId = extraId;
|
this.extraId = extraId;
|
||||||
|
@ -57,7 +56,7 @@ public class TwidereURLSpan extends URLSpan implements Constants {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NonNull final View widget) {
|
public void onClick(@NonNull final View widget) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onLinkClick(url, orig, accountKey, extraId, type, sensitive, start, end);
|
listener.onLinkClick(getURL(), orig, accountKey, extraId, type, sensitive, start, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,10 +136,6 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
|
||||||
UserFragment.Referral.USER_MENTION);
|
UserFragment.Referral.USER_MENTION);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TwidereLinkify.LINK_TYPE_STATUS: {
|
|
||||||
IntentUtils.openStatus(context, accountKey, link);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,9 @@ public final class TwidereLinkify implements Constants {
|
||||||
public static final int LINK_TYPE_LIST = 6;
|
public static final int LINK_TYPE_LIST = 6;
|
||||||
public static final int LINK_TYPE_CASHTAG = 7;
|
public static final int LINK_TYPE_CASHTAG = 7;
|
||||||
public static final int LINK_TYPE_USER_ID = 8;
|
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,
|
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?://)?";
|
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,
|
public static final Pattern PATTERN_TWITTER_PROFILE_IMAGES = Pattern.compile(STRING_PATTERN_TWITTER_PROFILE_IMAGES,
|
||||||
Pattern.CASE_INSENSITIVE);
|
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_SCREEN_NAME = 4;
|
||||||
public static final int GROUP_ID_TWITTER_LIST_LIST_NAME = 5;
|
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_NO_SCHEME = "((mobile|www)\\.)?twitter\\.com/(?:#!/)?(\\w+)/lists/(.+)/?";
|
||||||
private static final String STRING_PATTERN_TWITTER_LIST = AVAILABLE_URL_SCHEME_PREFIX
|
private static final String STRING_PATTERN_TWITTER_LIST = AVAILABLE_URL_SCHEME_PREFIX
|
||||||
+ STRING_PATTERN_TWITTER_LIST_NO_SCHEME;
|
+ STRING_PATTERN_TWITTER_LIST_NO_SCHEME;
|
||||||
|
@ -257,25 +249,6 @@ public final class TwidereLinkify implements Constants {
|
||||||
}
|
}
|
||||||
break;
|
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: {
|
case LINK_TYPE_CASHTAG: {
|
||||||
addCashtagLinks(string, accountKey, extraId, listener, highlightOption);
|
addCashtagLinks(string, accountKey, extraId, listener, highlightOption);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue