Auto cache clean

This commit is contained in:
tom5079
2020-10-02 12:51:59 +09:00
parent 87fdbdbb6e
commit 2b67858453
13 changed files with 127 additions and 52 deletions

View File

@@ -61,9 +61,18 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt
var thin: Boolean = Preferences["thin"]
inner class GalleryViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
var update = true
private var galleryID: Int = 0
private fun updateProgress(context: Context, galleryID: Int) {
init {
CoroutineScope(Dispatchers.Main).launch {
while (updateAll) {
updateProgress(view.context)
delay(1000)
}
}
}
private fun updateProgress(context: Context) {
val cache = Cache.getInstance(context, galleryID)
CoroutineScope(Dispatchers.Main).launch {
@@ -116,9 +125,13 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt
}
fun bind(galleryID: Int) {
this.galleryID = galleryID
val cache = Cache.getInstance(view.context, galleryID)
val galleryBlock = cache.metadata.galleryBlock ?: return
val galleryBlock = runBlocking {
cache.getGalleryBlock()
} ?: return
with(view) {
val resources = context.resources
@@ -162,13 +175,6 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt
}
}
CoroutineScope(Dispatchers.Main).launch {
while (updateAll && update) {
updateProgress(context, galleryID)
delay(1000)
}
}
galleryblock_title.text = galleryBlock.title
with(galleryblock_artist) {
text = artists.joinToString { it.wordCapitalize() }
@@ -377,13 +383,6 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt
}
}
override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) {
super.onViewDetachedFromWindow(holder)
if (holder is GalleryViewHolder)
holder.update = false
}
override fun getItemCount() =
galleries.size +
(if (showNext) 1 else 0) +

View File

@@ -62,7 +62,14 @@ class ReaderAdapter(
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
fun clear() {
view.image.ssiv?.recycle()
view.image.mainView.let {
when (it) {
is SubsamplingScaleImageView ->
it.recycle()
is SimpleDraweeView ->
it.controller = null
}
}
}
}