pull/783/head
gedoor 4 years ago
parent 692ad361a8
commit f93d1b6f6c
  1. 4
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 8
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  3. 13
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  4. 30
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -12,10 +12,10 @@ interface BookSourceDao {
fun liveDataAll(): LiveData<List<BookSource>>
@Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey or bookSourceComment like :searchKey order by customOrder asc")
fun liveDataSearch(searchKey: String = ""): LiveData<List<BookSource>>
fun liveDataSearch(searchKey: String): LiveData<List<BookSource>>
@Query("select * from book_sources where bookSourceGroup like :searchKey order by customOrder asc")
fun liveDataGroupSearch(searchKey: String = ""): LiveData<List<BookSource>>
fun liveDataGroupSearch(searchKey: String): LiveData<List<BookSource>>
@Query("select * from book_sources where enabled = 1 order by customOrder asc")
fun liveDataEnabled(): LiveData<List<BookSource>>

@ -28,9 +28,15 @@ interface RssSourceDao {
@Query("SELECT * FROM rssSources where sourceGroup like :key order by customOrder")
fun liveGroupSearch(key: String): LiveData<List<RssSource>>
@Query("SELECT * FROM rssSources where enabled = 1 and (sourceName like '%'||:searchKey||'%' or sourceGroup like '%'||:searchKey||'%' or sourceUrl like '%'||:searchKey||'%') order by customOrder")
@Query("SELECT * FROM rssSources where enabled = 1 order by customOrder")
fun liveEnabled(): LiveData<List<RssSource>>
@Query("SELECT * FROM rssSources where enabled = 1 and (sourceName like :searchKey or sourceGroup like :searchKey or sourceUrl like :searchKey) order by customOrder")
fun liveEnabled(searchKey: String): LiveData<List<RssSource>>
@Query("SELECT * FROM rssSources where enabled = 1 and sourceGroup like :searchKey order by customOrder")
fun liveEnabledByGroup(searchKey: String): LiveData<List<RssSource>>
@Query("select sourceGroup from rssSources where trim(sourceGroup) <> ''")
fun liveGroup(): LiveData<List<String>>

@ -92,7 +92,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
}
override fun onQueryTextChange(newText: String?): Boolean {
initData(newText ?: "")
initData(newText)
return false
}
})
@ -113,9 +113,16 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
}
}
private fun initData(searchKey: String = "") {
private fun initData(searchKey: String? = null) {
liveRssData?.removeObservers(this)
liveRssData = App.db.rssSourceDao.liveEnabled(searchKey).apply {
liveRssData = when {
searchKey.isNullOrEmpty() -> App.db.rssSourceDao.liveEnabled()
searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:")
App.db.rssSourceDao.liveEnabledByGroup("%$key%")
}
else -> App.db.rssSourceDao.liveEnabled("%$searchKey%")
}.apply {
observe(viewLifecycleOwner, {
adapter.setItems(it)
})

@ -199,22 +199,22 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private fun initLiveDataSource(searchKey: String? = null) {
sourceLiveData?.removeObservers(this)
sourceLiveData =
when {
searchKey.isNullOrBlank() -> {
App.db.rssSourceDao.liveAll()
}
searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:")
App.db.rssSourceDao.liveGroupSearch("%$key%")
}
else -> {
App.db.rssSourceDao.liveSearch("%$searchKey%")
}
sourceLiveData = when {
searchKey.isNullOrBlank() -> {
App.db.rssSourceDao.liveAll()
}
sourceLiveData?.observe(this, {
adapter.setItems(it, adapter.diffItemCallback)
})
searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:")
App.db.rssSourceDao.liveGroupSearch("%$key%")
}
else -> {
App.db.rssSourceDao.liveSearch("%$searchKey%")
}
}.apply {
observe(this@RssSourceActivity, {
adapter.setItems(it, adapter.diffItemCallback)
})
}
}
private fun showHelp() {

Loading…
Cancel
Save