2015-10-12 18:25:05 -07:00
|
|
|
package org.thoughtcrime.securesms.attachments;
|
|
|
|
|
|
|
|
import android.net.Uri;
|
2016-12-11 13:37:27 -08:00
|
|
|
import android.support.annotation.Nullable;
|
2015-10-12 18:25:05 -07:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
|
|
|
|
|
|
|
public class DatabaseAttachment extends Attachment {
|
|
|
|
|
|
|
|
private final AttachmentId attachmentId;
|
|
|
|
private final long mmsId;
|
|
|
|
private final boolean hasData;
|
2016-12-11 13:37:27 -08:00
|
|
|
private final boolean hasThumbnail;
|
2015-10-12 18:25:05 -07:00
|
|
|
|
2016-12-11 13:37:27 -08:00
|
|
|
public DatabaseAttachment(AttachmentId attachmentId, long mmsId,
|
|
|
|
boolean hasData, boolean hasThumbnail,
|
2015-10-12 18:25:05 -07:00
|
|
|
String contentType, int transferProgress, long size,
|
2017-03-28 12:05:30 -07:00
|
|
|
String fileName, String location, String key, String relay,
|
2017-05-11 22:46:35 -07:00
|
|
|
byte[] digest, String fastPreflightId, boolean voiceNote)
|
2015-10-12 18:25:05 -07:00
|
|
|
{
|
2017-05-11 22:46:35 -07:00
|
|
|
super(contentType, transferProgress, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote);
|
2015-10-12 18:25:05 -07:00
|
|
|
this.attachmentId = attachmentId;
|
|
|
|
this.hasData = hasData;
|
2016-12-11 13:37:27 -08:00
|
|
|
this.hasThumbnail = hasThumbnail;
|
2015-10-12 18:25:05 -07:00
|
|
|
this.mmsId = mmsId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-11 13:37:27 -08:00
|
|
|
@Nullable
|
2015-10-12 18:25:05 -07:00
|
|
|
public Uri getDataUri() {
|
2016-12-11 13:37:27 -08:00
|
|
|
if (hasData) {
|
|
|
|
return PartAuthority.getAttachmentDataUri(attachmentId);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2015-10-12 18:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-11 13:37:27 -08:00
|
|
|
@Nullable
|
2015-10-12 18:25:05 -07:00
|
|
|
public Uri getThumbnailUri() {
|
2016-12-11 13:37:27 -08:00
|
|
|
if (hasThumbnail) {
|
|
|
|
return PartAuthority.getAttachmentThumbnailUri(attachmentId);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2015-10-12 18:25:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public AttachmentId getAttachmentId() {
|
|
|
|
return attachmentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object other) {
|
|
|
|
return other != null &&
|
|
|
|
other instanceof DatabaseAttachment &&
|
|
|
|
((DatabaseAttachment) other).attachmentId.equals(this.attachmentId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return attachmentId.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getMmsId() {
|
|
|
|
return mmsId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasData() {
|
|
|
|
return hasData;
|
|
|
|
}
|
2016-12-11 13:37:27 -08:00
|
|
|
|
|
|
|
public boolean hasThumbnail() {
|
|
|
|
return hasThumbnail;
|
|
|
|
}
|
2015-10-12 18:25:05 -07:00
|
|
|
}
|