Pages lru cache
This commit is contained in:
@@ -57,7 +57,7 @@ dependencies {
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.3.0-alpha01'
|
||||
implementation "androidx.fragment:fragment-ktx:1.2.0"
|
||||
implementation "androidx.fragment:fragment-ktx:1.2.1"
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0-alpha02'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03'
|
||||
@@ -77,11 +77,12 @@ dependencies {
|
||||
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.3.1'
|
||||
implementation 'com.squareup.okio:okio:2.4.3'
|
||||
implementation 'org.jsoup:jsoup:1.12.1'
|
||||
implementation 'org.jsoup:jsoup:1.12.2'
|
||||
|
||||
implementation 'org.koin:koin-android:2.0.1'
|
||||
implementation 'io.coil-kt:coil:0.9.4'
|
||||
implementation 'io.coil-kt:coil:0.9.5'
|
||||
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
|
||||
implementation 'com.tomclaw.cache:cache:1.0'
|
||||
|
||||
testImplementation 'junit:junit:4.13'
|
||||
testImplementation 'androidx.test:core:1.2.0'
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.koitharu.kotatsu.core.local
|
||||
|
||||
import android.content.Context
|
||||
import com.tomclaw.cache.DiskLruCache
|
||||
import org.koitharu.kotatsu.utils.FileSizeUtils
|
||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||
import org.koitharu.kotatsu.utils.ext.sub
|
||||
import org.koitharu.kotatsu.utils.ext.takeIfReadable
|
||||
@@ -9,19 +11,18 @@ import java.io.OutputStream
|
||||
|
||||
class PagesCache(context: Context) {
|
||||
|
||||
private val cacheDir = File(context.externalCacheDir ?: context.cacheDir, "pages")
|
||||
private val cacheDir = context.externalCacheDir ?: context.cacheDir
|
||||
private val lruCache = DiskLruCache.create(cacheDir.sub("pages"), FileSizeUtils.mbToBytes(200))
|
||||
|
||||
init {
|
||||
if (!cacheDir.exists()) {
|
||||
cacheDir.mkdir()
|
||||
}
|
||||
operator fun get(url: String): File? {
|
||||
return lruCache.get(url)?.takeIfReadable()
|
||||
}
|
||||
|
||||
operator fun get(url: String) = cacheDir.sub(url.longHashCode().toString()).takeIfReadable()
|
||||
|
||||
fun put(url: String, writer: (OutputStream) -> Unit): File {
|
||||
val file = cacheDir.sub(url.longHashCode().toString())
|
||||
file.outputStream().use(writer)
|
||||
return file
|
||||
val res = lruCache.put(url, file)
|
||||
file.delete()
|
||||
return res
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:text="?android:textColorSecondary"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
tools:text="@tools:sample/lorem[3]" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user