fix some glitches with files not properly appearing in recycle bin
This commit is contained in:
parent
225337a1d3
commit
6098c24227
3 changed files with 7 additions and 5 deletions
|
@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.activities.SimpleActivity
|
import com.simplemobiletools.gallery.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog
|
import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog
|
||||||
import com.simplemobiletools.gallery.pro.helpers.NOMEDIA
|
import com.simplemobiletools.gallery.pro.helpers.NOMEDIA
|
||||||
|
import com.simplemobiletools.gallery.pro.helpers.RECYCLE_BIN
|
||||||
import com.simplemobiletools.gallery.pro.interfaces.MediumDao
|
import com.simplemobiletools.gallery.pro.interfaces.MediumDao
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
@ -211,7 +212,7 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, mediumDao
|
||||||
val internalFile = File(recycleBinPath, it)
|
val internalFile = File(recycleBinPath, it)
|
||||||
try {
|
try {
|
||||||
if (file.copyRecursively(internalFile, true)) {
|
if (file.copyRecursively(internalFile, true)) {
|
||||||
mediumDao.updateDeleted(it, System.currentTimeMillis())
|
mediumDao.updateDeleted("$RECYCLE_BIN$it", System.currentTimeMillis(), it)
|
||||||
pathsCnt--
|
pathsCnt--
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -240,7 +241,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDa
|
||||||
inputStream = getFileInputStreamSync(source)!!
|
inputStream = getFileInputStreamSync(source)!!
|
||||||
inputStream.copyTo(out!!)
|
inputStream.copyTo(out!!)
|
||||||
if (File(source).length() == File(destination).length()) {
|
if (File(source).length() == File(destination).length()) {
|
||||||
mediumDao.updateDeleted(destination, 0)
|
mediumDao.updateDeleted(destination.removePrefix(recycleBinPath), 0, "$RECYCLE_BIN$destination")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
|
|
|
@ -470,10 +470,11 @@ fun Context.getOTGFolderChildrenNames(path: String) = getOTGFolderChildren(path)
|
||||||
|
|
||||||
fun Context.getFavoritePaths() = galleryDB.MediumDao().getFavoritePaths() as ArrayList<String>
|
fun Context.getFavoritePaths() = galleryDB.MediumDao().getFavoritePaths() as ArrayList<String>
|
||||||
|
|
||||||
|
// remove the "recycle_bin" from the file path prefix, replace it with real bin path /data/user...
|
||||||
fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList<Medium> {
|
fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList<Medium> {
|
||||||
val media = mediumDao.getDeletedMedia() as ArrayList<Medium>
|
val media = mediumDao.getDeletedMedia() as ArrayList<Medium>
|
||||||
media.forEach {
|
media.forEach {
|
||||||
it.path = File(recycleBinPath, it.path).toString()
|
it.path = File(recycleBinPath, it.path.removePrefix(RECYCLE_BIN)).toString()
|
||||||
}
|
}
|
||||||
return media
|
return media
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,8 @@ interface MediumDao {
|
||||||
@Query("UPDATE media SET is_favorite = :isFavorite WHERE full_path = :path COLLATE NOCASE")
|
@Query("UPDATE media SET is_favorite = :isFavorite WHERE full_path = :path COLLATE NOCASE")
|
||||||
fun updateFavorite(path: String, isFavorite: Boolean)
|
fun updateFavorite(path: String, isFavorite: Boolean)
|
||||||
|
|
||||||
@Query("UPDATE media SET deleted_ts = :deletedTS WHERE full_path = :path COLLATE NOCASE")
|
@Query("UPDATE OR REPLACE media SET full_path = :newPath, deleted_ts = :deletedTS WHERE full_path = :oldPath COLLATE NOCASE")
|
||||||
fun updateDeleted(path: String, deletedTS: Long)
|
fun updateDeleted(newPath: String, deletedTS: Long, oldPath: String)
|
||||||
|
|
||||||
@Query("UPDATE media SET date_taken = :dateTaken WHERE full_path = :path COLLATE NOCASE")
|
@Query("UPDATE media SET date_taken = :dateTaken WHERE full_path = :path COLLATE NOCASE")
|
||||||
fun updateFavoriteDateTaken(path: String, dateTaken: Long)
|
fun updateFavoriteDateTaken(path: String, dateTaken: Long)
|
||||||
|
|
Loading…
Reference in a new issue