Compare commits
2 Commits
ecc1e4b443
...
ea890bfbcd
Author | SHA1 | Date |
---|---|---|
|
ea890bfbcd | |
|
1b86ec39f1 |
|
@ -7,6 +7,8 @@ import android.content.Intent;
|
|||
import android.content.ActivityNotFoundException;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.webkit.URLUtil;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.blankie.unshortify.R;
|
||||
|
||||
|
@ -31,23 +33,27 @@ public class ShareActivity extends Activity {
|
|||
final Intent intent = getIntent();
|
||||
final String urlString = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
logVariable("urlString", urlString);
|
||||
if (urlString == null || urlString == "") {
|
||||
if (urlString == null || urlString.isEmpty()) {
|
||||
Toast.makeText(getApplicationContext(), R.string.empty_url,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
final Uri urlParsed = Uri.parse(urlString);
|
||||
final String scheme = urlParsed.getScheme();
|
||||
final Uri urlParsed = Uri.parse(URLUtil.guessUrl(urlString));
|
||||
final String scheme = urlParsed.getScheme() != null
|
||||
? urlParsed.getScheme().toLowerCase(Locale.ROOT)
|
||||
: null;
|
||||
logVariable("scheme", scheme);
|
||||
if (scheme != null && !scheme.equals("") && !scheme.equals("http") &&
|
||||
!scheme.equals("https")) {
|
||||
if (scheme == null || (!scheme.equals("http")
|
||||
&& !scheme.equals("https"))) {
|
||||
Toast.makeText(getApplicationContext(), R.string.unknown_scheme,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
final String host = urlParsed.getHost();
|
||||
final String host = urlParsed.getHost() != null
|
||||
? urlParsed.getHost().toLowerCase(Locale.ROOT)
|
||||
: null;
|
||||
logVariable("host", host);
|
||||
if (host == null || (!host.equals("youtube.com") &&
|
||||
!host.endsWith(".youtube.com"))) {
|
||||
|
@ -63,7 +69,7 @@ public class ShareActivity extends Activity {
|
|||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (!path.startsWith("/shorts/")) {
|
||||
if (!path.toLowerCase(Locale.ROOT).startsWith("/shorts/")) {
|
||||
Toast.makeText(getApplicationContext(), R.string.non_shorts_url,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
|
@ -85,7 +91,7 @@ public class ShareActivity extends Activity {
|
|||
|
||||
final Intent unshortifiedIntent = new Intent(Intent.ACTION_VIEW, unshortifiedUrl);
|
||||
try {
|
||||
startActivity(intent);
|
||||
startActivity(unshortifiedIntent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(getApplicationContext(), R.string.no_activity_found,
|
||||
|
|
Loading…
Reference in New Issue