Adress requested changes and try some cleanup in handleUrl method of InternalUrlsHandler class
This commit is contained in:
parent
2702700d10
commit
a79badd783
4 changed files with 34 additions and 34 deletions
|
@ -48,14 +48,11 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
||||||
|
|
||||||
if (link.length != 0) {
|
if (link.length != 0) {
|
||||||
if (action == MotionEvent.ACTION_UP) {
|
if (action == MotionEvent.ACTION_UP) {
|
||||||
boolean handled = false;
|
|
||||||
if (link[0] instanceof URLSpan) {
|
if (link[0] instanceof URLSpan) {
|
||||||
handled = InternalUrlsHandler.handleUrl(v.getContext(),
|
final String url = ((URLSpan) link[0]).getURL();
|
||||||
((URLSpan) link[0]).getURL(), 1);
|
if (!InternalUrlsHandler.handleUrl(v.getContext(), url, 1)) {
|
||||||
}
|
ShareUtils.openUrlInBrowser(v.getContext(), url, false);
|
||||||
if (!handled) {
|
}
|
||||||
ShareUtils.openUrlInBrowser(v.getContext(),
|
|
||||||
((URLSpan) link[0]).getURL(), false);
|
|
||||||
}
|
}
|
||||||
} else if (action == MotionEvent.ACTION_DOWN) {
|
} else if (action == MotionEvent.ACTION_DOWN) {
|
||||||
Selection.setSelection(buffer,
|
Selection.setSelection(buffer,
|
||||||
|
|
|
@ -49,22 +49,20 @@ public final class InternalUrlsHandler {
|
||||||
final int timestampType) {
|
final int timestampType) {
|
||||||
String matchedUrl = "";
|
String matchedUrl = "";
|
||||||
int seconds = -1;
|
int seconds = -1;
|
||||||
final Pattern timestampPattern;
|
final Matcher matcher;
|
||||||
|
|
||||||
if (timestampType == 0) {
|
if (timestampType == 0) {
|
||||||
timestampPattern = AMPERSAND_TIMESTAMP_PATTERN;
|
matcher = AMPERSAND_TIMESTAMP_PATTERN.matcher(url);
|
||||||
} else if (timestampType == 1) {
|
} else if (timestampType == 1) {
|
||||||
timestampPattern = HASHTAG_TIMESTAMP_PATTERN;
|
matcher = HASHTAG_TIMESTAMP_PATTERN.matcher(url);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Matcher matcher = timestampPattern.matcher(url);
|
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
matchedUrl = matcher.group(1);
|
matchedUrl = matcher.group(1);
|
||||||
seconds = Integer.parseInt(matcher.group(2));
|
seconds = Integer.parseInt(matcher.group(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchedUrl == null || matchedUrl.isEmpty()) {
|
if (matchedUrl == null || matchedUrl.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +76,6 @@ public final class InternalUrlsHandler {
|
||||||
} catch (final ExtractionException e) {
|
} catch (final ExtractionException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linkType == StreamingService.LinkType.NONE) {
|
if (linkType == StreamingService.LinkType.NONE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,13 +144,18 @@ public final class TextLinkifier {
|
||||||
final int hashtagEnd = hashtagsMatches.end(1);
|
final int hashtagEnd = hashtagsMatches.end(1);
|
||||||
final String parsedHashtag = descriptionText.substring(hashtagStart, hashtagEnd);
|
final String parsedHashtag = descriptionText.substring(hashtagStart, hashtagEnd);
|
||||||
|
|
||||||
spannableDescription.setSpan(new ClickableSpan() {
|
// don't add a ClickableSpan if there is already one, which should be a part of an URL,
|
||||||
@Override
|
// already parsed before
|
||||||
public void onClick(@NonNull final View view) {
|
if (spannableDescription.getSpans(hashtagStart, hashtagEnd,
|
||||||
NavigationHelper.openSearch(context, streamingService.getServiceId(),
|
ClickableSpan.class).length == 0) {
|
||||||
parsedHashtag);
|
spannableDescription.setSpan(new ClickableSpan() {
|
||||||
}
|
@Override
|
||||||
}, hashtagStart, hashtagEnd, 0);
|
public void onClick(@NonNull final View view) {
|
||||||
|
NavigationHelper.openSearch(context, streamingService.getServiceId(),
|
||||||
|
parsedHashtag);
|
||||||
|
}
|
||||||
|
}, hashtagStart, hashtagEnd, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,26 +186,24 @@ public final class TextLinkifier {
|
||||||
final String parsedTimestamp = descriptionText.substring(timestampStart, timestampEnd);
|
final String parsedTimestamp = descriptionText.substring(timestampStart, timestampEnd);
|
||||||
final String[] timestampParts = parsedTimestamp.split(":");
|
final String[] timestampParts = parsedTimestamp.split(":");
|
||||||
final int time;
|
final int time;
|
||||||
|
|
||||||
if (timestampParts.length == 3) { // timestamp format: XX:XX:XX
|
if (timestampParts.length == 3) { // timestamp format: XX:XX:XX
|
||||||
time = Integer.parseInt(timestampParts[0]) * 3600 // hours
|
time = Integer.parseInt(timestampParts[0]) * 3600 // hours
|
||||||
+ Integer.parseInt(timestampParts[1]) * 60 // minutes
|
+ Integer.parseInt(timestampParts[1]) * 60 // minutes
|
||||||
+ Integer.parseInt(timestampParts[2]); // seconds
|
+ Integer.parseInt(timestampParts[2]); // seconds
|
||||||
spannableDescription.setSpan(new ClickableSpan() {
|
|
||||||
@Override
|
|
||||||
public void onClick(@NonNull final View view) {
|
|
||||||
playOnPopup(context, contentUrl, streamingService, time);
|
|
||||||
}
|
|
||||||
}, timestampStart, timestampEnd, 0);
|
|
||||||
} else if (timestampParts.length == 2) { // timestamp format: XX:XX
|
} else if (timestampParts.length == 2) { // timestamp format: XX:XX
|
||||||
time = Integer.parseInt(timestampParts[0]) * 60 // minutes
|
time = Integer.parseInt(timestampParts[0]) * 60 // minutes
|
||||||
+ Integer.parseInt(timestampParts[1]); // seconds
|
+ Integer.parseInt(timestampParts[1]); // seconds
|
||||||
spannableDescription.setSpan(new ClickableSpan() {
|
} else {
|
||||||
@Override
|
continue;
|
||||||
public void onClick(@NonNull final View view) {
|
|
||||||
playOnPopup(context, contentUrl, streamingService, time);
|
|
||||||
}
|
|
||||||
}, timestampStart, timestampEnd, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spannableDescription.setSpan(new ClickableSpan() {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NonNull final View view) {
|
||||||
|
playOnPopup(context, contentUrl, streamingService, time);
|
||||||
|
}
|
||||||
|
}, timestampStart, timestampEnd, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,10 +242,11 @@ public final class TextLinkifier {
|
||||||
final URLSpan[] urls = textBlockLinked.getSpans(0, chars.length(), URLSpan.class);
|
final URLSpan[] urls = textBlockLinked.getSpans(0, chars.length(), URLSpan.class);
|
||||||
|
|
||||||
for (final URLSpan span : urls) {
|
for (final URLSpan span : urls) {
|
||||||
|
final String url = span.getURL();
|
||||||
final ClickableSpan clickableSpan = new ClickableSpan() {
|
final ClickableSpan clickableSpan = new ClickableSpan() {
|
||||||
public void onClick(@NonNull final View view) {
|
public void onClick(@NonNull final View view) {
|
||||||
if (!InternalUrlsHandler.handleUrl(context, span.getURL(), 0)) {
|
if (!InternalUrlsHandler.handleUrl(context, url, 0)) {
|
||||||
ShareUtils.openUrlInBrowser(context, span.getURL(), false);
|
ShareUtils.openUrlInBrowser(context, url, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -375,6 +375,8 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
|
||||||
|
|
||||||
final Intent intent = new Intent(Intent.ACTION_CHOOSER);
|
final Intent intent = new Intent(Intent.ACTION_CHOOSER);
|
||||||
intent.putExtra(Intent.EXTRA_INTENT, shareIntent);
|
intent.putExtra(Intent.EXTRA_INTENT, shareIntent);
|
||||||
|
// unneeded to set a title to the chooser on Android P and higher because the system
|
||||||
|
// ignores this title on these versions
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
|
||||||
intent.putExtra(Intent.EXTRA_TITLE, mContext.getString(R.string.share_dialog_title));
|
intent.putExtra(Intent.EXTRA_TITLE, mContext.getString(R.string.share_dialog_title));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue