mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 09:08:49 -05:00
Delete attachment metadata and thumbnails when deleting attachments
This commit is contained in:
parent
c6696f632a
commit
4e5d116713
@ -2692,22 +2692,34 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
|
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
|
||||||
Cursor attachmentsCursor = null;
|
Cursor attachmentsCursor = null;
|
||||||
try {
|
try {
|
||||||
attachmentsCursor = db.query("attachments", new String[]
|
String accountUuid = mAccount.getUuid();
|
||||||
{ "id" }, "message_id = ?", new String[]
|
Context context = mApplication;
|
||||||
{ Long.toString(messageId) }, null, null, null);
|
|
||||||
|
// Get attachment IDs
|
||||||
|
String[] whereArgs = new String[] { Long.toString(messageId) };
|
||||||
|
attachmentsCursor = db.query("attachments", new String[] { "id" },
|
||||||
|
"message_id = ?", whereArgs, null, null, null);
|
||||||
|
|
||||||
final File attachmentDirectory = StorageManager.getInstance(mApplication)
|
final File attachmentDirectory = StorageManager.getInstance(mApplication)
|
||||||
.getAttachmentDirectory(uUid, database.getStorageProviderId());
|
.getAttachmentDirectory(uUid, database.getStorageProviderId());
|
||||||
|
|
||||||
while (attachmentsCursor.moveToNext()) {
|
while (attachmentsCursor.moveToNext()) {
|
||||||
long attachmentId = attachmentsCursor.getLong(0);
|
String attachmentId = Long.toString(attachmentsCursor.getLong(0));
|
||||||
try {
|
try {
|
||||||
File file = new File(attachmentDirectory, Long.toString(attachmentId));
|
// Delete stored attachment
|
||||||
|
File file = new File(attachmentDirectory, attachmentId);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
// Delete thumbnail file
|
||||||
|
AttachmentProvider.deleteThumbnail(context, accountUuid,
|
||||||
|
attachmentId);
|
||||||
|
} catch (Exception e) { /* ignore */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete attachment metadata from the database
|
||||||
|
db.delete("attachments", "message_id = ?", whereArgs);
|
||||||
} finally {
|
} finally {
|
||||||
Utility.closeQuietly(attachmentsCursor);
|
Utility.closeQuietly(attachmentsCursor);
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,30 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the thumbnail of an attachment.
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* The application context.
|
||||||
|
* @param accountUuid
|
||||||
|
* The UUID of the account the attachment belongs to.
|
||||||
|
* @param attachmentId
|
||||||
|
* The ID of the attachment the thumbnail was created for.
|
||||||
|
*/
|
||||||
|
public static void deleteThumbnail(Context context, String accountUuid, String attachmentId) {
|
||||||
|
File file = getThumbnailFile(context, accountUuid, attachmentId);
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File getThumbnailFile(Context context, String accountUuid,
|
||||||
|
String attachmentId) {
|
||||||
|
String filename = "thmb_" + accountUuid + "_" + attachmentId + ".tmp";
|
||||||
|
File dir = context.getCacheDir();
|
||||||
|
return new File(dir, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
@ -139,9 +163,7 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
int width = Integer.parseInt(segments.get(3));
|
int width = Integer.parseInt(segments.get(3));
|
||||||
int height = Integer.parseInt(segments.get(4));
|
int height = Integer.parseInt(segments.get(4));
|
||||||
|
|
||||||
String filename = "thmb_" + accountUuid + "_" + attachmentId + ".tmp";
|
file = getThumbnailFile(getContext(), accountUuid, attachmentId);
|
||||||
File dir = getContext().getCacheDir();
|
|
||||||
file = new File(dir, filename);
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
String type = getType(accountUuid, attachmentId, FORMAT_VIEW);
|
String type = getType(accountUuid, attachmentId, FORMAT_VIEW);
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user