From c47190b30baf2c1d38701add8e16d3408a72e7bc Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 20 Feb 2022 19:47:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=98=85=E8=AF=BB=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../main/java/io/legado/app/help/AppConfig.kt | 6 ++++ .../main/java/io/legado/app/model/ReadBook.kt | 8 +++-- .../app/service/BaseReadAloudService.kt | 2 +- .../legado/app/ui/about/ReadRecordActivity.kt | 35 +++++++++++-------- app/src/main/res/menu/book_read_record.xml | 15 ++++++-- app/src/main/res/menu/book_source.xml | 2 +- app/src/main/res/values-es-rES/strings.xml | 4 ++- app/src/main/res/values-ja-rJP/strings.xml | 4 ++- app/src/main/res/values-pt-rBR/strings.xml | 4 ++- app/src/main/res/values-zh-rHK/strings.xml | 4 ++- app/src/main/res/values-zh-rTW/strings.xml | 4 ++- app/src/main/res/values-zh/strings.xml | 4 ++- app/src/main/res/values/strings.xml | 4 ++- 14 files changed, 68 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 93f9d9d18..21f0db261 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -94,6 +94,7 @@ object PreferKey { const val checkSource = "checkSource" const val uploadRule = "uploadRule" const val tocUiUseReplace = "tocUiUseReplace" + const val enableReadRecord = "enableReadRecord" const val cPrimary = "colorPrimary" const val cAccent = "colorAccent" diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 83a889fa6..0878ff572 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -256,6 +256,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { appCtx.putPrefBoolean(PreferKey.tocUiUseReplace, value) } + var enableReadRecord: Boolean + get() = appCtx.getPrefBoolean(PreferKey.enableReadRecord, true) + set(value) { + appCtx.putPrefBoolean(PreferKey.enableReadRecord, value) + } + val autoChangeSource: Boolean get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true) diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index e72366389..234437d1f 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -114,11 +114,13 @@ object ReadBook : CoroutineScope by MainScope() { } } - fun upReadStartTime() { + fun upReadTime() { Coroutine.async { readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime readStartTime = System.currentTimeMillis() - appDb.readRecordDao.insert(readRecord) + if (AppConfig.enableReadRecord) { + appDb.readRecordDao.insert(readRecord) + } } } @@ -205,7 +207,7 @@ object ReadBook : CoroutineScope by MainScope() { if (BaseReadAloudService.isRun) { readAloud(!BaseReadAloudService.pause) } - upReadStartTime() + upReadTime() preDownload() ImageProvider.clearOut(durChapterIndex) } diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 29dbefd83..119aabbe1 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -353,7 +353,7 @@ abstract class BaseReadAloudService : BaseService(), abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent? open fun nextChapter() { - ReadBook.upReadStartTime() + ReadBook.upReadTime() if (!ReadBook.moveToNextChapter(true)) { stopSelf() } diff --git a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt index b611b88f7..3fea0673c 100644 --- a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt @@ -13,6 +13,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.ReadRecordShow import io.legado.app.databinding.ActivityReadRecordBinding import io.legado.app.databinding.ItemReadRecordBinding +import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.search.SearchActivity @@ -20,7 +21,6 @@ import io.legado.app.utils.cnCompare import io.legado.app.utils.startActivity import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -41,6 +41,11 @@ class ReadRecordActivity : BaseActivity() { return super.onCompatCreateOptionsMenu(menu) } + override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { + menu.findItem(R.id.menu_enable_record)?.isChecked = AppConfig.enableReadRecord + return super.onMenuOpened(featureId, menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_sort_name -> { @@ -51,6 +56,9 @@ class ReadRecordActivity : BaseActivity() { sortMode = 1 initData() } + R.id.menu_enable_record -> { + AppConfig.enableReadRecord = !item.isChecked + } } return super.onCompatOptionsItemSelected(item) } @@ -70,23 +78,22 @@ class ReadRecordActivity : BaseActivity() { } private fun initData() { - launch(IO) { - val allTime = appDb.readRecordDao.allTime - withContext(Main) { - binding.readRecord.tvReadTime.text = formatDuring(allTime) + launch { + val allTime = withContext(IO) { + appDb.readRecordDao.allTime } - var readRecords = appDb.readRecordDao.allShow - readRecords = when (sortMode) { - 1 -> readRecords.sortedBy { it.readTime } - else -> { - readRecords.sortedWith { o1, o2 -> - o1.bookName.cnCompare(o2.bookName) + binding.readRecord.tvReadTime.text = formatDuring(allTime) + val readRecords = withContext(IO) { + appDb.readRecordDao.allShow.let { records -> + when (sortMode) { + 1 -> records.sortedBy { it.readTime } + else -> records.sortedWith { o1, o2 -> + o1.bookName.cnCompare(o2.bookName) + } } } } - withContext(Main) { - adapter.setItems(readRecords) - } + adapter.setItems(readRecords) } } diff --git a/app/src/main/res/menu/book_read_record.xml b/app/src/main/res/menu/book_read_record.xml index 6ba105d38..65c58abb3 100644 --- a/app/src/main/res/menu/book_read_record.xml +++ b/app/src/main/res/menu/book_read_record.xml @@ -1,12 +1,21 @@ - + + android:title="@string/sort_by_name" + app:showAsAction="never" /> + android:title="@string/sort_by_time" + app:showAsAction="never" /> + + \ No newline at end of file diff --git a/app/src/main/res/menu/book_source.xml b/app/src/main/res/menu/book_source.xml index dd43aec84..679c237e4 100644 --- a/app/src/main/res/menu/book_source.xml +++ b/app/src/main/res/menu/book_source.xml @@ -39,7 +39,7 @@ + android:title="@string/sort_by_name" /> Ordenar Ordenar automáticamente Ordenar manualmente - Ordenar por nombre + Ordenar por nombre Ir al principio Ir al final Leído: %s @@ -941,5 +941,7 @@ 编辑内容 单章换源 整书换源 + 时间排序 + 开启记录 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 63e284e46..8f30e828e 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -351,7 +351,7 @@ Sort Sort automatically Sort manually - Sort by name + Sort by name Scroll to the top Scroll to the bottom Read: %s @@ -944,5 +944,7 @@ 编辑内容 单章换源 整书换源 + 时间排序 + 开启记录 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 7ed33933c..790e20227 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -349,7 +349,7 @@ Ordenar Ordenar automaticamente Ordenar manualmente - Ordenar por nome + Ordenar por nome Vá ao topo Vá ao final Ler: %s @@ -944,5 +944,7 @@ 编辑内容 单章换源 整书换源 + 时间排序 + 开启记录 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 48bae19f7..29c9cf854 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -348,7 +348,7 @@ 排序 智能排序 手動排序 - 名稱排序 + 名稱排序 滾動到頂部 滾動到底部 已讀: %s @@ -941,5 +941,7 @@ 编辑内容 单章换源 整书换源 + 时间排序 + 开启记录 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 29cacaa4a..82d29637f 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -350,7 +350,7 @@ 排序 智慧排序 手動排序 - 名稱排序 + 名稱排序 滾動到頂部 滾動到底部 已讀: %s @@ -943,5 +943,7 @@ 编辑内容 单章换源 整书换源 + 时间排序 + 开启记录 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 3056ada0a..13012c32c 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -350,7 +350,7 @@ 排序 智能排序 手动排序 - 名称排序 + 名称排序 滚动到顶部 滚动到底部 已读: %s @@ -943,5 +943,7 @@ 编辑内容 单章换源 整书换源 + 时间排序 + 开启记录 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b6aa7626..7171000b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -351,7 +351,7 @@ Sort Sort automatically Sort manually - Sort by name + Sort by name Scroll to the top Scroll to the bottom Read: %s @@ -944,5 +944,7 @@ Edit Content 单章换源 整书换源 + 时间排序 + 开启记录