29
29
public class Media implements Parcelable {
30
30
31
31
public static final Media EMPTY = new Media ("" );
32
- public static Creator <Media > CREATOR = new Creator <Media >() {
33
- @ Override
34
- public Media createFromParcel (Parcel parcel ) {
35
- return new Media (parcel );
36
- }
37
-
38
- @ Override
39
- public Media [] newArray (int i ) {
40
- return new Media [0 ];
41
- }
42
- };
43
32
44
33
// Primary metadata fields
45
34
protected Uri localUri ;
@@ -107,27 +96,6 @@ public Media(Uri localUri, String imageUrl, String filename, String description,
107
96
this .descriptions = new HashMap <>();
108
97
}
109
98
110
- @ SuppressWarnings ("unchecked" )
111
- public Media (Parcel in ) {
112
- localUri = in .readParcelable (Uri .class .getClassLoader ());
113
- thumbUrl = in .readString ();
114
- imageUrl = in .readString ();
115
- filename = in .readString ();
116
- description = in .readString ();
117
- dataLength = in .readLong ();
118
- dateCreated = (Date ) in .readSerializable ();
119
- dateUploaded = (Date ) in .readSerializable ();
120
- creator = in .readString ();
121
- tags = (HashMap <String , Object >) in .readSerializable ();
122
- width = in .readInt ();
123
- height = in .readInt ();
124
- license = in .readString ();
125
- if (categories != null ) {
126
- in .readStringList (categories );
127
- }
128
- descriptions = in .readHashMap (ClassLoader .getSystemClassLoader ());
129
- }
130
-
131
99
/**
132
100
* Creating Media object from MWQueryPage.
133
101
* Earlier only basic details were set for the media object but going forward,
@@ -499,40 +467,6 @@ public String getDescription(String preferredLanguage) {
499
467
}
500
468
}
501
469
502
- /**
503
- * Method of Parcelable interface
504
- * @return zero
505
- */
506
- @ Override
507
- public int describeContents () {
508
- return 0 ;
509
- }
510
-
511
- /**
512
- * Creates a way to transfer information between two or more
513
- * activities.
514
- * @param parcel Instance of Parcel
515
- * @param flags Parcel flag
516
- */
517
- @ Override
518
- public void writeToParcel (Parcel parcel , int flags ) {
519
- parcel .writeParcelable (localUri , flags );
520
- parcel .writeString (thumbUrl );
521
- parcel .writeString (imageUrl );
522
- parcel .writeString (filename );
523
- parcel .writeString (description );
524
- parcel .writeLong (dataLength );
525
- parcel .writeSerializable (dateCreated );
526
- parcel .writeSerializable (dateUploaded );
527
- parcel .writeString (creator );
528
- parcel .writeSerializable (tags );
529
- parcel .writeInt (width );
530
- parcel .writeInt (height );
531
- parcel .writeString (license );
532
- parcel .writeStringList (categories );
533
- parcel .writeMap (descriptions );
534
- }
535
-
536
470
/**
537
471
* Set requested deletion to true
538
472
*/
@@ -556,4 +490,68 @@ public boolean getRequestedDeletion(){
556
490
public void setLicense (String license ) {
557
491
this .license = license ;
558
492
}
493
+
494
+
495
+ @ Override
496
+ public int describeContents () {
497
+ return 0 ;
498
+ }
499
+
500
+ @ Override
501
+ public void writeToParcel (Parcel dest , int flags ) {
502
+ dest .writeParcelable (this .localUri , flags );
503
+ dest .writeString (this .thumbUrl );
504
+ dest .writeString (this .imageUrl );
505
+ dest .writeString (this .filename );
506
+ dest .writeString (this .description );
507
+ dest .writeString (this .discussion );
508
+ dest .writeLong (this .dataLength );
509
+ dest .writeLong (this .dateCreated != null ? this .dateCreated .getTime () : -1 );
510
+ dest .writeLong (this .dateUploaded != null ? this .dateUploaded .getTime () : -1 );
511
+ dest .writeInt (this .width );
512
+ dest .writeInt (this .height );
513
+ dest .writeString (this .license );
514
+ dest .writeString (this .licenseUrl );
515
+ dest .writeString (this .creator );
516
+ dest .writeStringList (this .categories );
517
+ dest .writeByte (this .requestedDeletion ? (byte ) 1 : (byte ) 0 );
518
+ dest .writeInt (this .descriptions .size ());
519
+ for (Map .Entry <String , String > entry : this .descriptions .entrySet ()) {
520
+ dest .writeString (entry .getKey ());
521
+ dest .writeString (entry .getValue ());
522
+ }
523
+ dest .writeSerializable (this .tags );
524
+ dest .writeParcelable (this .coordinates , flags );
525
+ }
526
+
527
+ protected Media (Parcel in ) {
528
+ this .localUri = in .readParcelable (Uri .class .getClassLoader ());
529
+ this .thumbUrl = in .readString ();
530
+ this .imageUrl = in .readString ();
531
+ this .filename = in .readString ();
532
+ this .description = in .readString ();
533
+ this .discussion = in .readString ();
534
+ this .dataLength = in .readLong ();
535
+ long tmpDateCreated = in .readLong ();
536
+ this .dateCreated = tmpDateCreated == -1 ? null : new Date (tmpDateCreated );
537
+ long tmpDateUploaded = in .readLong ();
538
+ this .dateUploaded = tmpDateUploaded == -1 ? null : new Date (tmpDateUploaded );
539
+ this .width = in .readInt ();
540
+ this .height = in .readInt ();
541
+ this .license = in .readString ();
542
+ this .licenseUrl = in .readString ();
543
+ this .creator = in .readString ();
544
+ this .categories = in .createStringArrayList ();
545
+ this .requestedDeletion = in .readByte () != 0 ;
546
+ int descriptionsSize = in .readInt ();
547
+ this .descriptions = new HashMap <>(descriptionsSize );
548
+ for (int i = 0 ; i < descriptionsSize ; i ++) {
549
+ String key = in .readString ();
550
+ String value = in .readString ();
551
+ this .descriptions .put (key , value );
552
+ }
553
+ this .tags = (HashMap <String , Object >) in .readSerializable ();
554
+ this .coordinates = in .readParcelable (LatLng .class .getClassLoader ());
555
+ }
556
+
559
557
}
0 commit comments