优化一些代码 (#4601)

This commit is contained in:
niuhb
2025-02-02 19:32:44 +08:00
committed by GitHub
parent 89b393ff7d
commit acdec5cb45
3 changed files with 13 additions and 16 deletions
@@ -10,12 +10,12 @@ interface RssReadRecordDao {
fun insertRecord(vararg rssReadRecord: RssReadRecord)
@Query("select * from rssReadRecords order by readTime desc")
fun getRecord(): List<RssReadRecord>
fun getRecords(): List<RssReadRecord>
@get:Query("select count(1) from rssReadRecords")
val countRead: Int
val countRecords: Int
@Query("delete from rssReadRecords")
fun deleteRecord()
fun deleteAllRecord()
}
@@ -2,7 +2,6 @@ package io.legado.app.ui.rss.article
import android.content.Context
import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
@@ -44,18 +43,18 @@ class ReadRecordDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.adapter = adapter
}
adapter.setItems(viewModel.getRecord())
adapter.setItems(viewModel.getRecords())
}
override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.menu_clear -> {
alert(R.string.draw) {
val countRead = viewModel.countRead()
val countRead = viewModel.countRecords()
setMessage(getString(R.string.sure_del) + "\n" + countRead + " " + getString(R.string.read_record))
noButton()
yesButton{
viewModel.delReadRecord()
yesButton {
viewModel.deleteAllRecord()
adapter.clearItems()
}
}
@@ -77,8 +76,6 @@ class ReadRecordDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
item: RssReadRecord,
payloads: MutableList<Any>
) {
binding.textTitle.movementMethod = ScrollingMovementMethod()
binding.textRecord.movementMethod = ScrollingMovementMethod()
binding.textTitle.text = item.title
binding.textRecord.text = item.record
}
@@ -77,17 +77,17 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
}
}
fun getRecord(): List<RssReadRecord> {
return appDb.rssReadRecordDao.getRecord()
fun getRecords(): List<RssReadRecord> {
return appDb.rssReadRecordDao.getRecords()
}
fun countRead() : Int {
return appDb.rssReadRecordDao.countRead
fun countRecords() : Int {
return appDb.rssReadRecordDao.countRecords
}
fun delReadRecord() {
fun deleteAllRecord() {
execute {
appDb.rssReadRecordDao.deleteRecord()
appDb.rssReadRecordDao.deleteAllRecord()
}
}