mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Remove thumbnails from the AttachmentDatabase.
Glide can do everything for us now, including video thumbnails.
This commit is contained in:
@@ -39,19 +39,13 @@ public class AudioSlide extends Slide {
|
||||
}
|
||||
|
||||
public AudioSlide(Context context, Uri uri, long dataSize, String contentType, boolean voiceNote) {
|
||||
super(context, new UriAttachment(uri, null, contentType, AttachmentDatabase.TRANSFER_PROGRESS_STARTED, dataSize, 0, 0, null, null, voiceNote, false, false, null, null, null, null, null));
|
||||
super(context, new UriAttachment(uri, contentType, AttachmentDatabase.TRANSFER_PROGRESS_STARTED, dataSize, 0, 0, null, null, voiceNote, false, false, null, null, null, null, null));
|
||||
}
|
||||
|
||||
public AudioSlide(Context context, Attachment attachment) {
|
||||
super(context, attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Uri getThumbnailUri() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlaceholder() {
|
||||
return true;
|
||||
|
||||
@@ -29,7 +29,7 @@ class DecryptableStreamLocalUriFetcher extends StreamLocalUriFetcher {
|
||||
|
||||
@Override
|
||||
protected InputStream loadResource(Uri uri, ContentResolver contentResolver) throws FileNotFoundException {
|
||||
if (MediaUtil.hasVideoThumbnail(uri)) {
|
||||
if (MediaUtil.hasVideoThumbnail(context, uri)) {
|
||||
Bitmap thumbnail = MediaUtil.getVideoThumbnail(context, uri, 1000);
|
||||
|
||||
if (thumbnail != null) {
|
||||
|
||||
@@ -26,11 +26,6 @@ public class GifSlide extends ImageSlide {
|
||||
this.borderless = borderless;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Uri getThumbnailUri() {
|
||||
return getUri();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBorderless() {
|
||||
return borderless;
|
||||
|
||||
@@ -54,11 +54,6 @@ public class ImageSlide extends Slide {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Uri getThumbnailUri() {
|
||||
return getUri();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasImage() {
|
||||
return true;
|
||||
|
||||
@@ -48,8 +48,8 @@ public abstract class MediaConstraints {
|
||||
|
||||
public boolean isSatisfied(@NonNull Context context, @NonNull Attachment attachment) {
|
||||
try {
|
||||
return (MediaUtil.isGif(attachment) && attachment.getSize() <= getGifMaxSize(context) && isWithinBounds(context, attachment.getDataUri())) ||
|
||||
(MediaUtil.isImage(attachment) && attachment.getSize() <= getImageMaxSize(context) && isWithinBounds(context, attachment.getDataUri())) ||
|
||||
return (MediaUtil.isGif(attachment) && attachment.getSize() <= getGifMaxSize(context) && isWithinBounds(context, attachment.getUri())) ||
|
||||
(MediaUtil.isImage(attachment) && attachment.getSize() <= getImageMaxSize(context) && isWithinBounds(context, attachment.getUri())) ||
|
||||
(MediaUtil.isAudio(attachment) && attachment.getSize() <= getAudioMaxSize(context)) ||
|
||||
(MediaUtil.isVideo(attachment) && attachment.getSize() <= getVideoMaxSize(context)) ||
|
||||
(MediaUtil.isFile(attachment) && attachment.getSize() <= getDocumentMaxSize(context));
|
||||
|
||||
@@ -22,24 +22,20 @@ import java.io.InputStream;
|
||||
public class PartAuthority {
|
||||
|
||||
private static final String PART_URI_STRING = "content://org.thoughtcrime.securesms/part";
|
||||
private static final String THUMB_URI_STRING = "content://org.thoughtcrime.securesms/thumb";
|
||||
private static final String STICKER_URI_STRING = "content://org.thoughtcrime.securesms/sticker";
|
||||
private static final Uri PART_CONTENT_URI = Uri.parse(PART_URI_STRING);
|
||||
private static final Uri THUMB_CONTENT_URI = Uri.parse(THUMB_URI_STRING);
|
||||
private static final Uri STICKER_CONTENT_URI = Uri.parse(STICKER_URI_STRING);
|
||||
|
||||
private static final int PART_ROW = 1;
|
||||
private static final int THUMB_ROW = 2;
|
||||
private static final int PERSISTENT_ROW = 3;
|
||||
private static final int BLOB_ROW = 4;
|
||||
private static final int STICKER_ROW = 5;
|
||||
private static final int PERSISTENT_ROW = 2;
|
||||
private static final int BLOB_ROW = 3;
|
||||
private static final int STICKER_ROW = 4;
|
||||
|
||||
private static final UriMatcher uriMatcher;
|
||||
|
||||
static {
|
||||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
uriMatcher.addURI("org.thoughtcrime.securesms", "part/*/#", PART_ROW);
|
||||
uriMatcher.addURI("org.thoughtcrime.securesms", "thumb/*/#", THUMB_ROW);
|
||||
uriMatcher.addURI("org.thoughtcrime.securesms", "sticker/#", STICKER_ROW);
|
||||
uriMatcher.addURI(DeprecatedPersistentBlobProvider.AUTHORITY, DeprecatedPersistentBlobProvider.EXPECTED_PATH_OLD, PERSISTENT_ROW);
|
||||
uriMatcher.addURI(DeprecatedPersistentBlobProvider.AUTHORITY, DeprecatedPersistentBlobProvider.EXPECTED_PATH_NEW, PERSISTENT_ROW);
|
||||
@@ -49,13 +45,6 @@ public class PartAuthority {
|
||||
public static InputStream getAttachmentThumbnailStream(@NonNull Context context, @NonNull Uri uri)
|
||||
throws IOException
|
||||
{
|
||||
String contentType = getAttachmentContentType(context, uri);
|
||||
int match = uriMatcher.match(uri);
|
||||
|
||||
if (match == PART_ROW && MediaUtil.isVideoType(contentType)) {
|
||||
return DatabaseFactory.getAttachmentDatabase(context).getThumbnailStream(new PartUriParser(uri).getPartId());
|
||||
}
|
||||
|
||||
return getAttachmentStream(context, uri);
|
||||
}
|
||||
|
||||
@@ -66,7 +55,6 @@ public class PartAuthority {
|
||||
try {
|
||||
switch (match) {
|
||||
case PART_ROW: return DatabaseFactory.getAttachmentDatabase(context).getAttachmentStream(new PartUriParser(uri).getPartId(), 0);
|
||||
case THUMB_ROW: return DatabaseFactory.getAttachmentDatabase(context).getThumbnailStream(new PartUriParser(uri).getPartId());
|
||||
case STICKER_ROW: return DatabaseFactory.getStickerDatabase(context).getStickerStream(ContentUris.parseId(uri));
|
||||
case PERSISTENT_ROW: return DeprecatedPersistentBlobProvider.getInstance(context).getStream(context, ContentUris.parseId(uri));
|
||||
case BLOB_ROW: return BlobProvider.getInstance().getStream(context, uri);
|
||||
@@ -81,7 +69,6 @@ public class PartAuthority {
|
||||
int match = uriMatcher.match(uri);
|
||||
|
||||
switch (match) {
|
||||
case THUMB_ROW:
|
||||
case PART_ROW:
|
||||
Attachment attachment = DatabaseFactory.getAttachmentDatabase(context).getAttachment(new PartUriParser(uri).getPartId());
|
||||
|
||||
@@ -100,7 +87,6 @@ public class PartAuthority {
|
||||
int match = uriMatcher.match(uri);
|
||||
|
||||
switch (match) {
|
||||
case THUMB_ROW:
|
||||
case PART_ROW:
|
||||
Attachment attachment = DatabaseFactory.getAttachmentDatabase(context).getAttachment(new PartUriParser(uri).getPartId());
|
||||
|
||||
@@ -119,7 +105,6 @@ public class PartAuthority {
|
||||
int match = uriMatcher.match(uri);
|
||||
|
||||
switch (match) {
|
||||
case THUMB_ROW:
|
||||
case PART_ROW:
|
||||
Attachment attachment = DatabaseFactory.getAttachmentDatabase(context).getAttachment(new PartUriParser(uri).getPartId());
|
||||
|
||||
@@ -145,8 +130,7 @@ public class PartAuthority {
|
||||
}
|
||||
|
||||
public static Uri getAttachmentThumbnailUri(AttachmentId attachmentId) {
|
||||
Uri uri = Uri.withAppendedPath(THUMB_CONTENT_URI, String.valueOf(attachmentId.getUniqueId()));
|
||||
return ContentUris.withAppendedId(uri, attachmentId.getRowId());
|
||||
return getAttachmentDataUri(attachmentId);
|
||||
}
|
||||
|
||||
public static Uri getStickerUri(long id) {
|
||||
@@ -157,11 +141,18 @@ public class PartAuthority {
|
||||
int match = uriMatcher.match(uri);
|
||||
switch (match) {
|
||||
case PART_ROW:
|
||||
case THUMB_ROW:
|
||||
case PERSISTENT_ROW:
|
||||
case BLOB_ROW:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isAttachmentUri(@NonNull Uri uri) {
|
||||
return uriMatcher.match(uri) == PART_ROW;
|
||||
}
|
||||
|
||||
public static @NonNull AttachmentId requireAttachmentId(@NonNull Uri uri) {
|
||||
return new PartUriParser(uri).getPartId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,12 +52,7 @@ public abstract class Slide {
|
||||
|
||||
@Nullable
|
||||
public Uri getUri() {
|
||||
return attachment.getDataUri();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Uri getThumbnailUri() {
|
||||
return attachment.getThumbnailUri();
|
||||
return attachment.getUri();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -188,7 +183,6 @@ public abstract class Slide {
|
||||
String resolvedType = Optional.fromNullable(MediaUtil.getMimeType(context, uri)).or(defaultMime);
|
||||
String fastPreflightId = String.valueOf(new SecureRandom().nextLong());
|
||||
return new UriAttachment(uri,
|
||||
hasThumbnail ? uri : null,
|
||||
resolvedType,
|
||||
AttachmentDatabase.TRANSFER_PROGRESS_STARTED,
|
||||
size,
|
||||
@@ -246,13 +240,12 @@ public abstract class Slide {
|
||||
this.hasImage() == that.hasImage() &&
|
||||
this.hasVideo() == that.hasVideo() &&
|
||||
this.getTransferState() == that.getTransferState() &&
|
||||
Util.equals(this.getUri(), that.getUri()) &&
|
||||
Util.equals(this.getThumbnailUri(), that.getThumbnailUri());
|
||||
Util.equals(this.getUri(), that.getUri());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Util.hashCode(getContentType(), hasAudio(), hasImage(),
|
||||
hasVideo(), getUri(), getThumbnailUri(), getTransferState());
|
||||
hasVideo(), getUri(), getTransferState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,6 @@ public class StickerSlide extends Slide {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Uri getThumbnailUri() {
|
||||
return getUri();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSticker() {
|
||||
return true;
|
||||
|
||||
@@ -37,7 +37,11 @@ public class VideoSlide extends Slide {
|
||||
}
|
||||
|
||||
public VideoSlide(Context context, Uri uri, long dataSize, @Nullable String caption, @Nullable AttachmentDatabase.TransformProperties transformProperties) {
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaUtil.VIDEO_UNSPECIFIED, dataSize, 0, 0, MediaUtil.hasVideoThumbnail(uri), null, caption, null, null, null, false, false, false, transformProperties));
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaUtil.VIDEO_UNSPECIFIED, dataSize, 0, 0, MediaUtil.hasVideoThumbnail(context, uri), null, caption, null, null, null, false, false, false, transformProperties));
|
||||
}
|
||||
|
||||
public VideoSlide(Context context, Uri uri, long dataSize, int width, int height, @Nullable String caption, @Nullable AttachmentDatabase.TransformProperties transformProperties) {
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaUtil.VIDEO_UNSPECIFIED, dataSize, width, height, MediaUtil.hasVideoThumbnail(context, uri), null, caption, null, null, null, false, false, false, transformProperties));
|
||||
}
|
||||
|
||||
public VideoSlide(Context context, Attachment attachment) {
|
||||
|
||||
Reference in New Issue
Block a user