优化一些代码 (#4601)
This commit is contained in:
@@ -10,12 +10,12 @@ interface RssReadRecordDao {
|
|||||||
fun insertRecord(vararg rssReadRecord: RssReadRecord)
|
fun insertRecord(vararg rssReadRecord: RssReadRecord)
|
||||||
|
|
||||||
@Query("select * from rssReadRecords order by readTime desc")
|
@Query("select * from rssReadRecords order by readTime desc")
|
||||||
fun getRecord(): List<RssReadRecord>
|
fun getRecords(): List<RssReadRecord>
|
||||||
|
|
||||||
@get:Query("select count(1) from rssReadRecords")
|
@get:Query("select count(1) from rssReadRecords")
|
||||||
val countRead: Int
|
val countRecords: Int
|
||||||
|
|
||||||
@Query("delete from rssReadRecords")
|
@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.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.method.ScrollingMovementMethod
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -44,18 +43,18 @@ class ReadRecordDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
|||||||
recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
}
|
}
|
||||||
adapter.setItems(viewModel.getRecord())
|
adapter.setItems(viewModel.getRecords())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemClick(item: MenuItem?): Boolean {
|
override fun onMenuItemClick(item: MenuItem?): Boolean {
|
||||||
when (item?.itemId) {
|
when (item?.itemId) {
|
||||||
R.id.menu_clear -> {
|
R.id.menu_clear -> {
|
||||||
alert(R.string.draw) {
|
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))
|
setMessage(getString(R.string.sure_del) + "\n" + countRead + " " + getString(R.string.read_record))
|
||||||
noButton()
|
noButton()
|
||||||
yesButton{
|
yesButton {
|
||||||
viewModel.delReadRecord()
|
viewModel.deleteAllRecord()
|
||||||
adapter.clearItems()
|
adapter.clearItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,8 +76,6 @@ class ReadRecordDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
|||||||
item: RssReadRecord,
|
item: RssReadRecord,
|
||||||
payloads: MutableList<Any>
|
payloads: MutableList<Any>
|
||||||
) {
|
) {
|
||||||
binding.textTitle.movementMethod = ScrollingMovementMethod()
|
|
||||||
binding.textRecord.movementMethod = ScrollingMovementMethod()
|
|
||||||
binding.textTitle.text = item.title
|
binding.textTitle.text = item.title
|
||||||
binding.textRecord.text = item.record
|
binding.textRecord.text = item.record
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,17 +77,17 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRecord(): List<RssReadRecord> {
|
fun getRecords(): List<RssReadRecord> {
|
||||||
return appDb.rssReadRecordDao.getRecord()
|
return appDb.rssReadRecordDao.getRecords()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun countRead() : Int {
|
fun countRecords() : Int {
|
||||||
return appDb.rssReadRecordDao.countRead
|
return appDb.rssReadRecordDao.countRecords
|
||||||
}
|
}
|
||||||
|
|
||||||
fun delReadRecord() {
|
fun deleteAllRecord() {
|
||||||
execute {
|
execute {
|
||||||
appDb.rssReadRecordDao.deleteRecord()
|
appDb.rssReadRecordDao.deleteAllRecord()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user