@@ -42,6 +42,7 @@ public Media[] newArray(int i) {
4242
4343 // Primary metadata fields
4444 protected Uri localUri ;
45+ private String thumbUrl ;
4546 protected String imageUrl ;
4647 protected String filename ;
4748 protected String description ; // monolingual description on input...
@@ -93,6 +94,7 @@ public Media(Uri localUri, String imageUrl, String filename, String description,
9394 long dataLength , Date dateCreated , Date dateUploaded , String creator ) {
9495 this ();
9596 this .localUri = localUri ;
97+ this .thumbUrl = imageUrl ;
9698 this .imageUrl = imageUrl ;
9799 this .filename = filename ;
98100 this .description = description ;
@@ -107,6 +109,7 @@ public Media(Uri localUri, String imageUrl, String filename, String description,
107109 @ SuppressWarnings ("unchecked" )
108110 public Media (Parcel in ) {
109111 localUri = in .readParcelable (Uri .class .getClassLoader ());
112+ thumbUrl = in .readString ();
110113 imageUrl = in .readString ();
111114 filename = in .readString ();
112115 description = in .readString ();
@@ -124,6 +127,67 @@ public Media(Parcel in) {
124127 descriptions = in .readHashMap (ClassLoader .getSystemClassLoader ());
125128 }
126129
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+
127191 /**
128192 * Gets tag of media
129193 * @param key Media key
@@ -322,53 +386,8 @@ public String getLicense() {
322386 return license ;
323387 }
324388
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 ;
372391 }
373392
374393 public String getLicenseUrl () {
@@ -482,6 +501,7 @@ public int describeContents() {
482501 @ Override
483502 public void writeToParcel (Parcel parcel , int flags ) {
484503 parcel .writeParcelable (localUri , flags );
504+ parcel .writeString (thumbUrl );
485505 parcel .writeString (imageUrl );
486506 parcel .writeString (filename );
487507 parcel .writeString (description );
0 commit comments