diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index f52ce8c0c..2244823a9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.activities.SimpleActivity import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog import com.simplemobiletools.gallery.pro.helpers.NOMEDIA +import com.simplemobiletools.gallery.pro.helpers.RECYCLE_BIN import com.simplemobiletools.gallery.pro.interfaces.MediumDao import java.io.File import java.io.InputStream @@ -211,7 +212,7 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList, mediumDao val internalFile = File(recycleBinPath, it) try { if (file.copyRecursively(internalFile, true)) { - mediumDao.updateDeleted(it, System.currentTimeMillis()) + mediumDao.updateDeleted("$RECYCLE_BIN$it", System.currentTimeMillis(), it) pathsCnt-- } } catch (e: Exception) { @@ -240,7 +241,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList, mediumDa inputStream = getFileInputStreamSync(source)!! inputStream.copyTo(out!!) if (File(source).length() == File(destination).length()) { - mediumDao.updateDeleted(destination, 0) + mediumDao.updateDeleted(destination.removePrefix(recycleBinPath), 0, "$RECYCLE_BIN$destination") } } catch (e: Exception) { showErrorToast(e) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index dfb74bc2f..b4936f781 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -470,10 +470,11 @@ fun Context.getOTGFolderChildrenNames(path: String) = getOTGFolderChildren(path) fun Context.getFavoritePaths() = galleryDB.MediumDao().getFavoritePaths() as ArrayList +// remove the "recycle_bin" from the file path prefix, replace it with real bin path /data/user... fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList { val media = mediumDao.getDeletedMedia() as ArrayList media.forEach { - it.path = File(recycleBinPath, it.path).toString() + it.path = File(recycleBinPath, it.path.removePrefix(RECYCLE_BIN)).toString() } return media } 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 d0436d877..1ce2bb641 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 @@ -42,8 +42,8 @@ interface MediumDao { @Query("UPDATE media SET is_favorite = :isFavorite WHERE full_path = :path COLLATE NOCASE") fun updateFavorite(path: String, isFavorite: Boolean) - @Query("UPDATE media SET deleted_ts = :deletedTS WHERE full_path = :path COLLATE NOCASE") - fun updateDeleted(path: String, deletedTS: Long) + @Query("UPDATE OR REPLACE media SET full_path = :newPath, deleted_ts = :deletedTS WHERE full_path = :oldPath COLLATE NOCASE") + fun updateDeleted(newPath: String, deletedTS: Long, oldPath: String) @Query("UPDATE media SET date_taken = :dateTaken WHERE full_path = :path COLLATE NOCASE") fun updateFavoriteDateTaken(path: String, dateTaken: Long)