Procházet zdrojové kódy

添加阅读记录开关

kunfei před 4 roky
rodič
revize
2f2f1e0ca5

+ 1 - 0
app/src/main/java/io/legado/app/constant/PreferKey.kt

@@ -94,6 +94,7 @@ object PreferKey {
     const val checkSource = "checkSource"
     const val checkSource = "checkSource"
     const val uploadRule = "uploadRule"
     const val uploadRule = "uploadRule"
     const val tocUiUseReplace = "tocUiUseReplace"
     const val tocUiUseReplace = "tocUiUseReplace"
+    const val enableReadRecord = "enableReadRecord"
 
 
     const val cPrimary = "colorPrimary"
     const val cPrimary = "colorPrimary"
     const val cAccent = "colorAccent"
     const val cAccent = "colorAccent"

+ 6 - 0
app/src/main/java/io/legado/app/help/AppConfig.kt

@@ -256,6 +256,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
             appCtx.putPrefBoolean(PreferKey.tocUiUseReplace, value)
             appCtx.putPrefBoolean(PreferKey.tocUiUseReplace, value)
         }
         }
 
 
+    var enableReadRecord: Boolean
+        get() = appCtx.getPrefBoolean(PreferKey.enableReadRecord, true)
+        set(value) {
+            appCtx.putPrefBoolean(PreferKey.enableReadRecord, value)
+        }
+
     val autoChangeSource: Boolean
     val autoChangeSource: Boolean
         get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true)
         get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true)
 
 

+ 5 - 3
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 {
         Coroutine.async {
             readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime
             readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime
             readStartTime = System.currentTimeMillis()
             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) {
         if (BaseReadAloudService.isRun) {
             readAloud(!BaseReadAloudService.pause)
             readAloud(!BaseReadAloudService.pause)
         }
         }
-        upReadStartTime()
+        upReadTime()
         preDownload()
         preDownload()
         ImageProvider.clearOut(durChapterIndex)
         ImageProvider.clearOut(durChapterIndex)
     }
     }

+ 1 - 1
app/src/main/java/io/legado/app/service/BaseReadAloudService.kt

@@ -353,7 +353,7 @@ abstract class BaseReadAloudService : BaseService(),
     abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent?
     abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent?
 
 
     open fun nextChapter() {
     open fun nextChapter() {
-        ReadBook.upReadStartTime()
+        ReadBook.upReadTime()
         if (!ReadBook.moveToNextChapter(true)) {
         if (!ReadBook.moveToNextChapter(true)) {
             stopSelf()
             stopSelf()
         }
         }

+ 21 - 14
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.data.entities.ReadRecordShow
 import io.legado.app.databinding.ActivityReadRecordBinding
 import io.legado.app.databinding.ActivityReadRecordBinding
 import io.legado.app.databinding.ItemReadRecordBinding
 import io.legado.app.databinding.ItemReadRecordBinding
+import io.legado.app.help.AppConfig
 import io.legado.app.lib.dialogs.alert
 import io.legado.app.lib.dialogs.alert
 import io.legado.app.ui.book.read.ReadBookActivity
 import io.legado.app.ui.book.read.ReadBookActivity
 import io.legado.app.ui.book.search.SearchActivity
 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.startActivity
 import io.legado.app.utils.viewbindingdelegate.viewBinding
 import io.legado.app.utils.viewbindingdelegate.viewBinding
 import kotlinx.coroutines.Dispatchers.IO
 import kotlinx.coroutines.Dispatchers.IO
-import kotlinx.coroutines.Dispatchers.Main
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
 import kotlinx.coroutines.withContext
 
 
@@ -41,6 +41,11 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
         return super.onCompatCreateOptionsMenu(menu)
         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 {
     override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
         when (item.itemId) {
         when (item.itemId) {
             R.id.menu_sort_name -> {
             R.id.menu_sort_name -> {
@@ -51,6 +56,9 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
                 sortMode = 1
                 sortMode = 1
                 initData()
                 initData()
             }
             }
+            R.id.menu_enable_record -> {
+                AppConfig.enableReadRecord = !item.isChecked
+            }
         }
         }
         return super.onCompatOptionsItemSelected(item)
         return super.onCompatOptionsItemSelected(item)
     }
     }
@@ -70,23 +78,22 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
     }
     }
 
 
     private fun initData() {
     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)
         }
         }
     }
     }
 
 

+ 12 - 3
app/src/main/res/menu/book_read_record.xml

@@ -1,12 +1,21 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
 
 
     <item
     <item
         android:id="@+id/menu_sort_name"
         android:id="@+id/menu_sort_name"
-        android:title="按书名排序" />
+        android:title="@string/sort_by_name"
+        app:showAsAction="never" />
 
 
     <item
     <item
         android:id="@+id/menu_sort_time"
         android:id="@+id/menu_sort_time"
