11
11
import fr .free .nrw .commons .utils .MediaDataExtractorUtil ;
12
12
import java .text .ParseException ;
13
13
import java .util .ArrayList ;
14
- import java .util .Collections ;
15
14
import java .util .Date ;
16
- import java .util .HashMap ;
17
15
import java .util .List ;
18
16
import java .util .Locale ;
19
17
import java .util .Map ;
@@ -30,53 +28,42 @@ public class Media implements Parcelable {
30
28
31
29
// Primary metadata fields
32
30
@ Nullable
33
- public Uri localUri ;
34
- public String thumbUrl ;
35
- public String imageUrl ;
36
- public String filename ;
37
- public String thumbnailTitle ;
38
- /**
31
+ private Uri localUri ;
32
+ private String thumbUrl ;
33
+ private String imageUrl ;
34
+ private String filename ;
35
+ private String thumbnailTitle ;
36
+ /*
39
37
* Captions are a feature part of Structured data. They are meant to store short, multilingual descriptions about files
40
38
* This is a replacement of the previously used titles for images (titles were not multilingual)
41
39
* Also now captions replace the previous convention of using title for filename
42
40
*/
43
41
private String caption ;
44
- public String description ; // monolingual description on input...
45
- public String discussion ;
42
+ private String description ; // monolingual description on input...
43
+ private String discussion ;
46
44
private long dataLength ;
47
- public Date dateCreated ;
48
- @ Nullable public Date dateUploaded ;
49
- public String license ;
50
- public String licenseUrl ;
51
- public String creator ;
45
+ private Date dateCreated ;
46
+ @ Nullable private Date dateUploaded ;
47
+ private String license ;
48
+ private String licenseUrl ;
49
+ private String creator ;
52
50
/**
53
51
* Wikibase Identifier associated with media files
54
52
*/
55
- public String pageId ;
53
+ private String pageId ;
56
54
private List <String > categories ; // as loaded at runtime?
57
55
/**
58
56
* Depicts is a feature part of Structured data. Multiple Depictions can be added for an image just like categories.
59
57
* However unlike categories depictions is multi-lingual
60
58
*/
61
- public ArrayList <Map <String , String >> depictionList ;
62
- public boolean requestedDeletion ;
63
- public HashMap <String , String > descriptions ; // multilingual descriptions as loaded
64
- /**
65
- * This hasmap stores the list of multilingual captions, where
66
- * key of the HashMap is the language and value is the caption in the corresponding language
67
- * Ex: key = "en", value: "<caption in short in English>"
68
- * key = "de" , value: "<caption in german>"
69
- */
70
- public Map <String , String > captions ;
71
- @ Nullable public LatLng coordinates ;
59
+ private List <Map <String , String >> depictionList = new ArrayList <>();
60
+ private boolean requestedDeletion ;
61
+ @ Nullable private LatLng coordinates ;
72
62
73
63
/**
74
64
* Provides local constructor
75
65
*/
76
- protected Media () {
77
- this .categories = new ArrayList <>();
78
- this .descriptions = new HashMap <>();
79
- this .captions = new HashMap <>();
66
+ public Media () {
80
67
}
81
68
82
69
/**
@@ -85,7 +72,6 @@ protected Media() {
85
72
* @param filename Media filename
86
73
*/
87
74
public Media (String filename ) {
88
- this ();
89
75
this .filename = filename ;
90
76
}
91
77
@@ -94,28 +80,35 @@ public Media(String filename) {
94
80
* @param localUri Media URI
95
81
* @param imageUrl Media image URL
96
82
* @param filename Media filename
97
- * @param captions Media captions
98
83
* @param description Media description
99
84
* @param dataLength Media date length
100
85
* @param dateCreated Media creation date
101
86
* @param dateUploaded Media date uploaded
102
87
* @param creator Media creator
103
88
*/
104
- public Media (Uri localUri , String imageUrl , String filename , Map < String , String > captions , String description ,
105
- long dataLength , Date dateCreated , Date dateUploaded , String creator ) {
106
- this ();
89
+ public Media (Uri localUri , String imageUrl , String filename ,
90
+ String description ,
91
+ long dataLength , Date dateCreated , Date dateUploaded , String creator ) {
107
92
this .localUri = localUri ;
108
93
this .thumbUrl = imageUrl ;
109
94
this .imageUrl = imageUrl ;
110
95
this .filename = filename ;
111
- this .captions = captions ;
112
96
this .description = description ;
113
97
this .dataLength = dataLength ;
114
98
this .dateCreated = dateCreated ;
115
99
this .dateUploaded = dateUploaded ;
116
100
this .creator = creator ;
117
- this .categories = new ArrayList <>();
118
- this .descriptions = new HashMap <>();
101
+ }
102
+
103
+ public Media (Uri localUri , String filename ,
104
+ String description , String creator , List <String > categories ) {
105
+ this (localUri ,null , filename ,
106
+ description , -1 , null , new Date (), creator );
107
+ this .categories = categories ;
108
+ }
109
+
110
+ public Media (String title , Date date , String user ) {
111
+ this (null , null , title , "" , -1 , date , date , user );
119
112
}
120
113
121
114
/**
@@ -135,7 +128,7 @@ public static Media from(MwQueryPage page) {
135
128
ExtMetadata metadata = imageInfo .getMetadata ();
136
129
if (metadata == null ) {
137
130
Media media = new Media (null , imageInfo .getOriginalUrl (),
138
- page .title (), new HashMap <>() , "" , 0 , null , null , null );
131
+ page .title (), "" , 0 , null , null , null );
139
132
if (!StringUtils .isBlank (imageInfo .getThumbUrl ())) {
140
133
media .setThumbUrl (imageInfo .getThumbUrl ());
141
134
}
@@ -145,8 +138,7 @@ public static Media from(MwQueryPage page) {
145
138
Media media = new Media (null ,
146
139
imageInfo .getOriginalUrl (),
147
140
page .title (),
148
- new HashMap <>(),
149
- "" ,
141
+ "" ,
150
142
0 ,
151
143
safeParseDate (metadata .dateTime ()),
152
144
safeParseDate (metadata .dateTime ()),
@@ -164,7 +156,7 @@ public static Media from(MwQueryPage page) {
164
156
language = "default" ;
165
157
}
166
158
167
- media .setDescriptions ( Collections . singletonMap ( language , metadata .imageDescription () ));
159
+ media .setDescription ( metadata .imageDescription ());
168
160
media .setCategories (MediaDataExtractorUtil .extractCategoriesFromList (metadata .getCategories ()));
169
161
String latitude = metadata .getGpsLatitude ();
170
162
String longitude = metadata .getGpsLongitude ();
@@ -202,7 +194,7 @@ public String getPageId() {
202
194
/**
203
195
*sets pageId for the current media object
204
196
*/
205
- private void setPageId (String pageId ) {
197
+ public void setPageId (String pageId ) {
206
198
this .pageId = pageId ;
207
199
}
208
200
@@ -313,22 +305,11 @@ public String getCaption() {
313
305
/**
314
306
* @return depictions associated with the current media
315
307
*/
316
- public ArrayList <Map <String , String >> getDepiction () {
308
+ public List <Map <String , String >> getDepiction () {
317
309
return depictionList ;
318
310
}
319
311
320
- /**
321
- * Captions are a feature part of Structured data. They are meant to store short, multilingual descriptions about files
322
- * This is a replacement of the previously used titles for images (titles were not multilingual)
323
- * Also now captions replace the previous convention of using title for filename
324
- *
325
- * key of the HashMap is the language and value is the caption in the corresponding language
326
- *
327
- * returns list of captions stored in hashmap
328
- */
329
- public Map <String , String > getCaptions () {
330
- return captions ;
331
- }
312
+
332
313
333
314
/**
334
315
* Sets the file description.
@@ -451,7 +432,6 @@ public List<String> getCategories() {
451
432
return categories ;
452
433
}
453
434
454
-
455
435
/**
456
436
* Sets the categories the file falls under.
457
437
* </p>
@@ -463,36 +443,6 @@ public void setCategories(List<String> categories) {
463
443
this .categories = categories ;
464
444
}
465
445
466
- /**
467
- * Modifies (or sets) media descriptions
468
- * @param descriptions Media descriptions
469
- */
470
- void setDescriptions (Map <String , String > descriptions ) {
471
- this .descriptions .clear ();
472
- this .descriptions .putAll (descriptions );
473
- }
474
-
475
- /**
476
- * Gets media description in preferred language
477
- * @param preferredLanguage Language preferred
478
- * @return Description in preferred language
479
- */
480
- public String getDescription (String preferredLanguage ) {
481
- if (descriptions .containsKey (preferredLanguage )) {
482
- // See if the requested language is there.
483
- return descriptions .get (preferredLanguage );
484
- } else if (descriptions .containsKey ("en" )) {
485
- // Ah, English. Language of the world, until the Chinese crush us.
486
- return descriptions .get ("en" );
487
- } else if (descriptions .containsKey ("default" )) {
488
- // No languages marked...
489
- return descriptions .get ("default" );
490
- } else {
491
- // FIXME: return the first available non-English description?
492
- return "" ;
493
- }
494
- }
495
-
496
446
@ Nullable private static Date safeParseDate (String dateStr ) {
497
447
try {
498
448
return CommonsDateUtil .getIso8601DateFormatShort ().parse (dateStr );
@@ -501,20 +451,19 @@ public String getDescription(String preferredLanguage) {
501
451
}
502
452
}
503
453
504
-
505
-
506
454
/**
507
455
* Set requested deletion to true
456
+ * @param requestedDeletion
508
457
*/
509
- public void setRequestedDeletion (){
510
- requestedDeletion = true ;
458
+ public void setRequestedDeletion (boolean requestedDeletion ){
459
+ this . requestedDeletion = requestedDeletion ;
511
460
}
512
461
513
462
/**
514
463
* Get the value of requested deletion
515
464
* @return boolean requestedDeletion
516
465
*/
517
- public boolean getRequestedDeletion (){
466
+ public boolean isRequestedDeletion (){
518
467
return requestedDeletion ;
519
468
}
520
469
@@ -539,15 +488,29 @@ public void setCaption(String caption) {
539
488
this .caption = caption ;
540
489
}
541
490
542
- public void setCaptions (HashMap <String , String > captions ) {
543
- this .captions = captions ;
491
+ /* Sets depictions for the current media obtained fro Wikibase API*/
492
+ public void setDepictionList (List <Map <String , String >> depictions ) {
493
+ this .depictionList = depictions ;
544
494
}
545
495
546
- /**
547
- * Sets depictions for the current media obtained fro Wikibase API
548
- */
549
- public void setDepiction (ArrayList <Map <String , String >> depictions ) {
550
- this .depictionList = depictions ;
496
+ public void setLocalUri (@ Nullable final Uri localUri ) {
497
+ this .localUri = localUri ;
498
+ }
499
+
500
+ public void setImageUrl (final String imageUrl ) {
501
+ this .imageUrl = imageUrl ;
502
+ }
503
+
504
+ public void setDateUploaded (@ Nullable final Date dateUploaded ) {
505
+ this .dateUploaded = dateUploaded ;
506
+ }
507
+
508
+ public void setLicenseUrl (final String licenseUrl ) {
509
+ this .licenseUrl = licenseUrl ;
510
+ }
511
+
512
+ public List <Map <String , String >> getDepictionList () {
513
+ return depictionList ;
551
514
}
552
515
553
516
@ Override
@@ -581,7 +544,6 @@ public void writeToParcel(Parcel dest, int flags) {
581
544
dest .writeStringList (this .categories );
582
545
dest .writeList (this .depictionList );
583
546
dest .writeByte (this .requestedDeletion ? (byte ) 1 : (byte ) 0 );
584
- dest .writeSerializable (this .descriptions );
585
547
dest .writeParcelable (this .coordinates , flags );
586
548
}
587
549
@@ -608,7 +570,6 @@ protected Media(Parcel in) {
608
570
this .categories =list ;
609
571
in .readList (depictionList ,null );
610
572
this .requestedDeletion = in .readByte () != 0 ;
611
- this .descriptions = (HashMap <String , String >) in .readSerializable ();
612
573
this .coordinates = in .readParcelable (LatLng .class .getClassLoader ());
613
574
}
614
575
0 commit comments