Skip to content

Commit 9c93172

Browse files
committed
Fixes issue where private blog images wouldn't load.
1 parent 84139a9 commit 9c93172

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ public static boolean isImageUrl(String url) {
231231
cleanedUrl.endsWith("gif") || cleanedUrl.endsWith("png");
232232
}
233233

234+
/**
235+
* Returns true if the url is on wordpress.com
236+
*/
237+
public static boolean isWPComUrl(String url) {
238+
return !TextUtils.isEmpty(url) && url.contains("wordpress.com");
239+
}
240+
241+
234242
public static String appendUrlParameter(String url, String paramName, String paramValue) {
235243
Map<String, String> parameters = new HashMap<>();
236244
parameters.put(paramName, paramValue);

WordPressUtils/src/main/java/org/wordpress/android/util/helpers/WPImageGetter.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.graphics.Canvas;
44
import android.graphics.drawable.BitmapDrawable;
55
import android.graphics.drawable.Drawable;
6+
import android.support.v4.util.ArrayMap;
67
import android.text.Html;
78
import android.text.TextUtils;
89
import android.widget.TextView;
@@ -13,14 +14,18 @@
1314
import org.wordpress.android.util.AppLog;
1415
import org.wordpress.android.util.AppLog.T;
1516
import org.wordpress.android.util.PhotonUtils;
17+
import org.wordpress.android.util.UrlUtils;
1618

1719
import java.lang.ref.WeakReference;
20+
import java.util.Map;
1821

1922
/**
2023
* ImageGetter for Html.fromHtml()
2124
* adapted from existing ImageGetter code in NoteCommentFragment
2225
*/
2326
public class WPImageGetter implements Html.ImageGetter {
27+
private static final String IMAGE_QUALITY = "65";
28+
2429
private final WeakReference<TextView> mWeakView;
2530
private final int mMaxSize;
2631
private ImageLoader mImageLoader;
@@ -32,13 +37,13 @@ public WPImageGetter(TextView view) {
3237
}
3338

3439
public WPImageGetter(TextView view, int maxSize) {
35-
mWeakView = new WeakReference<TextView>(view);
40+
mWeakView = new WeakReference<>(view);
3641
mMaxSize = maxSize;
3742
}
3843

3944
public WPImageGetter(TextView view, int maxSize, ImageLoader imageLoader, Drawable loadingDrawable,
4045
Drawable failedDrawable) {
41-
mWeakView = new WeakReference<TextView>(view);
46+
mWeakView = new WeakReference<>(view);
4247
mMaxSize = maxSize;
4348
mImageLoader = imageLoader;
4449
mLoadingDrawable = loadingDrawable;
@@ -64,10 +69,20 @@ public Drawable getDrawable(String source) {
6469
source = "http:" + source;
6570
}
6671

67-
// use Photon if a max size is requested (otherwise the full-sized image will be downloaded
72+
// Resize to max size if requested (otherwise the full-sized image will be downloaded
6873
// and then resized)
6974
if (mMaxSize > 0) {
70-
source = PhotonUtils.getPhotonImageUrl(source, mMaxSize, 0);
75+
if (UrlUtils.isWPComUrl(source)) {
76+
// Adjust query params for wp.com urls
77+
Map<String, String> params = new ArrayMap<>();
78+
params.put("w", String.valueOf(mMaxSize));
79+
params.put("quality", IMAGE_QUALITY);
80+
81+
source = UrlUtils.appendUrlParameters(UrlUtils.removeQuery(source), params);
82+
} else {
83+
// Otherwise use photon
84+
source = PhotonUtils.getPhotonImageUrl(source, mMaxSize, 0);
85+
}
7186
}
7287

7388
final RemoteDrawable remote = new RemoteDrawable(mLoadingDrawable, mFailedDrawable);

0 commit comments

Comments
 (0)