diff --git a/.idea/misc.xml b/.idea/misc.xml index 396387992..75dac5029 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -24,7 +24,7 @@ - + diff --git a/build.gradle b/build.gradle index cf771f96e..3b263de28 100644 --- a/build.gradle +++ b/build.gradle @@ -60,7 +60,7 @@ android { useLibrary 'org.apache.http.legacy' defaultConfig { - versionCode 166 + versionCode 167 versionName "4.5.1" minSdkVersion 14 targetSdkVersion 27 diff --git a/src/com/irccloud/android/IRCCloudLinkMovementMethod.java b/src/com/irccloud/android/IRCCloudLinkMovementMethod.java index 4569adff3..e87cba162 100644 --- a/src/com/irccloud/android/IRCCloudLinkMovementMethod.java +++ b/src/com/irccloud/android/IRCCloudLinkMovementMethod.java @@ -66,32 +66,7 @@ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event if (action == MotionEvent.ACTION_UP) { Uri uri = Uri.parse(link[0].getURL()); Context context = widget.getContext(); - if(!PreferenceManager.getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()).getBoolean("browser", false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 && uri.getScheme().startsWith("http") && CustomTabsHelper.getPackageNameToUse(context) != null) { - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - builder.setToolbarColor(ColorScheme.getInstance().navBarColor); - builder.addDefaultShareMenuItem(); - builder.addMenuItem("Copy URL", PendingIntent.getBroadcast(context, 0, new Intent(context, ChromeCopyLinkBroadcastReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT)); - CustomTabsIntent intent = builder.build(); - intent.intent.setData(uri); - if(Build.VERSION.SDK_INT >= 22) - intent.intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + context.getPackageName())); - if (Build.VERSION.SDK_INT >= 16 && intent.startAnimationBundle != null) { - context.startActivity(intent.intent, intent.startAnimationBundle); - } else { - context.startActivity(intent.intent); - } - } else { - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); - if(Build.VERSION.SDK_INT >= 22) - intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + context.getPackageName())); - try { - context.startActivity(intent); - } catch (ActivityNotFoundException e) { - Toast.makeText(context, "Unable to find an application to handle this URL scheme", Toast.LENGTH_SHORT).show(); - } - } + launchURI(uri, context); } else { Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0])); } @@ -102,4 +77,33 @@ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event } return false; } + + public static void launchURI(Uri uri, Context context) { + if(!PreferenceManager.getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()).getBoolean("browser", false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 && uri.getScheme().startsWith("http") && CustomTabsHelper.getPackageNameToUse(context) != null) { + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); + builder.setToolbarColor(ColorScheme.getInstance().navBarColor); + builder.addDefaultShareMenuItem(); + builder.addMenuItem("Copy URL", PendingIntent.getBroadcast(context, 0, new Intent(context, ChromeCopyLinkBroadcastReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT)); + CustomTabsIntent intent = builder.build(); + intent.intent.setData(uri); + if(Build.VERSION.SDK_INT >= 22) + intent.intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + context.getPackageName())); + if (Build.VERSION.SDK_INT >= 16 && intent.startAnimationBundle != null) { + context.startActivity(intent.intent, intent.startAnimationBundle); + } else { + context.startActivity(intent.intent); + } + } else { + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); + if(Build.VERSION.SDK_INT >= 22) + intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + context.getPackageName())); + try { + context.startActivity(intent); + } catch (ActivityNotFoundException e) { + Toast.makeText(context, "Unable to find an application to handle this URL scheme", Toast.LENGTH_SHORT).show(); + } + } + } } diff --git a/src/com/irccloud/android/fragment/MessageViewFragment.java b/src/com/irccloud/android/fragment/MessageViewFragment.java index 96ba7144a..80d43f0d4 100644 --- a/src/com/irccloud/android/fragment/MessageViewFragment.java +++ b/src/com/irccloud/android/fragment/MessageViewFragment.java @@ -2297,23 +2297,24 @@ public void run() { } } else if (e.row_type == ROW_THUMBNAIL) { try { - Intent intent = new Intent(getActivity(), ImageViewerActivity.class); + String uri; if(e.entities.has("id")) - intent.setData(Uri.parse(UriTemplate.fromTemplate(ColorFormatter.file_uri_template).set("id", e.entities.get("id").asText()).expand())); + uri = UriTemplate.fromTemplate(ColorFormatter.file_uri_template).set("id", e.entities.get("id").asText()).set("name", e.entities.get("name").asText()).expand(); else - intent.setData(Uri.parse(e.entities.get("url").asText())); - startActivity(intent); + uri = e.entities.get("url").asText(); + if (PreferenceManager.getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()).getBoolean("imageviewer", true)) { + if (uri.toLowerCase().startsWith("http://")) + uri = IRCCloudApplication.getInstance().getApplicationContext().getResources().getString(R.string.IMAGE_SCHEME) + "://" + uri.substring(7); + else if (uri.toLowerCase().startsWith("https://")) + uri = IRCCloudApplication.getInstance().getApplicationContext().getResources().getString(R.string.IMAGE_SCHEME_SECURE) + "://" + uri.substring(8); + } + IRCCloudLinkMovementMethod.launchURI(Uri.parse(uri), getActivity()); } catch (Exception ex) { ex.printStackTrace(); } } else if (e.row_type == ROW_FILE) { try { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(UriTemplate.fromTemplate(ColorFormatter.file_uri_template).set("id", e.entities.get("id").asText()).expand())); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(Browser.EXTRA_APPLICATION_ID, getActivity().getPackageName()); - if (Build.VERSION.SDK_INT >= 22) - intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + getActivity().getPackageName())); - startActivity(intent); + IRCCloudLinkMovementMethod.launchURI(Uri.parse(UriTemplate.fromTemplate(ColorFormatter.file_uri_template).set("id", e.entities.get("id").asText()).set("name", e.entities.get("name").asText()).expand()), getActivity()); } catch (ActivityNotFoundException ex) { Toast.makeText(getActivity(), "Unable to find an application to handle this URL scheme", Toast.LENGTH_SHORT).show(); } catch (Exception ex) {