添加阅读记录开关

pull/1649/head
kunfei 3 years ago
parent e3038daee1
commit c47190b30b
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 6
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 8
      app/src/main/java/io/legado/app/model/ReadBook.kt
  4. 2
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  5. 35
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  6. 15
      app/src/main/res/menu/book_read_record.xml
  7. 2
      app/src/main/res/menu/book_source.xml
  8. 4
      app/src/main/res/values-es-rES/strings.xml
  9. 4
      app/src/main/res/values-ja-rJP/strings.xml
  10. 4
      app/src/main/res/values-pt-rBR/strings.xml
  11. 4
      app/src/main/res/values-zh-rHK/strings.xml
  12. 4
      app/src/main/res/values-zh-rTW/strings.xml
  13. 4
      app/src/main/res/values-zh/strings.xml
  14. 4
      app/src/main/res/values/strings.xml

@ -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"

@ -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)

@ -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)
}

@ -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()
}

@ -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<ActivityReadRecordBinding>() {
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<ActivityReadRecordBinding>() {
sortMode = 1
initData()
}
R.id.menu_enable_record -> {
AppConfig.enableReadRecord = !item.isChecked
}
}
return super.onCompatOptionsItemSelected(item)
}
@ -70,23 +78,22 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
}
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)
}
}

@ -1,12 +1,21 @@
<?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
android:id="@+id/menu_sort_name"
android:title="按书名排序" />
android:title="@string/sort_by_name"
app:showAsAction="never" />
<item
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>

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

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

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

@ -349,7 +349,7 @@
<string name="sort">Ordenar</string>
<string name="sort_auto">Ordenar automaticamente</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_bottom">Vá ao final</string>
<string name="read_y">Ler: %s</string>
@ -944,5 +944,7 @@
<string name="edit_content">编辑内容</string>
<string name="chapter_change_source">单章换源</string>
<string name="book_change_source">整书换源</string>
<string name="sort_by_time">时间排序</string>
<string name="enable_record">开启记录</string>
<!-- string end -->
</resources>

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

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

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

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

Loading…
Cancel
Save