always clean up invalid files, not just at 20%

This commit is contained in:
tibbi 2019-02-22 10:25:38 +01:00
parent 15485fa183
commit 4b49cdf34f
1 changed files with 11 additions and 15 deletions

View File

@ -42,7 +42,6 @@ import java.util.HashSet
import java.util.LinkedHashSet import java.util.LinkedHashSet
import kotlin.Comparator import kotlin.Comparator
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.random.Random
val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
val Context.audioManager get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager 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) val grouped = mediaFetcher.groupMedia(media, pathToUse)
callback(grouped.clone() as ArrayList<ThumbnailItem>) callback(grouped.clone() as ArrayList<ThumbnailItem>)
val value = Random.nextInt(5) val mediaToDelete = ArrayList<Medium>()
if (value == 1) { media.filter { !File(it.path).exists() }.forEach {
val mediaToDelete = ArrayList<Medium>() if (it.path.startsWith(recycleBinPath)) {
media.filter { !File(it.path).exists() }.forEach { deleteDBPath(mediumDao, it.path)
if (it.path.startsWith(recycleBinPath)) { } else {
deleteDBPath(mediumDao, it.path) mediaToDelete.add(it)
} else {
mediaToDelete.add(it)
}
} }
}
try { try {
if (mediaToDelete.isNotEmpty()) { if (mediaToDelete.isNotEmpty()) {
mediumDao.deleteMedia(*mediaToDelete.toTypedArray()) mediumDao.deleteMedia(*mediaToDelete.toTypedArray())
}
} catch (ignored: Exception) {
} }
} catch (ignored: Exception) {
} }
}.start() }.start()
} }