mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
No longer generate image thumbnails manually
Delete manually calculated image thumbnails
This commit is contained in:
parent
95d76638dc
commit
3c30db7edf
@ -642,12 +642,10 @@ public class AttachmentDatabase extends Database {
|
||||
return null;
|
||||
}
|
||||
|
||||
ThumbnailData data;
|
||||
ThumbnailData data = null;
|
||||
|
||||
if (MediaUtil.isVideoType(attachment.getContentType())) {
|
||||
data = generateVideoThumbnail(attachmentId);
|
||||
} else{
|
||||
data = MediaUtil.generateThumbnail(context, attachment.getContentType(), attachment.getDataUri());
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package org.thoughtcrime.securesms.database.helpers;
|
||||
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
@ -29,14 +31,17 @@ import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = SQLCipherOpenHelper.class.getSimpleName();
|
||||
|
||||
private static final int RECIPIENT_CALL_RINGTONE_VERSION = 2;
|
||||
private static final int MIGRATE_PREKEYS_VERSION = 3;
|
||||
private static final int MIGRATE_SESSIONS_VERSION = 4;
|
||||
private static final int RECIPIENT_CALL_RINGTONE_VERSION = 2;
|
||||
private static final int MIGRATE_PREKEYS_VERSION = 3;
|
||||
private static final int MIGRATE_SESSIONS_VERSION = 4;
|
||||
private static final int NO_MORE_IMAGE_THUMBNAILS_VERSION = 5;
|
||||
|
||||
private static final int DATABASE_VERSION = 4;
|
||||
private static final String DATABASE_NAME = "signal.db";
|
||||
@ -134,6 +139,28 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
SessionStoreMigrationHelper.migrateSessions(context, db);
|
||||
}
|
||||
|
||||
if (oldVersion < NO_MORE_IMAGE_THUMBNAILS_VERSION) {
|
||||
ContentValues update = new ContentValues();
|
||||
update.put("thumbnail", (String)null);
|
||||
update.put("aspect_ratio", (String)null);
|
||||
update.put("thumbnail_random", (String)null);
|
||||
|
||||
try (Cursor cursor = db.query("part", new String[] {"_id", "ct", "thumbnail"}, "thumbnail IS NOT NULL", null, null, null, null)) {
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow("_id"));
|
||||
String contentType = cursor.getString(cursor.getColumnIndexOrThrow("ct"));
|
||||
|
||||
if (contentType != null && !contentType.startsWith("video")) {
|
||||
String thumbnailPath = cursor.getString(cursor.getColumnIndexOrThrow("thumbnail"));
|
||||
File thumbnailFile = new File(thumbnailPath);
|
||||
thumbnailFile.delete();
|
||||
|
||||
db.update("part", update, "_id = ?", new String[] {String.valueOf(id)});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
|
@ -11,14 +11,10 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.mms.AudioSlide;
|
||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
||||
import org.thoughtcrime.securesms.mms.DocumentSlide;
|
||||
import org.thoughtcrime.securesms.mms.GifSlide;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.mms.ImageSlide;
|
||||
import org.thoughtcrime.securesms.mms.MmsSlide;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
@ -28,7 +24,6 @@ import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class MediaUtil {
|
||||
|
||||
@ -42,42 +37,6 @@ public class MediaUtil {
|
||||
public static final String VIDEO_UNSPECIFIED = "video/*";
|
||||
|
||||
|
||||
public static @Nullable ThumbnailData generateThumbnail(Context context, String contentType, Uri uri)
|
||||
throws BitmapDecodingException
|
||||
{
|
||||
long startMillis = System.currentTimeMillis();
|
||||
ThumbnailData data = null;
|
||||
|
||||
if (isImageType(contentType)) {
|
||||
data = new ThumbnailData(generateImageThumbnail(context, uri));
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
Log.w(TAG, String.format("generated thumbnail for part, %dx%d (%.3f:1) in %dms",
|
||||
data.getBitmap().getWidth(), data.getBitmap().getHeight(),
|
||||
data.getAspectRatio(), System.currentTimeMillis() - startMillis));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private static Bitmap generateImageThumbnail(Context context, Uri uri)
|
||||
throws BitmapDecodingException
|
||||
{
|
||||
try {
|
||||
int maxSize = context.getResources().getDimensionPixelSize(R.dimen.media_bubble_height);
|
||||
return GlideApp.with(context.getApplicationContext())
|
||||
.asBitmap()
|
||||
.load(new DecryptableUri(uri))
|
||||
.centerCrop()
|
||||
.into(maxSize, maxSize)
|
||||
.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new BitmapDecodingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Slide getSlideForAttachment(Context context, Attachment attachment) {
|
||||
Slide slide = null;
|
||||
if (isGif(attachment.getContentType())) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user