@@ -42,6 +42,7 @@ public Media[] newArray(int i) {
42
42
43
43
// Primary metadata fields
44
44
protected Uri localUri ;
45
+ private String thumbUrl ;
45
46
protected String imageUrl ;
46
47
protected String filename ;
47
48
protected String description ; // monolingual description on input...
@@ -93,6 +94,7 @@ public Media(Uri localUri, String imageUrl, String filename, String description,
93
94
long dataLength , Date dateCreated , Date dateUploaded , String creator ) {
94
95
this ();
95
96
this .localUri = localUri ;
97
+ this .thumbUrl = imageUrl ;
96
98
this .imageUrl = imageUrl ;
97
99
this .filename = filename ;
98
100
this .description = description ;
@@ -107,6 +109,7 @@ public Media(Uri localUri, String imageUrl, String filename, String description,
107
109
@ SuppressWarnings ("unchecked" )
108
110
public Media (Parcel in ) {
109
111
localUri = in .readParcelable (Uri .class .getClassLoader ());
112
+ thumbUrl = in .readString ();
110
113
imageUrl = in .readString ();
111
114
filename = in .readString ();
112
115
description = in .readString ();
@@ -124,6 +127,67 @@ public Media(Parcel in) {
124
127
descriptions = in .readHashMap (ClassLoader .getSystemClassLoader ());
125
128
}
126
129
130
+ /**
131
+ * Creating Media object from MWQueryPage.
132
+ * Earlier only basic details were set for the media object but going forward,
133
+ * a full media object(with categories, descriptions, coordinates etc) can be constructed using this method
134
+ *
135
+ * @param page response from the API
136
+ * @return Media object
137
+ */
138
+ @ Nullable
139
+ public static Media from (MwQueryPage page ) {
140
+ ImageInfo imageInfo = page .imageInfo ();
141
+ if (imageInfo == null ) {
142
+ return null ;
143
+ }
144
+ ExtMetadata metadata = imageInfo .getMetadata ();
145
+ if (metadata == null ) {
146
+ Media media = new Media (null , imageInfo .getOriginalUrl (),
147
+ page .title (), "" , 0 , null , null , null );
148
+ if (!StringUtils .isBlank (imageInfo .getThumbUrl ())) {
149
+ media .setThumbUrl (imageInfo .getThumbUrl ());
150
+ }
151
+ return media ;
152
+ }
153
+
154
+ Media media = new Media (null ,
155
+ imageInfo .getOriginalUrl (),
156
+ page .title (),
157
+ "" ,
158
+ 0 ,
159
+ safeParseDate (metadata .dateTimeOriginal ().value ()),
160
+ safeParseDate (metadata .dateTime ().value ()),
161
+ StringUtil .fromHtml (metadata .artist ().value ()).toString ()
162
+ );
163
+
164
+ if (!StringUtils .isBlank (imageInfo .getThumbUrl ())) {
165
+ media .setThumbUrl (imageInfo .getThumbUrl ());
166
+ }
167
+
168
+ String language = Locale .getDefault ().getLanguage ();
169
+ if (StringUtils .isBlank (language )) {
170
+ language = "default" ;
171
+ }
172
+
173
+ media .setDescriptions (Collections .singletonMap (language , metadata .imageDescription ().value ()));
174
+ media .setCategories (MediaDataExtractorUtil .extractCategoriesFromList (metadata .categories ().value ()));
175
+ String latitude = metadata .gpsLatitude ().value ();
176
+ String longitude = metadata .gpsLongitude ().value ();
177
+
178
+ if (!StringUtils .isBlank (latitude ) && !StringUtils .isBlank (longitude )) {
179
+ LatLng latLng = new LatLng (Double .parseDouble (latitude ), Double .parseDouble (longitude ), 0 );
180
+ media .setCoordinates (latLng );
181
+ }
182
+
183
+ media .setLicenseInformation (metadata .licenseShortName ().value (), metadata .licenseUrl ().value ());
184
+ return media ;
185
+ }
186
+
187
+ public String getThumbUrl () {
188
+ return thumbUrl ;
189
+ }
190
+
127
191
/**
128
192
* Gets tag of media
129
193
* @param key Media key
@@ -322,53 +386,8 @@ public String getLicense() {
322
386
return license ;
323
387
}
324
388
325
- /**
326
- * Creating Media object from MWQueryPage.
327
- * Earlier only basic details were set for the media object but going forward,
328
- * a full media object(with categories, descriptions, coordinates etc) can be constructed using this method
329
- *
330
- * @param page response from the API
331
- * @return Media object
332
- */
333
- @ Nullable
334
- public static Media from (MwQueryPage page ) {
335
- ImageInfo imageInfo = page .imageInfo ();
336
- if (imageInfo == null ) {
337
- return null ;
338
- }
339
- ExtMetadata metadata = imageInfo .getMetadata ();
340
- if (metadata == null ) {
341
- return new Media (null , imageInfo .getOriginalUrl (),
342
- page .title (), "" , 0 , null , null , null );
343
- }
344
-
345
- Media media = new Media (null ,
346
- imageInfo .getOriginalUrl (),
347
- page .title (),
348
- "" ,
349
- 0 ,
350
- safeParseDate (metadata .dateTimeOriginal ().value ()),
351
- safeParseDate (metadata .dateTime ().value ()),
352
- StringUtil .fromHtml (metadata .artist ().value ()).toString ()
353
- );
354
-
355
- String language = Locale .getDefault ().getLanguage ();
356
- if (StringUtils .isBlank (language )) {
357
- language = "default" ;
358
- }
359
-
360
- media .setDescriptions (Collections .singletonMap (language , metadata .imageDescription ().value ()));
361
- media .setCategories (MediaDataExtractorUtil .extractCategoriesFromList (metadata .categories ().value ()));
362
- String latitude = metadata .gpsLatitude ().value ();
363
- String longitude = metadata .gpsLongitude ().value ();
364
-
365
- if (!StringUtils .isBlank (latitude ) && !StringUtils .isBlank (longitude )) {
366
- LatLng latLng = new LatLng (Double .parseDouble (latitude ), Double .parseDouble (longitude ), 0 );
367
- media .setCoordinates (latLng );
368
- }
369
-
370
- media .setLicenseInformation (metadata .licenseShortName ().value (), metadata .licenseUrl ().value ());
371
- return media ;
389
+ public void setThumbUrl (String thumbUrl ) {
390
+ this .thumbUrl = thumbUrl ;
372
391
}
373
392
374
393
public String getLicenseUrl () {
@@ -482,6 +501,7 @@ public int describeContents() {
482
501
@ Override
483
502
public void writeToParcel (Parcel parcel , int flags ) {
484
503
parcel .writeParcelable (localUri , flags );
504
+ parcel .writeString (thumbUrl );
485
505
parcel .writeString (imageUrl );
486
506
parcel .writeString (filename );
487
507
parcel .writeString (description );
0 commit comments