mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
always clean up invalid files, not just at 20%
This commit is contained in:
parent
15485fa183
commit
4b49cdf34f
1 changed files with 11 additions and 15 deletions
|
@ -42,7 +42,6 @@ import java.util.HashSet
|
|||
import java.util.LinkedHashSet
|
||||
import kotlin.Comparator
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.random.Random
|
||||
|
||||
val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
val Context.audioManager get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
@ -565,23 +564,20 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
|
|||
val grouped = mediaFetcher.groupMedia(media, pathToUse)
|
||||
callback(grouped.clone() as ArrayList<ThumbnailItem>)
|
||||
|
||||
val value = Random.nextInt(5)
|
||||
if (value == 1) {
|
||||
val mediaToDelete = ArrayList<Medium>()
|
||||
media.filter { !File(it.path).exists() }.forEach {
|
||||
if (it.path.startsWith(recycleBinPath)) {
|
||||
deleteDBPath(mediumDao, it.path)
|
||||
} else {
|
||||
mediaToDelete.add(it)
|
||||
}
|
||||
val mediaToDelete = ArrayList<Medium>()
|
||||
media.filter { !File(it.path).exists() }.forEach {
|
||||
if (it.path.startsWith(recycleBinPath)) {
|
||||
deleteDBPath(mediumDao, it.path)
|
||||
} else {
|
||||
mediaToDelete.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (mediaToDelete.isNotEmpty()) {
|
||||
mediumDao.deleteMedia(*mediaToDelete.toTypedArray())
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
try {
|
||||
if (mediaToDelete.isNotEmpty()) {
|
||||
mediumDao.deleteMedia(*mediaToDelete.toTypedArray())
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue