From 5e548e0460d229eaaeec03795986acd9fd7a3aaf Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 13 Feb 2022 12:08:34 +0100 Subject: [PATCH] fix #2336, really delete files from the device after 30 days in the bin --- .../gallery/pro/activities/MainActivity.kt | 7 ++++++- .../simplemobiletools/gallery/pro/interfaces/MediumDao.kt | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index a62c08c0b..8acd0d969 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -1324,7 +1324,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { Handler().postDelayed({ ensureBackgroundThread { try { - mediaDB.deleteOldRecycleBinItems(System.currentTimeMillis() - MONTH_MILLISECONDS) + val filesToDelete = mediaDB.getOldRecycleBinItems(System.currentTimeMillis() - MONTH_MILLISECONDS) + filesToDelete.forEach { + if (File(it.path.replaceFirst(RECYCLE_BIN, recycleBinPath)).delete()) { + mediaDB.deleteMediumPath(it.path) + } + } } catch (e: Exception) { } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediumDao.kt index 6a2d5161d..bbc3d3535 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediumDao.kt @@ -24,6 +24,9 @@ interface MediumDao { @Query("SELECT COUNT(filename) FROM media WHERE deleted_ts != 0") fun getDeletedMediaCount(): Long + @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts, media_store_id FROM media WHERE deleted_ts < :timestmap AND deleted_ts != 0") + fun getOldRecycleBinItems(timestmap: Long): List + @Insert(onConflict = REPLACE) fun insert(medium: Medium) @@ -36,9 +39,6 @@ interface MediumDao { @Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE") fun deleteMediumPath(path: String) - @Query("DELETE FROM media WHERE deleted_ts < :timestmap AND deleted_ts != 0") - fun deleteOldRecycleBinItems(timestmap: Long) - @Query("UPDATE OR REPLACE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath COLLATE NOCASE") fun updateMedium(newFilename: String, newFullPath: String, newParentPath: String, oldPath: String)