From 88e501b368f5d49133fccaaf35a8ce9f6b28cf95 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Thu, 19 Mar 2015 11:55:29 +0100 Subject: [PATCH 1/2] fix #2437: clear uploading posts state if the PostUploadService is not running during PostList creation --- .../org/wordpress/android/util/ServiceUtils.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 WordPressUtils/src/main/java/org/wordpress/android/util/ServiceUtils.java diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/ServiceUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/ServiceUtils.java new file mode 100644 index 000000000000..6bcfde06b892 --- /dev/null +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/ServiceUtils.java @@ -0,0 +1,16 @@ +package org.wordpress.android.util; + +import android.app.ActivityManager; +import android.content.Context; + +public class ServiceUtils { + public static boolean isServiceRunning(Context context, Class serviceClass) { + ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (serviceClass.getName().equals(service.service.getClassName())) { + return true; + } + } + return false; + } +} From 2879710da1dcb76c8e2daeedcd3a599e699cff43 Mon Sep 17 00:00:00 2001 From: Dan Roundhill Date: Fri, 20 Mar 2015 11:50:01 -0700 Subject: [PATCH 2/2] Added support for `WPWebViewClient` to pass the token for image requests. Moved `isImageUrl` method to `UrlUtils` since it is being used in two places now. Fixes #2444 --- .../java/org/wordpress/android/util/UrlUtils.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java index ec7f0144a757..6bf59b0998f2 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java @@ -1,6 +1,7 @@ package org.wordpress.android.util; import android.net.Uri; +import android.text.TextUtils; import android.webkit.MimeTypeMap; import android.webkit.URLUtil; @@ -195,4 +196,14 @@ public static boolean isValidUrlAndHostNotNull(String url) { } return true; } + + // returns true if the passed url is for an image + public static boolean isImageUrl(String url) { + if (TextUtils.isEmpty(url)) return false; + + String cleanedUrl = removeQuery(url.toLowerCase()); + + return cleanedUrl.endsWith("jpg") || cleanedUrl.endsWith("jpeg") || + cleanedUrl.endsWith("gif") || cleanedUrl.endsWith("png"); + } }