feat: 优化代码

pull/141/head
kunfei 5 years ago
parent cd10ded805
commit 2b52966e46
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  3. 4
      app/src/main/res/menu/arrange_book.xml

@ -27,6 +27,9 @@ interface BookDao {
@Query("SELECT * FROM books WHERE (`group` & :group) > 0") @Query("SELECT * FROM books WHERE (`group` & :group) > 0")
fun observeByGroup(group: Int): LiveData<List<Book>> fun observeByGroup(group: Int): LiveData<List<Book>>
@Query("select * from books where (SELECT sum(groupId) FROM book_groups) & `group` = 0")
fun observeNoGroup(): LiveData<List<Book>>
@Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'") @Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'")
fun liveDataSearch(key: String): LiveData<List<Book>> fun liveDataSearch(key: String): LiveData<List<Book>>

@ -100,6 +100,7 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
-1 -> App.db.bookDao().observeAll() -1 -> App.db.bookDao().observeAll()
-2 -> App.db.bookDao().observeLocal() -2 -> App.db.bookDao().observeLocal()
-3 -> App.db.bookDao().observeAudio() -3 -> App.db.bookDao().observeAudio()
-11 -> App.db.bookDao().observeNoGroup()
else -> App.db.bookDao().observeByGroup(groupId) else -> App.db.bookDao().observeByGroup(groupId)
} }
booksLiveData?.observe(this, Observer { booksLiveData?.observe(this, Observer {
@ -112,6 +113,11 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
when (item.itemId) { when (item.itemId) {
R.id.menu_group_manage -> GroupManageDialog() R.id.menu_group_manage -> GroupManageDialog()
.show(supportFragmentManager, "groupManage") .show(supportFragmentManager, "groupManage")
R.id.menu_no_group -> {
title_bar.subtitle = getString(R.string.no_group)
groupId = -11
initBookData()
}
R.id.menu_all -> { R.id.menu_all -> {
title_bar.subtitle = item.title title_bar.subtitle = item.title
groupId = -1 groupId = -1

@ -14,6 +14,10 @@
android:id="@+id/menu_group_manage" android:id="@+id/menu_group_manage"
android:title="@string/group_manage" /> android:title="@string/group_manage" />
<item
android:id="@+id/menu_no_group"
android:title="@string/no_group" />
<item <item
android:id="@+id/menu_all" android:id="@+id/menu_all"
android:title="@string/all" /> android:title="@string/all" />

Loading…
Cancel
Save