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. 8
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -12,10 +12,10 @@ interface BookSourceDao {
fun liveDataAll(): LiveData<List<BookSource>> 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") @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") @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") @Query("select * from book_sources where enabled = 1 order by customOrder asc")
fun liveDataEnabled(): LiveData<List<BookSource>> fun liveDataEnabled(): LiveData<List<BookSource>>

@ -28,9 +28,15 @@ interface RssSourceDao {
@Query("SELECT * FROM rssSources where sourceGroup like :key order by customOrder") @Query("SELECT * FROM rssSources where sourceGroup like :key order by customOrder")
fun liveGroupSearch(key: String): LiveData<List<RssSource>> 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>> 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) <> ''") @Query("select sourceGroup from rssSources where trim(sourceGroup) <> ''")
fun liveGroup(): LiveData<List<String>> fun liveGroup(): LiveData<List<String>>

@ -92,7 +92,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
} }
override fun onQueryTextChange(newText: String?): Boolean { override fun onQueryTextChange(newText: String?): Boolean {
initData(newText ?: "") initData(newText)
return false 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?.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, { observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
}) })

@ -199,8 +199,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private fun initLiveDataSource(searchKey: String? = null) { private fun initLiveDataSource(searchKey: String? = null) {
sourceLiveData?.removeObservers(this) sourceLiveData?.removeObservers(this)
sourceLiveData = sourceLiveData = when {
when {
searchKey.isNullOrBlank() -> { searchKey.isNullOrBlank() -> {
App.db.rssSourceDao.liveAll() App.db.rssSourceDao.liveAll()
} }
@ -211,11 +210,12 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
else -> { else -> {
App.db.rssSourceDao.liveSearch("%$searchKey%") App.db.rssSourceDao.liveSearch("%$searchKey%")
} }
} }.apply {
sourceLiveData?.observe(this, { observe(this@RssSourceActivity, {
adapter.setItems(it, adapter.diffItemCallback) adapter.setItems(it, adapter.diffItemCallback)
}) })
} }
}
private fun showHelp() { private fun showHelp() {
val text = String(assets.open("help/SourceMRssHelp.md").readBytes()) val text = String(assets.open("help/SourceMRssHelp.md").readBytes())

Loading…
Cancel
Save