mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 23:12:55 +00:00
Keep cached image files until message delete or deleted by Android
This commit is contained in:
parent
304909f926
commit
5fd22c34af
1 changed files with 5 additions and 3 deletions
|
@ -44,7 +44,6 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
|
|||
public class WorkerCleanup extends Worker {
|
||||
private static final int CLEANUP_INTERVAL = 4; // hours
|
||||
private static final long KEEP_FILES_DURATION = 3600 * 1000L; // milliseconds
|
||||
private static final long CACHE_IMAGE_DURATION = 3 * 24 * 3600 * 1000L; // milliseconds
|
||||
private static final long KEEP_CONTACTS_DURATION = 180 * 24 * 3600 * 1000L; // milliseconds
|
||||
private static final long KEEP_LOG_DURATION = 24 * 3600 * 1000L; // milliseconds
|
||||
|
||||
|
@ -163,12 +162,15 @@ public class WorkerCleanup extends Worker {
|
|||
File[] images = new File(context.getCacheDir(), "images").listFiles();
|
||||
if (images != null)
|
||||
for (File file : images)
|
||||
if (file.isFile())
|
||||
if (manual || now - file.lastModified() > CACHE_IMAGE_DURATION) {
|
||||
if (manual || file.lastModified() + KEEP_FILES_DURATION < now) {
|
||||
long id = Long.parseLong(file.getName().split("_")[0]);
|
||||
EntityMessage message = db.message().getMessage(id);
|
||||
if (message == null) {
|
||||
Log.i("Deleting " + file);
|
||||
if (!file.delete())
|
||||
Log.w("Error deleting " + file);
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("Cleanup contacts");
|
||||
int contacts = db.contact().deleteContacts(now - KEEP_CONTACTS_DURATION);
|
||||
|
|
Loading…
Reference in a new issue