mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Adress requested changes and try some cleanup in handleUrl method of InternalUrlsHandler class
This commit is contained in:
parent
2702700d10
commit
a79badd783
@ -48,14 +48,11 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
||||
|
||||
if (link.length != 0) {
|
||||
if (action == MotionEvent.ACTION_UP) {
|
||||
boolean handled = false;
|
||||
if (link[0] instanceof URLSpan) {
|
||||
handled = InternalUrlsHandler.handleUrl(v.getContext(),
|
||||
((URLSpan) link[0]).getURL(), 1);
|
||||
}
|
||||
if (!handled) {
|
||||
ShareUtils.openUrlInBrowser(v.getContext(),
|
||||
((URLSpan) link[0]).getURL(), false);
|
||||
final String url = ((URLSpan) link[0]).getURL();
|
||||
if (!InternalUrlsHandler.handleUrl(v.getContext(), url, 1)) {
|
||||
ShareUtils.openUrlInBrowser(v.getContext(), url, false);
|
||||
}
|
||||
}
|
||||
} else if (action == MotionEvent.ACTION_DOWN) {
|
||||
Selection.setSelection(buffer,
|
||||
|
@ -49,22 +49,20 @@ public final class InternalUrlsHandler {
|
||||
final int timestampType) {
|
||||
String matchedUrl = "";
|
||||
int seconds = -1;
|
||||
final Pattern timestampPattern;
|
||||
final Matcher matcher;
|
||||
|
||||
if (timestampType == 0) {
|
||||
timestampPattern = AMPERSAND_TIMESTAMP_PATTERN;
|
||||
matcher = AMPERSAND_TIMESTAMP_PATTERN.matcher(url);
|
||||
} else if (timestampType == 1) {
|
||||
timestampPattern = HASHTAG_TIMESTAMP_PATTERN;
|
||||
matcher = HASHTAG_TIMESTAMP_PATTERN.matcher(url);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Matcher matcher = timestampPattern.matcher(url);
|
||||
if (matcher.matches()) {
|
||||
matchedUrl = matcher.group(1);
|
||||
seconds = Integer.parseInt(matcher.group(2));
|
||||
}
|
||||
|
||||
if (matchedUrl == null || matchedUrl.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@ -78,7 +76,6 @@ public final class InternalUrlsHandler {
|
||||
} catch (final ExtractionException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (linkType == StreamingService.LinkType.NONE) {
|
||||
return false;
|
||||
}
|
||||
|
@ -144,13 +144,18 @@ public final class TextLinkifier {
|
||||
final int hashtagEnd = hashtagsMatches.end(1);
|
||||
final String parsedHashtag = descriptionText.substring(hashtagStart, hashtagEnd);
|
||||
|
||||
spannableDescription.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull final View view) {
|
||||
NavigationHelper.openSearch(context, streamingService.getServiceId(),
|
||||
parsedHashtag);
|
||||
}
|
||||
}, hashtagStart, hashtagEnd, 0);
|
||||
// don't add a ClickableSpan if there is already one, which should be a part of an URL,
|
||||
// already parsed before
|
||||
if (spannableDescription.getSpans(hashtagStart, hashtagEnd,
|
||||
ClickableSpan.class).length == 0) {
|
||||
spannableDescription.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
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[] timestampParts = parsedTimestamp.split(":");
|
||||
final int time;
|
||||
|
||||
if (timestampParts.length == 3) { // timestamp format: XX:XX:XX
|
||||
time = Integer.parseInt(timestampParts[0]) * 3600 // hours
|
||||
+ Integer.parseInt(timestampParts[1]) * 60 // minutes
|
||||
+ 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
|
||||
time = Integer.parseInt(timestampParts[0]) * 60 // minutes
|
||||
+ Integer.parseInt(timestampParts[1]); // seconds
|
||||
spannableDescription.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull final View view) {
|
||||
playOnPopup(context, contentUrl, streamingService, time);
|
||||
}
|
||||
}, timestampStart, timestampEnd, 0);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
for (final URLSpan span : urls) {
|
||||
final String url = span.getURL();
|
||||
final ClickableSpan clickableSpan = new ClickableSpan() {
|
||||
public void onClick(@NonNull final View view) {
|
||||
if (!InternalUrlsHandler.handleUrl(context, span.getURL(), 0)) {
|
||||
ShareUtils.openUrlInBrowser(context, span.getURL(), false);
|
||||
if (!InternalUrlsHandler.handleUrl(context, url, 0)) {
|
||||
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);
|
||||
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) {
|
||||
intent.putExtra(Intent.EXTRA_TITLE, mContext.getString(R.string.share_dialog_title));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user