pull/1923/head
kunfei 3 years ago
parent b98ff8261a
commit 38c6f28172
  1. 6
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
  2. 3
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt

@ -10,8 +10,8 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.localBook.EpubFile import io.legado.app.model.localBook.EpubFile
import io.legado.app.utils.BitmapUtils import io.legado.app.utils.BitmapUtils
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
@ -20,8 +20,6 @@ import kotlinx.coroutines.withContext
import splitties.init.appCtx import splitties.init.appCtx
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import kotlin.math.max
import kotlin.math.min
object ImageProvider { object ImageProvider {
@ -33,7 +31,7 @@ object ImageProvider {
*缓存bitmap LruCache实现 *缓存bitmap LruCache实现
*/ */
private const val M = 1024 * 1024 private const val M = 1024 * 1024
private val cacheSize = AppConfig.bitmapCacheSize * M val cacheSize get() = AppConfig.bitmapCacheSize * M
val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) { val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) {
override fun sizeOf(key: String, bitmap: Bitmap): Int { override fun sizeOf(key: String, bitmap: Bitmap): Int {

@ -21,6 +21,7 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.model.CheckSource import io.legado.app.model.CheckSource
import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.receiver.SharedReceiverActivity
import io.legado.app.service.WebService import io.legado.app.service.WebService
import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.utils.* import io.legado.app.utils.*
@ -106,7 +107,6 @@ class OtherConfigFragment : PreferenceFragment(),
PreferKey.uploadRule -> showDialogFragment<DirectLinkUploadConfig>() PreferKey.uploadRule -> showDialogFragment<DirectLinkUploadConfig>()
PreferKey.checkSource -> showDialogFragment<CheckSourceConfig>() PreferKey.checkSource -> showDialogFragment<CheckSourceConfig>()
PreferKey.bitmapCacheSize -> { PreferKey.bitmapCacheSize -> {
toastOnUi(R.string.restart_to_apply_changes)
NumberPickerDialog(requireContext()) NumberPickerDialog(requireContext())
.setTitle(getString(R.string.bitmap_cache_size)) .setTitle(getString(R.string.bitmap_cache_size))
.setMaxValue(9999) .setMaxValue(9999)
@ -114,6 +114,7 @@ class OtherConfigFragment : PreferenceFragment(),
.setValue(AppConfig.bitmapCacheSize) .setValue(AppConfig.bitmapCacheSize)
.show { .show {
AppConfig.bitmapCacheSize = it AppConfig.bitmapCacheSize = it
ImageProvider.bitmapLruCache.resize(ImageProvider.cacheSize)
} }
} }
} }

Loading…
Cancel
Save