From ea73c34f5d60d8e5741f80799337bcf27cf0c806 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 22:43:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../legado/app/ui/book/group/GroupManageDialog.kt | 5 ++++- .../app/ui/main/bookshelf/BookshelfFragment.kt | 13 +++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index a7d29d750..4f65a751c 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -31,6 +31,9 @@ interface BookGroupDao { @get:Query("SELECT * FROM book_groups ORDER BY `order`") val all: List + @Query("update book_groups set show = 1 where groupId = :groupId") + fun enableGroup(groupId: Long) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookGroup: BookGroup) diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 66fb7ebec..c39924f09 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -164,13 +164,16 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - return true + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + return oldItem.groupId == newItem.groupId } override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] return oldItem.groupName == newItem.groupName + && oldItem.show == newItem.show } } 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 1a0dfec74..33ac4ee78 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 @@ -12,6 +12,7 @@ import com.google.android.material.tabs.TabLayout import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment +import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup @@ -123,10 +124,14 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b @Synchronized private fun upGroup(data: List) { - bookGroups.clear() - bookGroups.addAll(data) - adapter.notifyDataSetChanged() - selectLastTab() + if (data.isEmpty()) { + App.db.bookGroupDao().enableGroup(AppConst.bookGroupAllId) + } else { + bookGroups.clear() + bookGroups.addAll(data) + adapter.notifyDataSetChanged() + selectLastTab() + } } @Synchronized