From 61c424abf77b6913deb6b6acb9c594046c80b18a Mon Sep 17 00:00:00 2001 From: l3d00m Date: Sun, 15 Nov 2015 20:45:40 +0100 Subject: [PATCH] url fixes don't crash on unknown url don't open submission with 'wiki' in title as wiki open reddit live links in browser --- .../me/ccrama/redditslide/ContentType.java | 6 +-- .../me/ccrama/redditslide/OpenRedditLink.java | 2 +- .../Views/MakeTextviewClickable.java | 51 ++++++++++++++++--- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/me/ccrama/redditslide/ContentType.java b/app/src/main/java/me/ccrama/redditslide/ContentType.java index a48d797913..d8db3b6bd6 100644 --- a/app/src/main/java/me/ccrama/redditslide/ContentType.java +++ b/app/src/main/java/me/ccrama/redditslide/ContentType.java @@ -74,7 +74,7 @@ public static ImageType getImageType(Submission s) { } if (s.isSelfPost()) { return ImageType.SELF; - } else if ((url.contains("reddit.com") || url.contains("redd.it")) && !url.contains("wiki")) { + } else if ((url.contains("reddit.com") || url.contains("redd.it")) && !url.contains("/wiki") && !url.contains("/live")) { return ImageType.REDDIT; } @@ -122,7 +122,7 @@ public static ImageType getImageType(Submission s) { if (url.contains("gfy")) return ImageType.NONE_GFY; return ImageType.NONE_GIF; - } else if ((url.contains("reddit.com") || url.contains("redd.it")) && !url.contains("wiki")) { + } else if ((url.contains("reddit.com") || url.contains("redd.it")) && !url.contains("/wiki") && !url.contains("/live")) { return ImageType.REDDIT; } else if (!url.isEmpty()) { return ImageType.LINK; @@ -174,7 +174,7 @@ public static ImageType getImageType(String url) { if (url.startsWith("/")) { url = "reddit.com" + url; } - if ((url.contains("reddit.com") || url.contains("redd.it")) && !url.contains("wiki")) { + if ((url.contains("reddit.com") || url.contains("redd.it")) && !url.contains("/wiki") && !url.contains("/live")) { return ImageType.REDDIT; } else if (url.contains("youtu")) { return ImageType.VIDEO; diff --git a/app/src/main/java/me/ccrama/redditslide/OpenRedditLink.java b/app/src/main/java/me/ccrama/redditslide/OpenRedditLink.java index 4b488a4e39..155d4fd00b 100644 --- a/app/src/main/java/me/ccrama/redditslide/OpenRedditLink.java +++ b/app/src/main/java/me/ccrama/redditslide/OpenRedditLink.java @@ -39,7 +39,7 @@ public OpenRedditLink(Context c, String url) { } - if (url.contains("wiki")) { + if (url.contains("/wiki")) { Intent i = new Intent(c, Wiki.class); i.putExtra("subreddit", parts[2]); c.startActivity(i); diff --git a/app/src/main/java/me/ccrama/redditslide/Views/MakeTextviewClickable.java b/app/src/main/java/me/ccrama/redditslide/Views/MakeTextviewClickable.java index 10b93fb67f..fcbfe99e29 100644 --- a/app/src/main/java/me/ccrama/redditslide/Views/MakeTextviewClickable.java +++ b/app/src/main/java/me/ccrama/redditslide/Views/MakeTextviewClickable.java @@ -1,15 +1,18 @@ package me.ccrama.redditslide.Views; import android.app.Activity; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.support.customtabs.CustomTabsIntent; +import android.support.design.widget.Snackbar; import android.text.Html; import android.text.SpannableStringBuilder; import android.text.style.ClickableSpan; import android.text.style.URLSpan; import android.util.DisplayMetrics; +import android.util.Log; import android.util.TypedValue; import android.view.View; @@ -184,7 +187,11 @@ public void onClick(String url) { builder.setStartAnimations(c, R.anim.slideright, R.anim.fading_out_real); builder.setExitAnimations(c, R.anim.fade_out, R.anim.fade_in_real); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(c, Uri.parse(url)); + try { + customTabsIntent.launchUrl(c, Uri.parse(url)); + } catch (ActivityNotFoundException anfe) { + Log.w("MakeTextViewClickable", "Unknown url: " + anfe); + } } else { Reddit.defaultShare(url, c); } @@ -198,7 +205,11 @@ public void onClick(String url) { builder.setStartAnimations(c, R.anim.slideright, R.anim.fading_out_real); builder.setExitAnimations(c, R.anim.fade_out, R.anim.fade_in_real); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(c, Uri.parse(url)); + try { + customTabsIntent.launchUrl(c, Uri.parse(url)); + } catch (ActivityNotFoundException anfe) { + Log.w("MakeTextViewClickable", "Unknown url: " + anfe); + } } else { Reddit.defaultShare(url, c); } @@ -212,7 +223,11 @@ public void onClick(String url) { builder.setStartAnimations(c, R.anim.slideright, R.anim.fading_out_real); builder.setExitAnimations(c, R.anim.fade_out, R.anim.fade_in_real); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(c, Uri.parse(url)); + try { + customTabsIntent.launchUrl(c, Uri.parse(url)); + } catch (ActivityNotFoundException anfe) { + Log.w("MakeTextViewClickable", "Unknown url: " + anfe); + } } else { Reddit.defaultShare(url, c); } @@ -269,7 +284,11 @@ public void onClick(String url) { builder.setStartAnimations(c, R.anim.slideright, R.anim.fading_out_real); builder.setExitAnimations(c, R.anim.fade_out, R.anim.fade_in_real); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(c, Uri.parse(url)); + try { + customTabsIntent.launchUrl(c, Uri.parse(url)); + } catch (ActivityNotFoundException anfe) { + Log.w("MakeTextViewClickable", "Unknown url: " + anfe); + } } else { Reddit.defaultShare(url, c); } @@ -352,7 +371,11 @@ public void onClick(String url) { builder.setStartAnimations(c, R.anim.slideright, R.anim.fading_out_real); builder.setExitAnimations(c, R.anim.fade_out, R.anim.fade_in_real); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(c, Uri.parse(url)); + try { + customTabsIntent.launchUrl(c, Uri.parse(url)); + } catch (ActivityNotFoundException anfe) { + Log.w("MakeTextViewClickable", "Unknown url: " + anfe); + } } else { Reddit.defaultShare(url, c); } @@ -366,7 +389,11 @@ public void onClick(String url) { builder.setStartAnimations(c, R.anim.slideright, R.anim.fading_out_real); builder.setExitAnimations(c, R.anim.fade_out, R.anim.fade_in_real); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(c, Uri.parse(url)); + try { + customTabsIntent.launchUrl(c, Uri.parse(url)); + } catch (ActivityNotFoundException anfe) { + Log.w("MakeTextViewClickable", "Unknown url: " + anfe); + } } else { Reddit.defaultShare(url, c); } @@ -380,7 +407,11 @@ public void onClick(String url) { builder.setStartAnimations(c, R.anim.slideright, R.anim.fading_out_real); builder.setExitAnimations(c, R.anim.fade_out, R.anim.fade_in_real); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(c, Uri.parse(url)); + try { + customTabsIntent.launchUrl(c, Uri.parse(url)); + } catch (ActivityNotFoundException anfe) { + Log.w("MakeTextViewClickable", "Unknown url: " + anfe); + } } else { Reddit.defaultShare(url, c); } @@ -437,7 +468,11 @@ public void onClick(String url) { builder.setStartAnimations(c, R.anim.slideright, R.anim.fading_out_real); builder.setExitAnimations(c, R.anim.fade_out, R.anim.fade_in_real); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(c, Uri.parse(url)); + try { + customTabsIntent.launchUrl(c, Uri.parse(url)); + } catch (ActivityNotFoundException anfe) { + Log.w("MakeTextViewClickable", "Unknown url: " + anfe); + } } else { Reddit.defaultShare(url, c); }