From 1dbed708cbb5e4973047b8394b4e82c2dc3428e3 Mon Sep 17 00:00:00 2001 From: Tomer Froumin Date: Sat, 23 Jan 2016 13:10:55 +0200 Subject: [PATCH] Improved URLs parsing and added error message --- app/src/main/AndroidManifest.xml | 1 + .../java/org/xbmc/kore/ui/RemoteActivity.java | 19 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4486b04..e3370f5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -42,6 +42,7 @@ + diff --git a/app/src/main/java/org/xbmc/kore/ui/RemoteActivity.java b/app/src/main/java/org/xbmc/kore/ui/RemoteActivity.java index b613bf6..71b8b6b 100644 --- a/app/src/main/java/org/xbmc/kore/ui/RemoteActivity.java +++ b/app/src/main/java/org/xbmc/kore/ui/RemoteActivity.java @@ -372,7 +372,12 @@ public class RemoteActivity extends BaseActivity } final String videoId = getVideoId(videoUri); - if (videoId == null) return; + if (videoId == null) { + Toast.makeText(RemoteActivity.this, + R.string.error_share_video, + Toast.LENGTH_SHORT).show(); + return; + } final String kodiAddonUrl = "plugin://plugin.video." + (videoUri.getHost().endsWith("vimeo.com") ? "vimeo" : "youtube") + @@ -524,9 +529,15 @@ public class RemoteActivity extends BaseActivity private String getVideoId(Uri playuri) { if (playuri.getHost().endsWith("youtube.com") || playuri.getHost().endsWith("youtu.be") || playuri.getHost().endsWith("vimeo.com")) { // We'll need to get the v= parameter from the URL - final Pattern pattern = - Pattern.compile("(?:https?:\\/\\/)?(?:www\\.|m\\.)?(?:youtu(?:\\.be\\/|be\\.com\\/watch\\?v=)|vimeo\\.com\\/)([\\w-]+)", - Pattern.CASE_INSENSITIVE); + final Pattern pattern; + if (playuri.getHost().endsWith("vimeo.com")) { + pattern = Pattern.compile("^(?:https?:\\/\\/)?(?:www\\.|player\\.)?vimeo\\.com\\/(?:.*\\/)?(\\d+)(?:\\?.*)?$", + Pattern.CASE_INSENSITIVE); + } + else { + pattern = Pattern.compile("^(?:https?:\\/\\/)?(?:www\\.|m\\.)?youtu(?:\\.be|be\\.com)\\/watch\\?(?:.*&)?v=([\\w-]+)(?:&.*)?$", + Pattern.CASE_INSENSITIVE); + } final Matcher matcher = pattern.matcher(playuri.toString()); if (matcher.matches()) { return matcher.group(1); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7b296b6..ebee5f8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -215,6 +215,7 @@ %1$s. Couldn\'t get active player.\nError message: %1$s. + Couldn\'t share video to Kodi/XBMC. Directors: Studio: