That fuck shit the fascists are using
1package org.tm.archive.mediasend;
2
3import android.net.Uri;
4import android.os.Parcel;
5import android.os.Parcelable;
6
7import androidx.annotation.NonNull;
8
9import org.tm.archive.database.AttachmentTable;
10import org.tm.archive.util.MediaUtil;
11import org.whispersystems.signalservice.api.util.Preconditions;
12import org.whispersystems.signalservice.internal.util.JsonUtil;
13
14import java.io.IOException;
15import java.util.Optional;
16
17/**
18 * Represents a piece of media that the user has on their device.
19 */
20public class Media implements Parcelable {
21
22 public static final String ALL_MEDIA_BUCKET_ID = "org.tm.archive.ALL_MEDIA";
23
24 private final Uri uri;
25 private final String mimeType;
26 private final long date;
27 private final int width;
28 private final int height;
29 private final long size;
30 private final long duration;
31 private final boolean borderless;
32 private final boolean videoGif;
33
34 private Optional<String> bucketId;
35 private Optional<String> caption;
36 private Optional<AttachmentTable.TransformProperties> transformProperties;
37
38 public Media(@NonNull Uri uri,
39 @NonNull String mimeType,
40 long date,
41 int width,
42 int height,
43 long size,
44 long duration,
45 boolean borderless,
46 boolean videoGif,
47 Optional<String> bucketId,
48 Optional<String> caption,
49 Optional<AttachmentTable.TransformProperties> transformProperties)
50 {
51 this.uri = uri;
52 this.mimeType = mimeType;
53 this.date = date;
54 this.width = width;
55 this.height = height;
56 this.size = size;
57 this.duration = duration;
58 this.borderless = borderless;
59 this.videoGif = videoGif;
60 this.bucketId = bucketId;
61 this.caption = caption;
62 this.transformProperties = transformProperties;
63 }
64
65 protected Media(Parcel in) {
66 uri = in.readParcelable(Uri.class.getClassLoader());
67 mimeType = in.readString();
68 date = in.readLong();
69 width = in.readInt();
70 height = in.readInt();
71 size = in.readLong();
72 duration = in.readLong();
73 borderless = in.readInt() == 1;
74 videoGif = in.readInt() == 1;
75 bucketId = Optional.ofNullable(in.readString());
76 caption = Optional.ofNullable(in.readString());
77 try {
78 String json = in.readString();
79 transformProperties = json == null ? Optional.empty() : Optional.ofNullable(JsonUtil.fromJson(json, AttachmentTable.TransformProperties.class));
80 } catch (IOException e) {
81 throw new AssertionError(e);
82 }
83 }
84
85 public Uri getUri() {
86 return uri;
87 }
88
89 public String getMimeType() {
90 return mimeType;
91 }
92
93 public long getDate() {
94 return date;
95 }
96
97 public int getWidth() {
98 return width;
99 }
100
101 public int getHeight() {
102 return height;
103 }
104
105 public long getSize() {
106 return size;
107 }
108
109 public long getDuration() {
110 return duration;
111 }
112
113 public boolean isBorderless() {
114 return borderless;
115 }
116
117 public boolean isVideoGif() {
118 return videoGif;
119 }
120
121 public Optional<String> getBucketId() {
122 return bucketId;
123 }
124
125 public Optional<String> getCaption() {
126 return caption;
127 }
128
129 public void setCaption(String caption) {
130 this.caption = Optional.ofNullable(caption);
131 }
132
133 public Optional<AttachmentTable.TransformProperties> getTransformProperties() {
134 return transformProperties;
135 }
136
137 @Override
138 public int describeContents() {
139 return 0;
140 }
141
142 @Override
143 public void writeToParcel(Parcel dest, int flags) {
144 dest.writeParcelable(uri, flags);
145 dest.writeString(mimeType);
146 dest.writeLong(date);
147 dest.writeInt(width);
148 dest.writeInt(height);
149 dest.writeLong(size);
150 dest.writeLong(duration);
151 dest.writeInt(borderless ? 1 : 0);
152 dest.writeInt(videoGif ? 1 : 0);
153 dest.writeString(bucketId.orElse(null));
154 dest.writeString(caption.orElse(null));
155 dest.writeString(transformProperties.map(JsonUtil::toJson).orElse(null));
156 }
157
158 public static final Creator<Media> CREATOR = new Creator<Media>() {
159 @Override
160 public Media createFromParcel(Parcel in) {
161 return new Media(in);
162 }
163
164 @Override
165 public Media[] newArray(int size) {
166 return new Media[size];
167 }
168 };
169
170 @Override
171 public boolean equals(Object o) {
172 if (this == o) return true;
173 if (o == null || getClass() != o.getClass()) return false;
174
175 Media media = (Media) o;
176
177 return uri.equals(media.uri);
178 }
179
180 @Override
181 public int hashCode() {
182 return uri.hashCode();
183 }
184
185 public static @NonNull Media withMimeType(@NonNull Media media, @NonNull String newMimeType) {
186 return new Media(media.getUri(),
187 newMimeType,
188 media.getDate(),
189 media.getWidth(),
190 media.getHeight(),
191 media.getSize(),
192 media.getDuration(),
193 media.isBorderless(),
194 media.isVideoGif(),
195 media.getBucketId(),
196 media.getCaption(),
197 media.getTransformProperties());
198 }
199
200 public static @NonNull Media stripTransform(@NonNull Media media) {
201 Preconditions.checkArgument(MediaUtil.isImageType(media.mimeType));
202
203 return new Media(media.getUri(),
204 media.getMimeType(),
205 media.getDate(),
206 media.getWidth(),
207 media.getHeight(),
208 media.getSize(),
209 media.getDuration(),
210 media.isBorderless(),
211 media.isVideoGif(),
212 media.getBucketId(),
213 media.getCaption(),
214 Optional.empty());
215 }
216}