Merge pull request #1921 from Xwite/master

图片bitmap缓存设置
pull/1923/head
kunfei 2 years ago committed by GitHub
commit b98ff8261a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/build.gradle
  2. 5
      app/src/main/assets/updateLog.md
  3. 4
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  4. 11
      app/src/main/java/io/legado/app/help/config/AppConfig.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  6. 21
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  7. 4
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
  8. 16
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  9. 7
      app/src/main/res/menu/book_cache.xml
  10. 5
      app/src/main/res/values-es-rES/strings.xml
  11. 6
      app/src/main/res/values-ja-rJP/strings.xml
  12. 5
      app/src/main/res/values-pt-rBR/strings.xml
  13. 5
      app/src/main/res/values-zh-rHK/strings.xml
  14. 5
      app/src/main/res/values-zh-rTW/strings.xml
  15. 5
      app/src/main/res/values-zh/strings.xml
  16. 6
      app/src/main/res/values/strings.xml
  17. 6
      app/src/main/res/xml/pref_config_other.xml

@ -253,7 +253,7 @@ dependencies {
implementation('com.github.liuyueyi.quick-chinese-transfer:quick-transfer-core:0.2.4')
//,使
implementation('cn.hutool:hutool-crypto:5.8.1')
implementation('cn.hutool:hutool-crypto:5.8.2')
//firebase, ,
//implementation platform('com.google.firebase:firebase-bom:30.0.1')

@ -11,6 +11,11 @@
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2022/05/30**
* 缓存导出添加导出图片文件选项
* 其他设置添加图片绘制缓存选项
**2022/05/27**
* 书源详情页规则添加刷新时重新获取目录页链接Url的配置,true or false

@ -55,6 +55,7 @@ object PreferKey {
const val exportToWebDav = "webDavCacheBackup"
const val exportNoChapterName = "exportNoChapterName"
const val exportType = "exportType"
const val exportPictureFile = "exportPictureFile"
const val changeSourceCheckAuthor = "changeSourceCheckAuthor"
const val changeSourceLoadToc = "changeSourceLoadToc"
const val changeSourceLoadInfo = "changeSourceLoadInfo"
@ -82,6 +83,7 @@ object PreferKey {
const val syncBookProgress = "syncBookProgress"
const val cronet = "Cronet"
const val antiAlias = "antiAlias"
const val bitmapCacheSize = "bitmapCacheSize"
const val preDownloadNum = "preDownloadNum"
const val autoRefresh = "auto_refresh"
const val defaultToRead = "defaultToRead"
@ -107,7 +109,6 @@ object PreferKey {
const val welcomeShowIcon = "welcomeShowIcon"
const val welcomeShowIconDark = "welcomeShowIconDark"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"
const val cBackground = "colorBackground"
@ -121,4 +122,5 @@ object PreferKey {
const val cNBBackground = "colorBottomBackgroundNight"
const val bgImageN = "backgroundImageNight"
const val bgImageNBlurring = "backgroundImageNightBlurring"
}

@ -243,6 +243,11 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
set(value) {
appCtx.putPrefInt(PreferKey.exportType, value)
}
var exportPictureFile: Boolean
get() = appCtx.getPrefBoolean(PreferKey.exportPictureFile, false)
set(value) {
appCtx.putPrefBoolean(PreferKey.exportPictureFile, value)
}
var changeSourceCheckAuthor: Boolean
get() = appCtx.getPrefBoolean(PreferKey.changeSourceCheckAuthor)
@ -323,5 +328,11 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
}
return ua
}
var bitmapCacheSize: Int
get() = appCtx.getPrefInt(PreferKey.bitmapCacheSize, 50)
set(value) {
appCtx.putPrefInt(PreferKey.bitmapCacheSize, value)
}
}

@ -93,6 +93,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
menu.findItem(R.id.menu_enable_replace)?.isChecked = AppConfig.exportUseReplace
menu.findItem(R.id.menu_export_no_chapter_name)?.isChecked = AppConfig.exportNoChapterName
menu.findItem(R.id.menu_export_web_dav)?.isChecked = AppConfig.exportToWebDav
menu.findItem(R.id.menu_export_pics_file)?.isChecked = AppConfig.exportPictureFile
menu.findItem(R.id.menu_export_type)?.title =
"${getString(R.string.export_type)}(${getTypeName()})"
menu.findItem(R.id.menu_export_charset)?.title =
@ -129,6 +130,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
R.id.menu_enable_replace -> AppConfig.exportUseReplace = !item.isChecked
R.id.menu_export_no_chapter_name -> AppConfig.exportNoChapterName = !item.isChecked
R.id.menu_export_web_dav -> AppConfig.exportToWebDav = !item.isChecked
R.id.menu_export_pics_file -> AppConfig.exportPictureFile = !item.isChecked
R.id.menu_export_folder -> {
selectExportFolder(-1)
}

@ -168,17 +168,22 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
chineseConvert = false,
reSegment = false
).joinToString("\n")
val srcList = arrayListOf<Triple<String, Int, String>>()
content?.split("\n")?.forEachIndexed { index, text ->
val matcher = AppPattern.imgPattern.matcher(text)
while (matcher.find()) {
matcher.group(1)?.let {
val src = NetworkUtils.getAbsoluteURL(chapter.url, it)
srcList.add(Triple(chapter.title, index, src))
if (AppConfig.exportPictureFile) {
//txt导出图片文件
val srcList = arrayListOf<Triple<String, Int, String>>()
content?.split("\n")?.forEachIndexed { index, text ->
val matcher = AppPattern.imgPattern.matcher(text)
while (matcher.find()) {
matcher.group(1)?.let {
val src = NetworkUtils.getAbsoluteURL(chapter.url, it)
srcList.add(Triple(chapter.title, index, src))
}
}
}
append.invoke("\n\n$content1", srcList)
} else {
append.invoke("\n\n$content1", null)
}
append.invoke("\n\n$content1", srcList)
}
}
}