-        android:title="按时间排序" />
+        android:title="@string/sort_by_time"
+        app:showAsAction="never" />
+
+    <item
+        android:id="@+id/menu_enable_record"
+        android:title="@string/enable_record"
+        android:checkable="true"
+        app:showAsAction="never" />
 
 
 </menu>
 </menu>

+ 1 - 1
app/src/main/res/menu/book_source.xml

@@ -39,7 +39,7 @@
                         <item
                         <item
                             android:id="@+id/menu_sort_name"
                             android:id="@+id/menu_sort_name"
                             android:checkable="true"
                             android:checkable="true"
-                            android:title="@string/sort_name" />
+                            android:title="@string/sort_by_name" />
 
 
                         <item
                         <item
                             android:id="@+id/menu_sort_url"
                             android:id="@+id/menu_sort_url"

+ 3 - 1
app/src/main/res/values-es-rES/strings.xml

@@ -347,7 +347,7 @@
     <string name="sort">Ordenar</string>
     <string name="sort">Ordenar</string>
     <string name="sort_auto">Ordenar automáticamente</string>
     <string name="sort_auto">Ordenar automáticamente</string>
     <string name="sort_manual">Ordenar manualmente</string>
     <string name="sort_manual">Ordenar manualmente</string>
-    <string name="sort_name">Ordenar por nombre</string>
+    <string name="sort_by_name">Ordenar por nombre</string>
     <string name="go_to_top">Ir al principio</string>
     <string name="go_to_top">Ir al principio</string>
     <string name="go_to_bottom">Ir al final</string>
     <string name="go_to_bottom">Ir al final</string>
     <string name="read_y">Leído: %s</string>
     <string name="read_y">Leído: %s</string>
@@ -941,5 +941,7 @@
     <string name="edit_content">编辑内容</string>
     <string name="edit_content">编辑内容</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="book_change_source">整书换源</string>
     <string name="book_change_source">整书换源</string>
+    <string name="sort_by_time">时间排序</string>
+    <string name="enable_record">开启记录</string>
     <!-- string end -->
     <!-- string end -->
 </resources>
 </resources>

+ 3 - 1
app/src/main/res/values-ja-rJP/strings.xml

@@ -351,7 +351,7 @@
     <string name="sort">Sort</string>
     <string name="sort">Sort</string>
     <string name="sort_auto">Sort automatically</string>
     <string name="sort_auto">Sort automatically</string>
     <string name="sort_manual">Sort manually</string>
     <string name="sort_manual">Sort manually</string>
-    <string name="sort_name">Sort by name</string>
+    <string name="sort_by_name">Sort by name</string>
     <string name="go_to_top">Scroll to the top</string>
     <string name="go_to_top">Scroll to the top</string>
     <string name="go_to_bottom">Scroll to the bottom</string>
     <string name="go_to_bottom">Scroll to the bottom</string>
     <string name="read_y">Read: %s</string>
     <string name="read_y">Read: %s</string>
@@ -944,5 +944,7 @@
     <string name="edit_content">编辑内容</string>
     <string name="edit_content">编辑内容</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="book_change_source">整书换源</string>
     <string name="book_change_source">整书换源</string>
+    <string name="sort_by_time">时间排序</string>
+    <string name="enable_record">开启记录</string>
     <!-- string end -->
     <!-- string end -->
 </resources>
 </resources>

+ 3 - 1
app/src/main/res/values-pt-rBR/strings.xml

@@ -349,7 +349,7 @@
     <string name="sort">Ordenar</string>
     <string name="sort">Ordenar</string>
     <string name="sort_auto">Ordenar automaticamente</string>
     <string name="sort_auto">Ordenar automaticamente</string>
     <string name="sort_manual">Ordenar manualmente</string>
     <string name="sort_manual">Ordenar manualmente</string>
-    <string name="sort_name">Ordenar por nome</string>
+    <string name="sort_by_name">Ordenar por nome</string>
     <string name="go_to_top">Vá ao topo</string>
     <string name="go_to_top">Vá ao topo</string>
     <string name="go_to_bottom">Vá ao final</string>
     <string name="go_to_bottom">Vá ao final</string>
     <string name="read_y">Ler: %s</string>
     <string name="read_y">Ler: %s</string>
@@ -944,5 +944,7 @@
     <string name="edit_content">编辑内容</string>
     <string name="edit_content">编辑内容</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="book_change_source">整书换源</string>
     <string name="book_change_source">整书换源</string>
+    <string name="sort_by_time">时间排序</string>
+    <string name="enable_record">开启记录</string>
     <!-- string end -->
     <!-- string end -->
 </resources>
 </resources>

+ 3 - 1
app/src/main/res/values-zh-rHK/strings.xml

