1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2024-12-18 11:39:10 +01:00

improved link click

This commit is contained in:
Mariotaku Lee 2016-04-06 09:38:12 +08:00
parent a2ddb653d3
commit 66b76adbb2
7 changed files with 3 additions and 84 deletions

View File

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

View File

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

View File

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

View File

@ -1379,10 +1379,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
}
break;
}
case TwidereLinkify.LINK_TYPE_STATUS: {
IntentUtils.openStatus(getActivity(), accountKey, link);
break;
}
}
}

View File

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

View File

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

View File

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