33import android .graphics .Canvas ;
44import android .graphics .drawable .BitmapDrawable ;
55import android .graphics .drawable .Drawable ;
6+ import android .support .v4 .util .ArrayMap ;
67import android .text .Html ;
78import android .text .TextUtils ;
89import android .widget .TextView ;
1314import org .wordpress .android .util .AppLog ;
1415import org .wordpress .android .util .AppLog .T ;
1516import org .wordpress .android .util .PhotonUtils ;
17+ import org .wordpress .android .util .UrlUtils ;
1618
1719import 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 */
2326public 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