@@ -348,7 +348,7 @@
     <string name="sort">排序</string>
     <string name="sort">排序</string>
     <string name="sort_auto">智能排序</string>
     <string name="sort_auto">智能排序</string>
     <string name="sort_manual">手動排序</string>
     <string name="sort_manual">手動排序</string>
-    <string name="sort_name">名稱排序</string>
+    <string name="sort_by_name">名稱排序</string>
     <string name="go_to_top">滾動到頂部</string>
     <string name="go_to_top">滾動到頂部</string>
     <string name="go_to_bottom">滾動到底部</string>
     <string name="go_to_bottom">滾動到底部</string>
     <string name="read_y">已讀: %s</string>
     <string name="read_y">已讀: %s</string>
@@ -941,5 +941,7 @@
     <string name="edit_content">编辑内容</string>
     <string name="edit_content">编辑内容</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="book_change_source">整书换源</string>
     <string name="book_change_source">整书换源</string>
+    <string name="sort_by_time">时间排序</string>
+    <string name="enable_record">开启记录</string>
     <!-- string end -->
     <!-- string end -->
 </resources>
 </resources>

+ 3 - 1
app/src/main/res/values-zh-rTW/strings.xml

@@ -350,7 +350,7 @@
     <string name="sort">排序</string>
     <string name="sort">排序</string>
     <string name="sort_auto">智慧排序</string>
     <string name="sort_auto">智慧排序</string>
     <string name="sort_manual">手動排序</string>
     <string name="sort_manual">手動排序</string>
-    <string name="sort_name">名稱排序</string>
+    <string name="sort_by_name">名稱排序</string>
     <string name="go_to_top">滾動到頂部</string>
     <string name="go_to_top">滾動到頂部</string>
     <string name="go_to_bottom">滾動到底部</string>
     <string name="go_to_bottom">滾動到底部</string>
     <string name="read_y">已讀: %s</string>
     <string name="read_y">已讀: %s</string>
@@ -943,5 +943,7 @@
     <string name="edit_content">编辑内容</string>
     <string name="edit_content">编辑内容</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="book_change_source">整书换源</string>
     <string name="book_change_source">整书换源</string>
+    <string name="sort_by_time">时间排序</string>
+    <string name="enable_record">开启记录</string>
     <!-- string end -->
     <!-- string end -->
 </resources>
 </resources>

+ 3 - 1
app/src/main/res/values-zh/strings.xml

@@ -350,7 +350,7 @@
     <string name="sort">排序</string>
     <string name="sort">排序</string>
     <string name="sort_auto">智能排序</string>
     <string name="sort_auto">智能排序</string>
     <string name="sort_manual">手动排序</string>
     <string name="sort_manual">手动排序</string>
-    <string name="sort_name">名称排序</string>
+    <string name="sort_by_name">名称排序</string>
     <string name="go_to_top">滚动到顶部</string>
     <string name="go_to_top">滚动到顶部</string>
     <string name="go_to_bottom">滚动到底部</string>
     <string name="go_to_bottom">滚动到底部</string>
     <string name="read_y">已读: %s</string>
     <string name="read_y">已读: %s</string>
@@ -943,5 +943,7 @@
     <string name="edit_content">编辑内容</string>
     <string name="edit_content">编辑内容</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="book_change_source">整书换源</string>
     <string name="book_change_source">整书换源</string>
+    <string name="sort_by_time">时间排序</string>
+    <string name="enable_record">开启记录</string>
     <!-- string end -->
     <!-- string end -->
 </resources>
 </resources>

+ 3 - 1
app/src/main/res/values/strings.xml

@@ -351,7 +351,7 @@
     <string name="sort">Sort</string>
     <string name="sort">Sort</string>
     <string name="sort_auto">Sort automatically</string>
     <string name="sort_auto">Sort automatically</string>
     <string name="sort_manual">Sort manually</string>
     <string name="sort_manual">Sort manually</string>
-    <string name="sort_name">Sort by name</string>
+    <string name="sort_by_name">Sort by name</string>
     <string name="go_to_top">Scroll to the top</string>
     <string name="go_to_top">Scroll to the top</string>
     <string name="go_to_bottom">Scroll to the bottom</string>
     <string name="go_to_bottom">Scroll to the bottom</string>
     <string name="read_y">Read: %s</string>
     <string name="read_y">Read: %s</string>
@@ -944,5 +944,7 @@
     <string name="edit_content">Edit Content</string>
     <string name="edit_content">Edit Content</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="chapter_change_source">单章换源</string>
     <string name="book_change_source">整书换源</string>
     <string name="book_change_source">整书换源</string>
+    <string name="sort_by_time">时间排序</string>
+    <string name="enable_record">开启记录</string>
     <!-- string end -->
     <!-- string end -->
 </resources>
 </resources>