@ -11,6 +11,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.BookHelp
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.config.AppConfig
import io.legado.app.model.localBook.EpubFile
import io.legado.app.utils.BitmapUtils
import io.legado.app.utils.FileUtils
@ -32,8 +33,7 @@ object ImageProvider {
*缓存bitmap LruCache实现
*/
private const val M = 1024 * 1024
private val cacheSize =
max(50 * M, min(100 * M, (Runtime.getRuntime().maxMemory() / 8).toInt()))
private val cacheSize = AppConfig.bitmapCacheSize * M
val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) {
override fun sizeOf(key: String, bitmap: Bitmap): Int {

@ -56,6 +56,7 @@ class OtherConfigFragment : PreferenceFragment(),
upPreferenceSummary(PreferKey.defaultBookTreeUri, it)
}
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
upPreferenceSummary(PreferKey.bitmapCacheSize, AppConfig.bitmapCacheSize.toString())
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -104,6 +105,17 @@ class OtherConfigFragment : PreferenceFragment(),
PreferKey.cleanCache -> clearCache()
PreferKey.uploadRule -> showDialogFragment<DirectLinkUploadConfig>()
PreferKey.checkSource -> showDialogFragment<CheckSourceConfig>()
PreferKey.bitmapCacheSize -> {
toastOnUi(R.string.restart_to_apply_changes)
NumberPickerDialog(requireContext())
.setTitle(getString(R.string.bitmap_cache_size))
.setMaxValue(9999)
.setMinValue(1)
.setValue(AppConfig.bitmapCacheSize)
.show {
AppConfig.bitmapCacheSize = it
}
}
}
return super.onPreferenceTreeClick(preference)
}
@ -141,6 +153,9 @@ class OtherConfigFragment : PreferenceFragment(),
PreferKey.checkSource -> listView.post {
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
}
PreferKey.bitmapCacheSize -> {
upPreferenceSummary(key, AppConfig.bitmapCacheSize.toString())
}
}
}
@ -151,6 +166,7 @@ class OtherConfigFragment : PreferenceFragment(),
getString(R.string.pre_download_s, value)
PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value)
PreferKey.webPort -> preference.summary = getString(R.string.web_port_summary, value)
PreferKey.bitmapCacheSize -> preference.summary = getString(R.string.bitmap_cache_size_summary, value)
else -> if (preference is ListPreference) {
val index = preference.findIndexOfValue(value)
// Set the summary to reflect the new value.

@ -36,12 +36,19 @@
android:title="@string/export_to_web_dav"
android:checkable="true"
app:showAsAction="never" />
<item
android:id="@+id/menu_export_no_chapter_name"
android:title="@string/export_no_chapter_name"
android:checkable="true"
app:showAsAction="never" />
<item
android:id="@+id/menu_export_pics_file"
android:title="@string/export_pics_file"
android:checkable="true"
app:showAsAction="never" />
<item
android:id="@+id/menu_export_folder"
android:title="@string/export_folder"

@ -989,5 +989,10 @@
<string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</string>
<string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
<string name="bitmap_cache_size">bitmap cache size</string>
<string name="restart_to_apply_changes">Restart to apply changes</string>
<string name="export_pics_file">Export Picture Files</string>
<!-- string end -->
</resources>

@ -992,5 +992,11 @@
<string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</string>
<string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
<string name="bitmap_cache_size">bitmap cache size</string>
<string name="restart_to_apply_changes">Restart to apply changes</string>
<string name="export_pics_file">Export Picture Files</string>
<!-- string end -->
</resources>

@ -992,5 +992,10 @@
<string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</string>
<string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
<string name="bitmap_cache_size">bitmap cache size</string>
<string name="restart_to_apply_changes">Restart to apply changes</string>
<string name="export_pics_file">Export Picture Files</string>
<!-- string end -->
</resources>

@ -989,5 +989,10 @@
<string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDav书籍</string>
<string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
<string name="bitmap_cache_size">图片绘制缓存</string>
<string name="restart_to_apply_changes">重启应用更改</string>
<string name="export_pics_file">TXT导出图片</string>
<!-- string end -->
</resources>

@ -991,5 +991,10 @@
<string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDav书籍</string>
<string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
<string name="bitmap_cache_size">图片绘制缓存</string>
<string name="restart_to_apply_changes">重启应用更改</string>
<string name="export_pics_file">TXT导出图片</string>
<!-- string end -->
</resources>

@ -991,5 +991,10 @@
<string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">上传WebDav</string>
<string name="add_remote_book">WebDav书籍</string>
<string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
<string name="bitmap_cache_size">图片绘制缓存</string>
<string name="restart_to_apply_changes">重启应用更改</string>
<string name="export_pics_file">TXT导出图片</string>
<!-- string end -->
</resources>

@ -992,5 +992,11 @@
<string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</string>
<string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
<string name="bitmap_cache_size">bitmap cache size</string>
<string name="restart_to_apply_changes">Restart to apply changes</string>
<string name="export_pics_file">Export Picture Files</string>
<!-- string end -->
</resources>

@ -75,12 +75,18 @@
android:key="Cronet"
android:summary="@string/pref_cronet_summary"
android:title="Cronet" />
<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false"
android:key="antiAlias"
android:summary="@string/pref_anti_alias_summary"
android:title="@string/anti_alias" />
<io.legado.app.lib.prefs.Preference
android:key="bitmapCacheSize"
android:summary="@string/bitmap_cache_size_summary"
android:title="@string/bitmap_cache_size" />
<io.legado.app.lib.prefs.Preference
android:key="preDownloadNum"
android:summary="@string/pre_download_s"

Loading…
Cancel
Save