mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 12:38:27 +00:00
Clear Glide disk cache after image deletion.
This commit is contained in:
parent
1d4020ffc6
commit
e09c99102e
@ -31,6 +31,8 @@ import android.text.TextUtils;
|
|||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
import net.sqlcipher.database.SQLiteDatabase;
|
import net.sqlcipher.database.SQLiteDatabase;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@ -248,11 +250,11 @@ public class AttachmentDatabase extends Database {
|
|||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = database.query(TABLE_NAME, new String[] {DATA, THUMBNAIL}, MMS_ID + " = ?",
|
cursor = database.query(TABLE_NAME, new String[] {DATA, THUMBNAIL, CONTENT_TYPE}, MMS_ID + " = ?",
|
||||||
new String[] {mmsId+""}, null, null, null);
|
new String[] {mmsId+""}, null, null, null);
|
||||||
|
|
||||||
while (cursor != null && cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
deleteAttachmentOnDisk(cursor.getString(0), cursor.getString(1));
|
deleteAttachmentOnDisk(cursor.getString(0), cursor.getString(1), cursor.getString(2));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null)
|
if (cursor != null)
|
||||||
@ -267,7 +269,7 @@ public class AttachmentDatabase extends Database {
|
|||||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||||
|
|
||||||
try (Cursor cursor = database.query(TABLE_NAME,
|
try (Cursor cursor = database.query(TABLE_NAME,
|
||||||
new String[]{DATA, THUMBNAIL},
|
new String[]{DATA, THUMBNAIL, CONTENT_TYPE},
|
||||||
PART_ID_WHERE,
|
PART_ID_WHERE,
|
||||||
id.toStrings(),
|
id.toStrings(),
|
||||||
null,
|
null,
|
||||||
@ -278,11 +280,12 @@ public class AttachmentDatabase extends Database {
|
|||||||
Log.w(TAG, "Tried to delete an attachment, but it didn't exist.");
|
Log.w(TAG, "Tried to delete an attachment, but it didn't exist.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String data = cursor.getString(0);
|
String data = cursor.getString(0);
|
||||||
String thumbnail = cursor.getString(1);
|
String thumbnail = cursor.getString(1);
|
||||||
|
String contentType = cursor.getString(2);
|
||||||
|
|
||||||
database.delete(TABLE_NAME, PART_ID_WHERE, id.toStrings());
|
database.delete(TABLE_NAME, PART_ID_WHERE, id.toStrings());
|
||||||
deleteAttachmentOnDisk(data, thumbnail);
|
deleteAttachmentOnDisk(data, thumbnail, contentType);
|
||||||
notifyAttachmentListeners();
|
notifyAttachmentListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,7 +306,7 @@ public class AttachmentDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
private void deleteAttachmentOnDisk(@Nullable String data, @Nullable String thumbnail) {
|
private void deleteAttachmentOnDisk(@Nullable String data, @Nullable String thumbnail, @Nullable String contentType) {
|
||||||
if (!TextUtils.isEmpty(data)) {
|
if (!TextUtils.isEmpty(data)) {
|
||||||
new File(data).delete();
|
new File(data).delete();
|
||||||
}
|
}
|
||||||
@ -311,6 +314,10 @@ public class AttachmentDatabase extends Database {
|
|||||||
if (!TextUtils.isEmpty(thumbnail)) {
|
if (!TextUtils.isEmpty(thumbnail)) {
|
||||||
new File(thumbnail).delete();
|
new File(thumbnail).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MediaUtil.isImageType(contentType) || thumbnail != null) {
|
||||||
|
Glide.get(context).clearDiskCache();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertAttachmentsForPlaceholder(long mmsId, @NonNull AttachmentId attachmentId, @NonNull InputStream inputStream)
|
public void insertAttachmentsForPlaceholder(long mmsId, @NonNull AttachmentId attachmentId, @NonNull InputStream inputStream)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user