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

pull/2091/head
kunfei 2 years ago
parent 2e07a89afd
commit 94f4e2b080
  1. 1
      app/build.gradle
  2. 18
      app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt
  3. 50
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  4. 49
      app/src/main/res/layout/activity_read_record.xml
  5. 2
      app/src/main/res/layout/item_read_record.xml
  6. 1
      app/src/main/res/menu/book_read_record.xml

@ -197,7 +197,6 @@ dependencies {
implementation("com.google.android.exoplayer:extension-okhttp:$exoplayer_version")
//Splitties
implementation("com.louiscad.splitties:splitties-appctx:$splitties_version")
implementation("com.louiscad.splitties:splitties-systemservices:$splitties_version")
implementation("com.louiscad.splitties:splitties-views:$splitties_version")

@ -10,12 +10,28 @@ interface ReadRecordDao {
@get:Query("select * from readRecord")
val all: List<ReadRecord>
@get:Query("select bookName, sum(readTime) as readTime, max(lastRead) as lastRead 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")
val allTime: Long
@Query(
"""
select bookName, sum(readTime) as readTime, max(lastRead) as lastRead
from readRecord
where bookName like '%' || :searchKey || '%'
group by bookName
order by bookName collate localized"""
)
fun search(searchKey: String): List<ReadRecordShow>
@Query("select sum(readTime) from readRecord where bookName = :bookName")
fun getReadTime(bookName: String): Long?

@ -6,6 +6,7 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.ViewGroup
import androidx.appcompat.widget.SearchView
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.base.adapter.ItemViewHolder
@ -16,10 +17,11 @@ import io.legado.app.databinding.ActivityReadRecordBinding
import io.legado.app.databinding.ItemReadRecordBinding
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.utils.applyTint
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
@ -30,11 +32,15 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
private val adapter by lazy { RecordAdapter(this) }
private var sortMode = 0
private val searchView: SearchView by lazy {
binding.titleBar.findViewById(R.id.search_view)
}
override val binding by viewBinding(ActivityReadRecordBinding::inflate)
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
initAllTime()
initData()
}
@ -72,13 +78,10 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
return super.onCompatOptionsItemSelected(item)
}
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 {
private fun initView() {
initSearchView()
binding.tvBookName.setText(R.string.all_read_time)
binding.tvRemove.setOnClickListener {
alert(R.string.delete, R.string.sure_del) {
yesButton {
appDb.readRecordDao.clear()
@ -87,16 +90,41 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
noButton()
}
}
binding.recyclerView.adapter = adapter
}
private fun initSearchView() {
searchView.applyTint(primaryTextColor)
searchView.onActionViewExpanded()
searchView.isSubmitButtonEnabled = true
searchView.queryHint = getString(R.string.search)
searchView.clearFocus()
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
searchView.clearFocus()
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
initData(newText)
return false
}
})
}
private fun initData() {
private fun initAllTime() {
launch {
val allTime = withContext(IO) {
appDb.readRecordDao.allTime
}
binding.readRecord.tvReadingTime.text = formatDuring(allTime)
binding.tvReadingTime.text = formatDuring(allTime)
}
}
private fun initData(searchKey: String? = null) {
launch {
val readRecords = withContext(IO) {
appDb.readRecordDao.allShow.let { records ->
appDb.readRecordDao.search(searchKey ?: "").let { records ->
when (sortMode) {
1 -> records.sortedByDescending { it.readTime }
2 -> records.sortedByDescending { it.lastRead }

@ -3,25 +3,60 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentLayout="@layout/view_search"
app:title="@string/read_record" />
<FrameLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp">
android:paddingLeft="10dp"
android:paddingRight="10dp">
<include
android:id="@+id/read_record"
layout="@layout/item_read_record" />
<TextView
android:id="@+id/tv_book_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="6dp"
android:textColor="@color/primaryText"
android:singleLine="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_remove"
tools:text="name"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<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_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_book_name"
app:layout_constraintRight_toLeftOf="@+id/tv_remove"
tools:text="readingTime" />
<TextView
android:id="@+id/tv_remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/clear"
android:textColor="@color/primaryText"
android:background="?attr/selectableItemBackground"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"

@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingLeft="10dp"
android:paddingRight="10dp">
@ -73,6 +74,7 @@
android:padding="6dp"
android:text="@string/clear"
android:textColor="@color/primaryText"
android:background="?attr/selectableItemBackground"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

@ -17,6 +17,7 @@
<item
android:id="@+id/menu_sort_name"
android:checked="true"
android:title="@string/sort_by_name" />
<item

Loading…
Cancel
Save