This commit is contained in:
Mariotaku Lee 2016-04-17 11:54:43 +08:00
parent a6d24f81a3
commit 3629c4cba0
6 changed files with 77 additions and 45 deletions

View File

@ -85,6 +85,7 @@ public class WebLinkHandlerActivity extends Activity implements Constants {
}
}
if (handled.first != null) {
handled.first.putExtras(intent);
startActivity(handled.first);
} else {
if (!handled.second) {

View File

@ -1600,21 +1600,21 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
}
@Override
public void onLinkClick(final String link, final String orig, final UserKey accountKey,
long extraId, int type, boolean sensitive, int start, int end) {
public boolean onLinkClick(final String link, final String orig, final UserKey accountKey,
long extraId, int type, boolean sensitive, int start, int end) {
final ParcelableStatus status = adapter.getStatus();
ParcelableMedia current;
if ((current = ParcelableMediaUtils.findByUrl(status.media, link)) != null &&
!current.open_browser) {
expandOrOpenMedia(current);
return;
return true;
}
if ((current = ParcelableMediaUtils.findByUrl(status.quoted_media, link)) != null &&
!current.open_browser) {
expandOrOpenMedia(current);
return;
return true;
}
super.onLinkClick(link, orig, accountKey, extraId, type, sensitive, start, end);
return super.onLinkClick(link, orig, accountKey, extraId, type, sensitive, start, end);
}
private void expandOrOpenMedia(ParcelableMedia current) {

View File

@ -1354,20 +1354,20 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
}
@Override
public void onLinkClick(final String link, final String orig, final UserKey accountKey,
public boolean onLinkClick(final String link, final String orig, final UserKey accountKey,
final long extraId, final int type, final boolean sensitive,
int start, int end) {
final ParcelableUser user = getUser();
if (user == null) return;
if (user == null) return false;
switch (type) {
case TwidereLinkify.LINK_TYPE_MENTION: {
IntentUtils.openUserProfile(getActivity(), user.account_key, null, link, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API), Referral.USER_MENTION);
break;
return true;
}
case TwidereLinkify.LINK_TYPE_HASHTAG: {
IntentUtils.openTweetSearch(getActivity(), user.account_key, "#" + link);
break;
return true;
}
case TwidereLinkify.LINK_TYPE_LINK_IN_TEXT:
case TwidereLinkify.LINK_TYPE_ENTITY_URL: {
@ -1379,7 +1379,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
intent = new Intent(Intent.ACTION_VIEW, uri.buildUpon().scheme("http").build());
}
startActivity(intent);
break;
return true;
}
case TwidereLinkify.LINK_TYPE_LIST: {
if (link == null) break;
@ -1387,9 +1387,10 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (mentionList.length != 2) {
break;
}
break;
return true;
}
}
return false;
}
@Override

View File

@ -66,8 +66,8 @@ public class DirectMessageOnLinkClickHandler extends OnLinkClickHandler {
}
private boolean hasShortenedLinks(final String link) {
for (final String short_link_service : SHORT_LINK_SERVICES) {
if (link.contains(short_link_service)) return true;
for (final String shortLinkService : SHORT_LINK_SERVICES) {
if (link.contains(shortLinkService)) return true;
}
return false;
}

View File

@ -28,6 +28,7 @@ import android.support.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.activity.WebLinkHandlerActivity;
import org.mariotaku.twidere.fragment.UserFragment;
import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.model.UserKey;
@ -55,10 +56,10 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
}
@Override
public void onLinkClick(final String link, final String orig, final UserKey accountKey,
final long extraId, final int type, final boolean sensitive,
final int start, final int end) {
if (manager != null && manager.isActive()) return;
public boolean onLinkClick(final String link, final String orig, final UserKey accountKey,
final long extraId, final int type, final boolean sensitive,
final int start, final int end) {
if (manager != null && manager.isActive()) return false;
if (!isPrivateData()) {
// BEGIN HotMobi
final LinkEvent event = LinkEvent.create(context, link, type);
@ -71,11 +72,11 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
IntentUtils.openUserProfile(context, accountKey, null, link, null,
preferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.USER_MENTION);
break;
return true;
}
case TwidereLinkify.LINK_TYPE_HASHTAG: {
IntentUtils.openTweetSearch(context, accountKey, "#" + link);
break;
return true;
}
case TwidereLinkify.LINK_TYPE_LINK_IN_TEXT: {
if (isMedia(link, extraId)) {
@ -83,60 +84,75 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
} else {
openLink(link);
}
break;
return true;
}
case TwidereLinkify.LINK_TYPE_ENTITY_URL: {
if (isMedia(link, extraId)) {
openMedia(accountKey, extraId, sensitive, link, start, end);
} else {
if (orig != null && "fanfou.com".equals(UriUtils.getAuthority(link))) {
// Process special case for fanfou
final char ch = orig.charAt(0);
// Extend selection
final int length = orig.length();
if (TwidereLinkify.isAtSymbol(ch)) {
String id = UriUtils.getPath(link);
if (id != null) {
int idxOfSlash = id.indexOf('/');
if (idxOfSlash == 0) {
id = id.substring(1);
final String authority = UriUtils.getAuthority(link);
if (authority == null) {
openLink(link);
return true;
}
switch (authority) {
case "fanfou.com": {
if (orig != null) {
// Process special case for fanfou
final char ch = orig.charAt(0);
// Extend selection
final int length = orig.length();
if (TwidereLinkify.isAtSymbol(ch)) {
String id = UriUtils.getPath(link);
if (id != null) {
int idxOfSlash = id.indexOf('/');
if (idxOfSlash == 0) {
id = id.substring(1);
}
final String screenName = orig.substring(1, length);
IntentUtils.openUserProfile(context, accountKey, UserKey.valueOf(id),
screenName, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.USER_MENTION);
return true;
}
} else if (TwidereLinkify.isHashSymbol(ch) &&
TwidereLinkify.isHashSymbol(orig.charAt(length - 1))) {
IntentUtils.openSearch(context, accountKey, orig.substring(1, length - 1));
return true;
}
final String screenName = orig.substring(1, length);
IntentUtils.openUserProfile(context, accountKey, UserKey.valueOf(id),
screenName, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.USER_MENTION);
break;
}
} else if (TwidereLinkify.isHashSymbol(ch) &&
TwidereLinkify.isHashSymbol(orig.charAt(length - 1))) {
IntentUtils.openSearch(context, accountKey, orig.substring(1, length - 1));
break;
}
case "twitter.com": {
openTwitterLink(link, accountKey);
return true;
}
}
openLink(link);
}
break;
return true;
}
case TwidereLinkify.LINK_TYPE_LIST: {
final String[] mentionList = StringUtils.split(link, "/");
if (mentionList.length != 2) {
break;
return false;
}
IntentUtils.openUserListDetails(context, accountKey, null, null, mentionList[0],
mentionList[1]);
break;
return true;
}
case TwidereLinkify.LINK_TYPE_CASHTAG: {
IntentUtils.openTweetSearch(context, accountKey, link);
break;
return true;
}
case TwidereLinkify.LINK_TYPE_USER_ID: {
IntentUtils.openUserProfile(context, accountKey, UserKey.valueOf(link), null, null,
preferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.USER_MENTION);
break;
return true;
}
}
return false;
}
protected boolean isPrivateData() {
@ -157,6 +173,20 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
if (manager != null && manager.isActive()) return;
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage(IntentUtils.getDefaultBrowserPackage(context));
try {
context.startActivity(intent);
} catch (final ActivityNotFoundException e) {
// TODO
}
}
protected void openTwitterLink(final String link, final UserKey accountKey) {
if (manager != null && manager.isActive()) return;
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(context, WebLinkHandlerActivity.class);
intent.putExtra(EXTRA_ACCOUNT_KEY, accountKey);
try {
context.startActivity(intent);
} catch (final ActivityNotFoundException e) {

View File

@ -323,7 +323,7 @@ public final class TwidereLinkify implements Constants {
}
public interface OnLinkClickListener {
void onLinkClick(String link, String orig, UserKey accountKey, long extraId, int type,
boolean onLinkClick(String link, String orig, UserKey accountKey, long extraId, int type,
boolean sensitive, int start, int end);
}
}