阅读记录添加最后阅读时间

pull/2088/head
kunfei 2 years ago
parent b3a470a4b0
commit 81f9abda71
  1. 2
      app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt
  2. 5
      app/src/main/java/io/legado/app/data/entities/ReadRecordShow.kt
  3. 24
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  4. 44
      app/src/main/res/layout/item_read_record.xml
  5. 33
      app/src/main/res/menu/book_read_record.xml
  6. 4
      app/src/main/res/values-es-rES/strings.xml
  7. 4
      app/src/main/res/values-ja-rJP/strings.xml
  8. 4
      app/src/main/res/values-pt-rBR/strings.xml
  9. 4
      app/src/main/res/values-zh-rHK/strings.xml
  10. 4
      app/src/main/res/values-zh-rTW/strings.xml
  11. 4
      app/src/main/res/values-zh/strings.xml
  12. 4
      app/src/main/res/values/strings.xml

@ -10,7 +10,7 @@ interface ReadRecordDao {
@get:Query("select * from readRecord")
val all: List<ReadRecord>
@get:Query("select bookName, sum(readTime) as readTime from readRecord group by bookName order by bookName collate localized")
@get:Query("select bookName, sum(readTime) as readTime, max(lastRead) as lastRead from readRecord group by bookName order by bookName collate localized")
val allShow: List<ReadRecordShow>
@get:Query("select sum(readTime) from readRecord")

@ -1,6 +1,7 @@
package io.legado.app.data.entities
data class ReadRecordShow(
var bookName: String = "",
var readTime: Long = 0L
var bookName: String,
var readTime: Long,
var lastRead: Long
)

@ -1,6 +1,7 @@
package io.legado.app.ui.about
import android.content.Context
import android.icu.text.SimpleDateFormat
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
@ -18,6 +19,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.utils.cnCompare
import io.legado.app.utils.gone
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
@ -50,10 +52,17 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
when (item.itemId) {
R.id.menu_sort_name -> {
sortMode = 0
item.isChecked = true
initData()
}
R.id.menu_sort_time -> {
R.id.menu_sort_read_long -> {
sortMode = 1
item.isChecked = true
initData()
}
R.id.menu_sort_read_time -> {
sortMode = 2
item.isChecked = true
initData()
}
R.id.menu_enable_record -> {
@ -65,6 +74,9 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
private fun initView() = binding.run {
readRecord.tvBookName.setText(R.string.all_read_time)
readRecord.tvLastReadTimeTag.gone()
readRecord.tvLastReadTimeTag.gone()
readRecord.tvLastReadTime.gone()
recyclerView.adapter = adapter
readRecord.tvRemove.setOnClickListener {
alert(R.string.delete, R.string.sure_del) {
@ -82,11 +94,12 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
val allTime = withContext(IO) {
appDb.readRecordDao.allTime
}
binding.readRecord.tvReadTime.text = formatDuring(allTime)
binding.readRecord.tvReadingTime.text = formatDuring(allTime)
val readRecords = withContext(IO) {
appDb.readRecordDao.allShow.let { records ->
when (sortMode) {
1 -> records.sortedBy { it.readTime }
1 -> records.sortedByDescending { it.readTime }
2 -> records.sortedByDescending { it.lastRead }
else -> records.sortedWith { o1, o2 ->
o1.bookName.cnCompare(o2.bookName)
}
@ -100,6 +113,8 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
inner class RecordAdapter(context: Context) :
RecyclerAdapter<ReadRecordShow, ItemReadRecordBinding>(context) {
private val dateFormat = SimpleDateFormat("yyyy-MM-dd")
override fun getViewBinding(parent: ViewGroup): ItemReadRecordBinding {
return ItemReadRecordBinding.inflate(inflater, parent, false)
}
@ -112,7 +127,8 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
) {
binding.apply {
tvBookName.text = item.bookName
tvReadTime.text = formatDuring(item.readTime)
tvReadingTime.text = formatDuring(item.readTime)
tvLastReadTime.text = dateFormat.format(item.lastRead)
}
}

@ -21,16 +21,50 @@
tools:ignore="RtlHardcoded" />
<TextView
android:id="@+id/tv_read_time"
android:layout_width="0dp"
android:id="@+id/tv_reading_time_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:singleLine="true"
android:text="@string/reading_time_tag"
android:textColor="@color/secondaryText"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_book_name" />
<TextView
android:id="@+id/tv_reading_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="6dp"
android:singleLine="true"
android:textColor="@color/secondaryText"
app:layout_constraintLeft_toRightOf="@+id/tv_reading_time_tag"
app:layout_constraintTop_toBottomOf="@id/tv_book_name"
app:layout_constraintRight_toLeftOf="@+id/tv_remove"
tools:text="time" />
tools:text="readingTime" />
<TextView
android:id="@+id/tv_last_read_time_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:singleLine="true"
android:text="@string/last_read_time_tag"
android:textColor="@color/secondaryText"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_reading_time_tag" />
<TextView
android:id="@+id/tv_last_read_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="6dp"
android:singleLine="true"
android:textColor="@color/secondaryText"
app:layout_constraintLeft_toRightOf="@+id/tv_last_read_time_tag"
app:layout_constraintTop_toBottomOf="@id/tv_reading_time_tag"
app:layout_constraintRight_toLeftOf="@+id/tv_remove"
tools:text="readingTime" />
<TextView
android:id="@+id/tv_remove"
@ -40,7 +74,7 @@
android:text="@string/clear"
android:textColor="@color/primaryText"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_book_name"
app:layout_constraintBottom_toBottomOf="@+id/tv_read_time" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,21 +1,44 @@
<?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">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/menu_sort"
android:icon="@drawable/ic_baseline_sort_24"
android:title="@string/sort"
app:showAsAction="always"
tools:ignore="AlwaysShowAction">
<menu>
<group
android:id="@+id/menu_group_sort"
android:checkableBehavior="single">
<item
android:id="@+id/menu_sort_name"
android:title="@string/sort_by_name"
android:title="@string/sort_by_name" />
<item
android:id="@+id/menu_sort_read_long"
android:title="@string/reading_time_sort"
app:showAsAction="never" />
<item
android:id="@+id/menu_sort_time"
android:title="@string/sort_by_time"
android:id="@+id/menu_sort_read_time"
android:title="@string/last_read_time_sort"
app:showAsAction="never" />
</group>
</menu>
</item>
<item
android:id="@+id/menu_enable_record"
android:title="@string/enable_record"
android:checkable="true"
android:title="@string/enable_record"
app:showAsAction="never" />
</menu>

@ -999,4 +999,8 @@
<string name="error_image_url_empty">Image url is empty, check replacement rules</string>
<string name="variable_comment">变量说明(variableComment)</string>
<string name="remote_book">远程书籍</string>
<string name="reading_time_sort">阅读时长排序</string>
<string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string>
</resources>

@ -1002,4 +1002,8 @@
<string name="error_image_url_empty">Image url is empty, check replacement rules</string>
<string name="variable_comment">变量说明(variableComment)</string>
<string name="remote_book">远程书籍</string>
<string name="reading_time_sort">阅读时长排序</string>
<string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string>
</resources>

@ -1002,4 +1002,8 @@
<string name="error_image_url_empty">Image url is empty, check replacement rules</string>
<string name="variable_comment">变量说明(variableComment)</string>
<string name="remote_book">远程书籍</string>
<string name="reading_time_sort">阅读时长排序</string>
<string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string>
</resources>

@ -999,4 +999,8 @@
<string name="error_image_url_empty">图片链接为空,检查替换净化规则</string>
<string name="variable_comment">变量说明(variableComment)</string>
<string name="remote_book">远程书籍</string>
<string name="reading_time_sort">阅读时长排序</string>
<string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string>
</resources>

@ -1001,4 +1001,8 @@
<string name="error_image_url_empty">图片链接为空,检查替换净化规则</string>
<string name="variable_comment">变量说明(variableComment)</string>
<string name="remote_book">远程书籍</string>
<string name="reading_time_sort">阅读时长排序</string>
<string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string>
</resources>

@ -1001,4 +1001,8 @@
<string name="error_image_url_empty">图片链接为空,检查替换净化规则</string>
<string name="variable_comment">变量说明(variableComment)</string>
<string name="remote_book">远程书籍</string>
<string name="reading_time_sort">阅读时长排序</string>
<string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string>
</resources>

@ -1002,4 +1002,8 @@
<string name="error_image_url_empty">Image url is empty, check replacement rules</string>
<string name="variable_comment">变量说明(variableComment)</string>
<string name="remote_book">远程书籍</string>
<string name="reading_time_sort">阅读时长排序</string>
<string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string>
</resources>

Loading…
Cancel
Save