diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2014-03-22 14:48:03 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2014-03-22 14:48:03 +0100 |
| commit | 9068fa9fc49620aea9cdf55ac985c4e50b4d8796 (patch) | |
| tree | f51ce2286056bfa410f9078683b0d42f0f2081a8 /main/src | |
| parent | dddba45bcc00f12009badc3df7c9ce304c4926fa (diff) | |
| download | cgeo-9068fa9fc49620aea9cdf55ac985c4e50b4d8796.zip cgeo-9068fa9fc49620aea9cdf55ac985c4e50b4d8796.tar.gz cgeo-9068fa9fc49620aea9cdf55ac985c4e50b4d8796.tar.bz2 | |
Do not open images from geocheck.org in external application
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/network/HtmlImage.java | 10 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/ImageUtils.java | 17 |
3 files changed, 24 insertions, 10 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index f6e3f18..a03f515 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -25,6 +25,7 @@ import cgeo.geocaching.list.StoredList; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.CancellableHandler; +import cgeo.geocaching.utils.ImageUtils; import cgeo.geocaching.utils.LazyInitializedList; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.LogTemplateProvider; @@ -159,6 +160,10 @@ public class Geocache implements ICache, IWaypoint { private Handler changeNotificationHandler = null; + // Images whose URL contains one of those patterns will not be available on the Images tab + // for opening into an external application. + private final String[] NO_EXTERNAL = new String[]{"geocheck.org"}; + /** * Create a new cache. To be used everywhere except for the GPX parser */ @@ -1723,7 +1728,7 @@ public class Geocache implements ICache, IWaypoint { Html.fromHtml(getDescription(), new ImageGetter() { @Override public Drawable getDrawable(final String source) { - if (!urls.contains(source)) { + if (!urls.contains(source) && !ImageUtils.containsPattern(source, NO_EXTERNAL)) { images.add(new Image(source, geocode)); urls.add(source); } diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java index 70cd095..5d713eb 100644 --- a/main/src/cgeo/geocaching/network/HtmlImage.java +++ b/main/src/cgeo/geocaching/network/HtmlImage.java @@ -132,7 +132,7 @@ public class HtmlImage implements Html.ImageGetter { // decoding. public Observable<BitmapDrawable> fetchDrawable(final String url) { - if (StringUtils.isBlank(url) || isCounter(url)) { + if (StringUtils.isBlank(url) || ImageUtils.containsPattern(url, BLOCKED)) { return Observable.from(getTransparent1x1Image(resources)); } @@ -394,12 +394,4 @@ public class HtmlImage implements Html.ImageGetter { bfOptions.inSampleSize = scale; } - private static boolean isCounter(final String url) { - for (String entry : BLOCKED) { - if (StringUtils.containsIgnoreCase(url, entry)) { - return true; - } - } - return false; - } } diff --git a/main/src/cgeo/geocaching/utils/ImageUtils.java b/main/src/cgeo/geocaching/utils/ImageUtils.java index 9f47ead..eb91724 100644 --- a/main/src/cgeo/geocaching/utils/ImageUtils.java +++ b/main/src/cgeo/geocaching/utils/ImageUtils.java @@ -3,6 +3,7 @@ package cgeo.geocaching.utils; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.compatibility.Compatibility; +import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -225,4 +226,20 @@ public final class ImageUtils { } return Uri.fromFile(file); } + + /** + * Check if the URL contains one of the given substrings. + * + * @param url the URL to check + * @param patterns a list of substrings to check against + * @return <tt>true</tt> if the URL contains at least one of the patterns, <tt>false</tt> otherwise + */ + public static boolean containsPattern(final String url, final String[] patterns) { + for (String entry : patterns) { + if (StringUtils.containsIgnoreCase(url, entry)) { + return true; + } + } + return false; + } } |
