Skip to content

Commit

Permalink
缓存管理优化 (#4584)
Browse files Browse the repository at this point in the history
  • Loading branch information
niu-hb authored Jan 27, 2025
1 parent 5bdfa0c commit 63a6450
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.MenuItem
import android.view.View
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.PopupMenu
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.textfield.TextInputLayout
Expand Down Expand Up @@ -38,11 +39,13 @@ import io.legado.app.ui.file.HandleFileContract
import io.legado.app.utils.ACache
import io.legado.app.utils.FileDoc
import io.legado.app.utils.applyNavigationBarPadding
import io.legado.app.utils.applyOpenTint
import io.legado.app.utils.applyTint
import io.legado.app.utils.checkWrite
import io.legado.app.utils.cnCompare
import io.legado.app.utils.enableCustomExport
import io.legado.app.utils.flowWithLifecycleAndDatabaseChange
import io.legado.app.utils.iconItemOnLongClick
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.observeEvent
import io.legado.app.utils.parseToUri
Expand All @@ -65,6 +68,7 @@ import kotlin.math.max
* cache/download 缓存界面
*/
class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>(),
PopupMenu.OnMenuItemClickListener,
CacheAdapter.CallBack {

override val binding by viewBinding(ActivityCacheBookBinding::inflate)
Expand Down Expand Up @@ -120,6 +124,13 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()

override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.book_cache, menu)
menu.iconItemOnLongClick(R.id.menu_download) {
PopupMenu(this, it).apply {
inflate(R.menu.book_cache_download)
this.menu.applyOpenTint(this@CacheActivity)
setOnMenuItemClickListener(this@CacheActivity)
}.show()
}
return super.onCompatCreateOptionsMenu(menu)
}

Expand Down Expand Up @@ -158,7 +169,8 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
*/
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_download -> {
R.id.menu_download,
R.id.menu_download_after -> {
if (!CacheBook.isRun) {
adapter.getItems().forEach { book ->
CacheBook.start(
Expand All @@ -172,6 +184,20 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
CacheBook.stop(this@CacheActivity)
}
}
R.id.menu_download_all -> {
if (!CacheBook.isRun) {
adapter.getItems().forEach { book ->
CacheBook.start(
this@CacheActivity,
book,
0,
book.lastChapterIndex
)
}
} else {
CacheBook.stop(this@CacheActivity)
}
}

R.id.menu_export_all -> exportAll()
R.id.menu_enable_replace -> AppConfig.exportUseReplace = !item.isChecked
Expand All @@ -198,6 +224,10 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
return super.onCompatOptionsItemSelected(item)
}

override fun onMenuItemClick(item: MenuItem): Boolean {
return onCompatOptionsItemSelected(item)
}

private fun initRecyclerView() {
binding.recyclerView.layoutManager = layoutManager
binding.recyclerView.adapter = adapter
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/menu/book_cache_download.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/menu_download_after"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/menu_download_after"
app:showAsAction="never" />

<item
android:id="@+id/menu_download_all"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/menu_download_all"
app:showAsAction="never" />

</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1178,4 +1178,6 @@
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
<string name="show_same_source">显示重复书源</string>
<string name="theme_config">主题配置</string>
<string name="menu_download_after">Descargar el siguiente capítulo</string>
<string name="menu_download_all">Descargar todos los capítulos</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1181,4 +1181,6 @@
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
<string name="show_same_source">显示重复书源</string>
<string name="theme_config">主题配置</string>
<string name="menu_download_after">下载之后章节</string>
<string name="menu_download_all">下载全部章节</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1181,4 +1181,6 @@
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
<string name="show_same_source">显示重复书源</string>
<string name="theme_config">主题配置</string>
<string name="menu_download_after">Faça o download do próximo capítulo</string>
<string name="menu_download_all">Download de todos os capítulos</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1177,4 +1177,6 @@ Còn </string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
<string name="show_same_source">显示重复书源</string>
<string name="theme_config">主题配置</string>
<string name="menu_download_after">Tải xuống chương tiếp theo</string>
<string name="menu_download_all">Tải xuống tất cả các chương</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1178,4 +1178,6 @@
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
<string name="show_same_source">显示重复书源</string>
<string name="theme_config">主题配置</string>
<string name="menu_download_after">下載之後章節</string>
<string name="menu_download_all">下載全部章節</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1180,4 +1180,6 @@
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
<string name="show_same_source">显示重复书源</string>
<string name="theme_config">主题配置</string>
<string name="menu_download_after">下載之後章節</string>
<string name="menu_download_all">下載全部章節</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1180,4 +1180,6 @@
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
<string name="show_same_source">显示重复书源</string>
<string name="theme_config">主题配置</string>
<string name="menu_download_after">下载之后章节</string>
<string name="menu_download_all">下载全部章节</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1181,4 +1181,6 @@
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
<string name="show_same_source">显示重复书源</string>
<string name="theme_config">主题配置</string>
<string name="menu_download_after">Download the chapter after</string>
<string name="menu_download_all">Download all chapter</string>
</resources>

0 comments on commit 63a6450

Please sign in to comment.