Unified logic to parse intent for links and for local URIs

This commit is contained in:
Francesco Bonazzi 2020-04-26 11:56:26 +02:00 committed by Martijn Brekhof
parent 5f0ca05eeb
commit 74ef717a37
1 changed files with 24 additions and 20 deletions

View File

@ -391,26 +391,11 @@ public class RemoteActivity extends BaseActivity
} }
if (videoUri == null) { if (videoUri == null) {
// Some apps hide the link in the clip, try to detect any link by casting the intent // Check if `intent` contains a URL or a link to a local file:
// to string a looking with a regular expression: videoUri = getShareLocalUriOrHiddenUri(intent);
Matcher matcher = Pattern.compile("https?://[^\\s]+").matcher(intent.toString());
String matchedString = null;
if (matcher.find()) {
matchedString = matcher.group(0);
if (matchedString.endsWith("}")) {
matchedString = matchedString.substring(0, matchedString.length() - 1);
}
videoUri = Uri.parse(matchedString);
}
} }
String url; String url = toPluginUrl(videoUri);
if (videoUri == null) {
url = getShareLocalUri(intent);
} else {
url = toPluginUrl(videoUri);
}
if (url == null) { if (url == null) {
url = videoUri.toString(); url = videoUri.toString();
@ -458,13 +443,32 @@ public class RemoteActivity extends BaseActivity
finish(); finish();
} }
private String getShareLocalUri(Intent intent) { private Uri getUrlInsideIntent(Intent intent) {
// Some apps hide the link in the clip, try to detect any link by casting the intent
// to string a looking with a regular expression:
Matcher matcher = Pattern.compile("https?://[^\\s]+").matcher(intent.toString());
String matchedString = null;
if (matcher.find()) {
matchedString = matcher.group(0);
if (matchedString.endsWith("}")) {
matchedString = matchedString.substring(0, matchedString.length() - 1);
}
return Uri.parse(matchedString);
}
return null;
}
private Uri getShareLocalUriOrHiddenUri(Intent intent) {
Uri contentUri = intent.getData(); Uri contentUri = intent.getData();
if (contentUri == null) { if (contentUri == null) {
Bundle bundle = intent.getExtras(); Bundle bundle = intent.getExtras();
contentUri = (Uri) bundle.get(Intent.EXTRA_STREAM); contentUri = (Uri) bundle.get(Intent.EXTRA_STREAM);
} }
if (contentUri == null) {
return getUrlInsideIntent(intent);
}
if (contentUri == null) { if (contentUri == null) {
return null; return null;
} }
@ -481,7 +485,7 @@ public class RemoteActivity extends BaseActivity
http_app.addUri(contentUri); http_app.addUri(contentUri);
String url = http_app.getLinkToFile(); String url = http_app.getLinkToFile();
return url; return Uri.parse(url);
} }
/** /**