From bff404360745b63030ca180954c2b2ace2a6c598 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 28 Sep 2019 17:00:53 +0800 Subject: [PATCH] up --- .../io/legado/app/data/dao/BookGroupDao.kt | 13 ++++---- .../ui/main/bookshelf/BookshelfViewModel.kt | 30 +++++++++---------- .../ui/main/bookshelf/GroupManageDialog.kt | 2 +- app/src/main/res/menu/book_group_manage.xml | 27 +++++++++++++++++ 4 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/menu/book_group_manage.xml 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 51068b149..6162ffc5a 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 @@ -1,10 +1,7 @@ package io.legado.app.data.dao import androidx.lifecycle.LiveData -import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy -import androidx.room.Query +import androidx.room.* import io.legado.app.data.entities.BookGroup @Dao @@ -17,5 +14,11 @@ interface BookGroupDao { val maxId: Int @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insert(bookGroup: BookGroup) + fun insert(vararg bookGroup: BookGroup) + + @Update + fun update(vararg bookGroup: BookGroup) + + @Delete + fun delete(vararg bookGroup: BookGroup) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index a56a08871..f4664fa22 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -7,28 +7,28 @@ import io.legado.app.data.entities.BookGroup class BookshelfViewModel(application: Application) : BaseViewModel(application) { - fun saveBookGroup(group: String?) { - if (!group.isNullOrBlank()) { - execute { - App.db.bookGroupDao().insert( - BookGroup( - App.db.bookGroupDao().maxId + 1, - group - ) - ) - } - } - } fun addGroup(groupName: String) { - + execute { + val maxId = App.db.bookGroupDao().maxId + val bookGroup = BookGroup( + groupId = maxId.plus(1), + groupName = groupName, + order = maxId.plus(1) + ) + App.db.bookGroupDao().insert(bookGroup) + } } fun upGroup(bookGroup: BookGroup) { - + execute { + App.db.bookGroupDao().update(bookGroup) + } } fun delGroup(bookGroup: BookGroup) { - + execute { + App.db.bookGroupDao().delete(bookGroup) + } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt index d33a62476..7db85906e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt @@ -59,7 +59,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private fun initData() { tool_bar.title = getString(R.string.group_manage) - tool_bar.inflateMenu(R.menu.group_manage) + tool_bar.inflateMenu(R.menu.book_group_manage) tool_bar.menu.applyTint(requireContext(), false) tool_bar.setOnMenuItemClickListener(this) adapter = GroupAdapter(requireContext()) diff --git a/app/src/main/res/menu/book_group_manage.xml b/app/src/main/res/menu/book_group_manage.xml new file mode 100644 index 000000000..4c887905d --- /dev/null +++ b/app/src/main/res/menu/book_group_manage.xml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file