订阅源选择分组时只搜索分组

pull/783/head
gedoor 4 years ago
parent 8aa68e6199
commit 6e03649e7d
  1. 3
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  2. 19
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -25,6 +25,9 @@ interface RssSourceDao {
@Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key order by customOrder") @Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key order by customOrder")
fun liveSearch(key: String): LiveData<List<RssSource>> fun liveSearch(key: String): LiveData<List<RssSource>>
@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 and (sourceName like '%'||:searchKey||'%' or sourceGroup like '%'||:searchKey||'%' or sourceUrl like '%'||:searchKey||'%') order by customOrder")
fun liveEnabled(searchKey: String): LiveData<List<RssSource>> fun liveEnabled(searchKey: String): LiveData<List<RssSource>>

@ -95,7 +95,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
R.id.menu_help -> showHelp() R.id.menu_help -> showHelp()
else -> if (item.groupId == R.id.source_group) { else -> if (item.groupId == R.id.source_group) {
binding.titleBar.findViewById<SearchView>(R.id.search_view) binding.titleBar.findViewById<SearchView>(R.id.search_view)
.setQuery(item.title, true) .setQuery("group:${item.title}", true)
} }
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
@ -197,13 +197,20 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
} }
} }
private fun initLiveDataSource(key: String? = null) { private fun initLiveDataSource(searchKey: String? = null) {
sourceLiveData?.removeObservers(this) sourceLiveData?.removeObservers(this)
sourceLiveData = sourceLiveData =
if (key.isNullOrBlank()) { when {
App.db.rssSourceDao.liveAll() searchKey.isNullOrBlank() -> {
} else { App.db.rssSourceDao.liveAll()
App.db.rssSourceDao.liveSearch("%$key%") }
searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:")
App.db.rssSourceDao.liveGroupSearch("%$key%")
}
else -> {
App.db.rssSourceDao.liveSearch("%$searchKey%")
}
} }
sourceLiveData?.observe(this, { sourceLiveData?.observe(this, {
adapter.setItems(it, adapter.diffItemCallback) adapter.setItems(it, adapter.diffItemCallback)

Loading…
Cancel
Save