do recycle bin checks less often and more optimized
This commit is contained in:
parent
730ca8b5c0
commit
46f4c41890
4 changed files with 17 additions and 11 deletions
|
@ -89,6 +89,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
config.temporarilyShowHidden = false
|
||||
config.tempSkipDeleteConfirmation = false
|
||||
removeTempFolder()
|
||||
checkRecycleBinItems()
|
||||
}
|
||||
|
||||
mIsPickImageIntent = isPickImageIntent(intent)
|
||||
|
@ -139,8 +140,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
config.filterMedia += TYPE_SVGS
|
||||
}
|
||||
}
|
||||
|
||||
checkRecycleBinItems()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
@ -982,16 +981,15 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
}, LAST_MEDIA_CHECK_PERIOD)
|
||||
}
|
||||
|
||||
|
||||
private fun checkRecycleBinItems() {
|
||||
if (config.useRecycleBin) {
|
||||
Thread {
|
||||
val deletedMedia = mMediumDao.getDeletedMedia()
|
||||
deletedMedia.forEach {
|
||||
if (System.currentTimeMillis() > it.deletedTS + MONTH_MILLISECONDS) {
|
||||
mMediumDao.deleteMediumPath(it.path)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
if (config.useRecycleBin && config.lastBinCheck < System.currentTimeMillis() - DAY_SECONDS * 1000) {
|
||||
config.lastBinCheck = System.currentTimeMillis()
|
||||
Handler().postDelayed({
|
||||
Thread {
|
||||
mMediumDao.deleteOldRecycleBinItems(System.currentTimeMillis() - MONTH_MILLISECONDS)
|
||||
}.start()
|
||||
}, 3000L)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -384,4 +384,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
var allowZoomingImages: Boolean
|
||||
get() = prefs.getBoolean(ALLOW_ZOOMING_IMAGES, true)
|
||||
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 ALLOW_ZOOMING_IMAGES = "allow_zooming_images"
|
||||
const val WAS_SVG_SHOWING_HANDLED = "was_svg_showing_handled"
|
||||
const val LAST_BIN_CHECK = "last_bin_check"
|
||||
|
||||
// slideshow
|
||||
const val SLIDESHOW_INTERVAL = "slideshow_interval"
|
||||
|
|
|
@ -33,6 +33,9 @@ interface MediumDao {
|
|||
@Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE")
|
||||
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")
|
||||
fun updateMedium(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String)
|
||||
|
||||
|
|
Loading…
Reference in a new issue