feat: 优化

pull/243/head
gedoor 5 years ago
parent c6d6d27cf3
commit da56541318
  1. 6
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 19
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt

@ -14,6 +14,12 @@ interface BookSourceDao {
@Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey order by customOrder asc") @Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl 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 enabled = 1 order by customOrder asc")
fun liveDataEnabled(): LiveData<List<BookSource>>
@Query("select * from book_sources where enabled = 0 order by customOrder asc")
fun liveDataDisabled(): LiveData<List<BookSource>>
@Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc")
fun liveExplore(): LiveData<List<BookSource>> fun liveExplore(): LiveData<List<BookSource>>

@ -115,6 +115,12 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
sort = 4 sort = 4
initLiveDataBookSource(search_view.query?.toString()) initLiveDataBookSource(search_view.query?.toString())
} }
R.id.menu_enabled_group -> {
search_view.setQuery(getString(R.string.enabled), true)
}
R.id.menu_disabled_group -> {
search_view.setQuery(getString(R.string.disabled), true)
}
} }
if (item.groupId == R.id.source_group) { if (item.groupId == R.id.source_group) {
search_view.setQuery(item.title, true) search_view.setQuery(item.title, true)
@ -166,11 +172,20 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
private fun initLiveDataBookSource(searchKey: String? = null) { private fun initLiveDataBookSource(searchKey: String? = null) {
bookSourceLiveDate?.removeObservers(this) bookSourceLiveDate?.removeObservers(this)
bookSourceLiveDate = if (searchKey.isNullOrEmpty()) { bookSourceLiveDate = when {
searchKey.isNullOrEmpty() -> {
App.db.bookSourceDao().liveDataAll() App.db.bookSourceDao().liveDataAll()
} else { }
searchKey == getString(R.string.enabled) -> {
App.db.bookSourceDao().liveDataEnabled()
}
searchKey == getString(R.string.disabled) -> {
App.db.bookSourceDao().liveDataDisabled()
}
else -> {
App.db.bookSourceDao().liveDataSearch("%$searchKey%") App.db.bookSourceDao().liveDataSearch("%$searchKey%")
} }
}
bookSourceLiveDate?.observe(this, Observer { data -> bookSourceLiveDate?.observe(this, Observer { data ->
val sourceList = when (sort) { val sourceList = when (sort) {
1 -> data.sortedBy { it.weight } 1 -> data.sortedBy { it.weight }

Loading…
Cancel
Save