Skip to content

Commit e8555a5

Browse files
committed
Switched to quality enum which defaults to medium
1 parent 455855b commit e8555a5

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,15 @@ public static boolean isMshotsUrl(final String imageUrl) {
3737
/*
3838
* returns a photon url for the passed image with the resize query set to the passed dimensions
3939
*/
40-
private static final String QUALITY_PARAM = "quality=65";
40+
public static enum Quality {
41+
HIGH,
42+
MEDIUM,
43+
LOW,
44+
}
4145
public static String getPhotonImageUrl(String imageUrl, int width, int height) {
46+
return getPhotonImageUrl(imageUrl, width, height, Quality.MEDIUM);
47+
}
48+
public static String getPhotonImageUrl(String imageUrl, int width, int height, Quality quality) {
4249
if (TextUtils.isEmpty(imageUrl)) {
4350
return "";
4451
}
@@ -68,17 +75,30 @@ public static String getPhotonImageUrl(String imageUrl, int width, int height) {
6875
return imageUrl + "?w=" + width + "&h=" + height;
6976
}
7077

78+
final String qualityParam;
79+
switch (quality) {
80+
case HIGH:
81+
qualityParam = "quality=100";
82+
break;
83+
case LOW:
84+
qualityParam = "quality=35";
85+
break;
86+
default: // medium
87+
qualityParam = "quality=65";
88+
break;
89+
}
90+
7191
// if both width & height are passed use the "resize" param, use only "w" or "h" if just
7292
// one of them is set - note that the passed quality parameter will only affect JPEGs
7393
final String query;
7494
if (width > 0 && height > 0) {
75-
query = "?resize=" + width + "," + height + "&" + QUALITY_PARAM;
95+
query = "?resize=" + width + "," + height + "&" + qualityParam;
7696
} else if (width > 0) {
77-
query = "?w=" + width + "&" + QUALITY_PARAM;
97+
query = "?w=" + width + "&" + qualityParam;
7898
} else if (height > 0) {
79-
query = "?h=" + height + "&" + QUALITY_PARAM;
99+
query = "?h=" + height + "&" + qualityParam;
80100
} else {
81-
query = "?" + QUALITY_PARAM;
101+
query = "?" + qualityParam;
82102
}
83103

84104
// return passed url+query if it's already a photon url

0 commit comments

Comments
 (0)