mirror of
https://github.com/SimpleMobileTools/Simple-Gallery.git
synced 2025-06-05 21:59:19 +02:00
do recycle bin checks less often and more optimized
This commit is contained in:
@@ -89,6 +89,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||||||
config.temporarilyShowHidden = false
|
config.temporarilyShowHidden = false
|
||||||
config.tempSkipDeleteConfirmation = false
|
config.tempSkipDeleteConfirmation = false
|
||||||
removeTempFolder()
|
removeTempFolder()
|
||||||
|
checkRecycleBinItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsPickImageIntent = isPickImageIntent(intent)
|
mIsPickImageIntent = isPickImageIntent(intent)
|
||||||
@@ -139,8 +140,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||||||
config.filterMedia += TYPE_SVGS
|
config.filterMedia += TYPE_SVGS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRecycleBinItems()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
@@ -982,16 +981,15 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||||||
}, LAST_MEDIA_CHECK_PERIOD)
|
}, LAST_MEDIA_CHECK_PERIOD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun checkRecycleBinItems() {
|
private fun checkRecycleBinItems() {
|
||||||
if (config.useRecycleBin) {
|
if (config.useRecycleBin && config.lastBinCheck < System.currentTimeMillis() - DAY_SECONDS * 1000) {
|
||||||
Thread {
|
config.lastBinCheck = System.currentTimeMillis()
|
||||||
val deletedMedia = mMediumDao.getDeletedMedia()
|
Handler().postDelayed({
|
||||||
deletedMedia.forEach {
|
Thread {
|
||||||
if (System.currentTimeMillis() > it.deletedTS + MONTH_MILLISECONDS) {
|
mMediumDao.deleteOldRecycleBinItems(System.currentTimeMillis() - MONTH_MILLISECONDS)
|
||||||
mMediumDao.deleteMediumPath(it.path)
|
}.start()
|
||||||
}
|
}, 3000L)
|
||||||
}
|
|
||||||
}.start()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -384,4 +384,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var allowZoomingImages: Boolean
|
var allowZoomingImages: Boolean
|
||||||
get() = prefs.getBoolean(ALLOW_ZOOMING_IMAGES, true)
|
get() = prefs.getBoolean(ALLOW_ZOOMING_IMAGES, true)
|
||||||
set(allowZoomingImages) = prefs.edit().putBoolean(ALLOW_ZOOMING_IMAGES, allowZoomingImages).apply()
|
set(allowZoomingImages) = prefs.edit().putBoolean(ALLOW_ZOOMING_IMAGES, allowZoomingImages).apply()
|
||||||
|
|
||||||
|
var lastBinCheck: Long
|
||||||
|
get() = prefs.getLong(LAST_BIN_CHECK, 0L)
|
||||||
|
set(lastBinCheck) = prefs.edit().putLong(LAST_BIN_CHECK, lastBinCheck).apply()
|
||||||
}
|
}
|
||||||
|
@@ -60,6 +60,7 @@ const val EVER_SHOWN_FOLDERS = "ever_shown_folders"
|
|||||||
const val SHOW_RECYCLE_BIN_AT_FOLDERS = "show_recycle_bin_at_folders"
|
const val SHOW_RECYCLE_BIN_AT_FOLDERS = "show_recycle_bin_at_folders"
|
||||||
const val ALLOW_ZOOMING_IMAGES = "allow_zooming_images"
|
const val ALLOW_ZOOMING_IMAGES = "allow_zooming_images"
|
||||||
const val WAS_SVG_SHOWING_HANDLED = "was_svg_showing_handled"
|
const val WAS_SVG_SHOWING_HANDLED = "was_svg_showing_handled"
|
||||||
|
const val LAST_BIN_CHECK = "last_bin_check"
|
||||||
|
|
||||||
// slideshow
|
// slideshow
|
||||||
const val SLIDESHOW_INTERVAL = "slideshow_interval"
|
const val SLIDESHOW_INTERVAL = "slideshow_interval"
|
||||||
|
@@ -33,6 +33,9 @@ interface MediumDao {
|
|||||||
@Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE")
|
@Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE")
|
||||||
fun deleteMediumPath(path: String)
|
fun deleteMediumPath(path: String)
|
||||||
|
|
||||||
|
@Query("DELETE FROM media WHERE deleted_ts < :timestmap")
|
||||||
|
fun deleteOldRecycleBinItems(timestmap: Long)
|
||||||
|
|
||||||
@Query("UPDATE OR REPLACE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath COLLATE NOCASE")
|
@Query("UPDATE OR REPLACE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath COLLATE NOCASE")
|
||||||
fun updateMedium(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String)
|
fun updateMedium(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user