From 2ecd94ffde312240e36c7393df204db4c799b496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Sat, 24 Oct 2020 20:08:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=B9=A6=E6=9E=B6=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B9=A6=E7=B1=8D=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/dao/BookDao.kt | 12 ++++++++++++ .../app/ui/main/bookshelf/BookshelfFragment.kt | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 8794296f6..39986674a 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -45,6 +45,18 @@ interface BookDao { @get:Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups) & `group` = 0") val noGroupSize: Int + @Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups) & `group` = :groupId") + fun groupCount(groupId: Long): Int + + @get:Query("SELECT count(*) FROM books where origin = '${BookType.local}'") + val localBookCount: Int + + @get:Query("SELECT count(*) FROM books where origin = '${BookType.audio}'") + val audioBookCount: Int + + @get:Query("SELECT count(*) FROM books where origin != '${BookType.audio}' and origin != '${BookType.local}' and `group` = 0") + val noneBookCount: Int + @get:Query("SELECT * FROM books where origin <> '${BookType.local}' and type = 0") val webBooks: List diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 218bc004a..64f7220f2 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -8,6 +8,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter import androidx.lifecycle.LiveData +import androidx.lifecycle.observe import com.google.android.material.tabs.TabLayout import io.legado.app.App import io.legado.app.R @@ -58,6 +59,11 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b initBookGroupData() } + override fun onResume() { + super.onResume() + adapter.notifyDataSetChanged() + } + override fun onCompatCreateOptionsMenu(menu: Menu) { menuInflater.inflate(R.menu.main_bookshelf, menu) } @@ -209,7 +215,14 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { override fun getPageTitle(position: Int): CharSequence? { - return bookGroups[position].groupName + val group = bookGroups[position] + return "${group.groupName} • ${when (group.groupId) { + AppConst.bookGroupAllId -> "${App.db.bookDao().allBookCount}" + AppConst.bookGroupLocalId -> "${App.db.bookDao().localBookCount}" + AppConst.bookGroupAudioId -> "${App.db.bookDao().audioBookCount}" + AppConst.bookGroupNoneId -> "${App.db.bookDao().noneBookCount}" + else -> "${App.db.bookDao().groupCount(group.groupId)}" + }}" } override fun getItemPosition(`object`: Any): Int { From 39676981d165717ddd6518166c50540cbe13750f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A3=E5=8F=A3=E5=90=95?= <156081428@qq.com> Date: Sat, 24 Oct 2020 23:42:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 39986674a..6749d06f7 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -45,7 +45,7 @@ interface BookDao { @get:Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups) & `group` = 0") val noGroupSize: Int - @Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups) & `group` = :groupId") + @Query("select count(bookUrl) from books where `group` = :groupId") fun groupCount(groupId: Long): Int @get:Query("SELECT count(*) FROM books where origin = '${BookType.local}'")