From a16ff33b4d16c4b8c660877b2e739d98e3be6a41 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 4 Oct 2020 15:56:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=BB=84=E6=94=AF=E6=8C=81=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=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 | 6 +++--- .../java/io/legado/app/data/dao/BookGroupDao.kt | 7 +++++-- .../java/io/legado/app/data/entities/Book.kt | 2 +- .../io/legado/app/data/entities/BookGroup.kt | 2 +- .../app/ui/book/arrange/ArrangeBookActivity.kt | 16 ++++++++-------- .../app/ui/book/arrange/ArrangeBookAdapter.kt | 8 ++++---- .../io/legado/app/ui/book/cache/CacheActivity.kt | 8 ++++---- .../app/ui/book/group/GroupSelectDialog.kt | 10 +++++----- .../legado/app/ui/book/group/GroupViewModel.kt | 4 ++-- .../legado/app/ui/book/info/BookInfoActivity.kt | 4 ++-- .../legado/app/ui/book/info/BookInfoViewModel.kt | 2 +- .../app/ui/main/bookshelf/BookshelfFragment.kt | 2 +- .../app/ui/main/bookshelf/BookshelfViewModel.kt | 6 +++--- .../app/ui/main/bookshelf/books/BooksFragment.kt | 8 ++++---- 14 files changed, 44 insertions(+), 41 deletions(-) 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 9aaf5d3fe..a4ad1d736 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 @@ -22,7 +22,7 @@ interface BookDao { fun observeLocalUri(): LiveData> @Query("SELECT * FROM books WHERE (`group` & :group) > 0") - fun observeByGroup(group: Int): LiveData> + fun observeByGroup(group: Long): LiveData> @Query("select * from books where (SELECT sum(groupId) FROM book_groups) & `group` = 0") fun observeNoGroup(): LiveData> @@ -34,7 +34,7 @@ interface BookDao { fun liveDataSearch(key: String): LiveData> @Query("SELECT * FROM books WHERE (`group` & :group) > 0") - fun getBooksByGroup(group: Int): List + fun getBooksByGroup(group: Long): List @Query("SELECT * FROM books WHERE `name` in (:names)") fun findByName(vararg names: String): List @@ -82,7 +82,7 @@ interface BookDao { fun upProgress(bookUrl: String, pos: Int) @Query("update books set `group` = :newGroupId where `group` = :oldGroupId") - fun upGroup(oldGroupId: Int, newGroupId: Int) + fun upGroup(oldGroupId: Long, newGroupId: Long) @get:Query("select bookUrl, tocUrl, origin, originName, durChapterIndex, durChapterPos, durChapterTime, durChapterTitle from books") val allBookProgress: List 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 c262d60e1..5f56d623f 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 @@ -8,13 +8,16 @@ import io.legado.app.data.entities.BookGroup interface BookGroupDao { @Query("select * from book_groups where groupId = :id") - fun getByID(id: Int): BookGroup? + fun getByID(id: Long): BookGroup? + + @Query("select * from book_groups where groupName = :groupName") + fun getByName(groupName: String): BookGroup? @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> @get:Query("SELECT sum(groupId) FROM book_groups") - val idsSum: Int + val idsSum: Long @get:Query("SELECT MAX(`order`) FROM book_groups") val maxOrder: Int diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 62926b3b4..64748355a 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -39,7 +39,7 @@ data class Book( var customIntro: String? = null, // 简介内容(用户修改) var charset: String? = null, // 自定义字符集名称(仅适用于本地书籍) var type: Int = 0, // 0:text 1:audio - var group: Int = 0, // 自定义分组索引号 + var group: Long = 0, // 自定义分组索引号 var latestChapterTitle: String? = null, // 最新章节标题 var latestChapterTime: Long = System.currentTimeMillis(), // 最新章节标题更新时间 var lastCheckTime: Long = System.currentTimeMillis(), // 最近一次更新书籍信息的时间 diff --git a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt index 9cd74b331..2d2c68698 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt @@ -9,7 +9,7 @@ import kotlinx.android.parcel.Parcelize @Entity(tableName = "book_groups") data class BookGroup( @PrimaryKey - val groupId: Int = 0b1, + val groupId: Long = 0b1, var groupName: String, var order: Int = 0 ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index f23a2008c..76ac7c89a 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -41,10 +41,10 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi private var groupLiveData: LiveData>? = null private var booksLiveData: LiveData>? = null private var menu: Menu? = null - private var groupId: Int = -1 + private var groupId: Long = -1 override fun onActivityCreated(savedInstanceState: Bundle?) { - groupId = intent.getIntExtra("groupId", -1) + groupId = intent.getLongExtra("groupId", -1) title_bar.subtitle = intent.getStringExtra("groupName") ?: getString(R.string.all) initView() initGroupData() @@ -85,7 +85,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi } override fun onClickMainAction() { - selectGroup(0, groupRequestCode) + selectGroup(groupRequestCode, 0) } }) } @@ -149,7 +149,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi } else -> if (item.groupId == R.id.menu_group) { title_bar.subtitle = item.title - groupId = item.itemId + groupId = App.db.bookGroupDao().getByName(item.title.toString())?.groupId ?: 0 initBookData() } } @@ -167,7 +167,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi viewModel.upCanUpdate(adapter.selectedBooks(), true) R.id.menu_update_disable -> viewModel.upCanUpdate(adapter.selectedBooks(), false) - R.id.menu_add_to_group -> selectGroup(0, addToGroupRequestCode) + R.id.menu_add_to_group -> selectGroup(addToGroupRequestCode, 0) } return false } @@ -176,16 +176,16 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi menu?.findItem(R.id.menu_book_group)?.subMenu?.let { subMenu -> subMenu.removeGroup(R.id.menu_group) groupList.forEach { bookGroup -> - subMenu.add(R.id.menu_group, bookGroup.groupId, Menu.NONE, bookGroup.groupName) + subMenu.add(R.id.menu_group, bookGroup.order, Menu.NONE, bookGroup.groupName) } } } - override fun selectGroup(groupId: Int, requestCode: Int) { + override fun selectGroup(requestCode: Int, groupId: Long) { GroupSelectDialog.show(supportFragmentManager, groupId, requestCode) } - override fun upGroup(requestCode: Int, groupId: Int) { + override fun upGroup(requestCode: Int, groupId: Long) { when (requestCode) { groupRequestCode -> { val books = arrayListOf() diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index 84e070259..762e18d1d 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -101,13 +101,13 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : tv_group.onClick { getItem(holder.layoutPosition)?.let { actionItem = it - callBack.selectGroup(it.group, groupRequestCode) + callBack.selectGroup(groupRequestCode, it.group) } } } } - private fun getGroupList(groupId: Int): List { + private fun getGroupList(groupId: Long): List { val groupNames = arrayListOf() callBack.groupList.forEach { if (it.groupId and groupId > 0) { @@ -117,7 +117,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : return groupNames } - private fun getGroupName(groupId: Int): String { + private fun getGroupName(groupId: Long): String { val groupNames = getGroupList(groupId) if (groupNames.isEmpty()) { return "" @@ -159,6 +159,6 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : fun upSelectCount() fun updateBook(vararg book: Book) fun deleteBook(book: Book) - fun selectGroup(groupId: Int, requestCode: Int) + fun selectGroup(requestCode: Int, groupId: Long) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 6dbbf7589..0ae61f349 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -43,13 +43,13 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) private var menu: Menu? = null private var exportPosition = -1 private val groupList: ArrayList = arrayListOf() - private var groupId: Int = -1 + private var groupId: Long = -1 override val viewModel: CacheViewModel get() = getViewModel(CacheViewModel::class.java) override fun onActivityCreated(savedInstanceState: Bundle?) { - groupId = intent.getIntExtra("groupId", -1) + groupId = intent.getLongExtra("groupId", -1) title_bar.subtitle = intent.getStringExtra("groupName") ?: getString(R.string.all) initRecyclerView() initGroupData() @@ -71,7 +71,7 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) menu?.findItem(R.id.menu_book_group)?.subMenu?.let { subMenu -> subMenu.removeGroup(R.id.menu_group) groupList.forEach { bookGroup -> - subMenu.add(R.id.menu_group, bookGroup.groupId, Menu.NONE, bookGroup.groupName) + subMenu.add(R.id.menu_group, bookGroup.order, Menu.NONE, bookGroup.groupName) } } } @@ -107,7 +107,7 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) } else -> if (item.groupId == R.id.menu_group) { title_bar.subtitle = item.title - groupId = item.itemId + groupId = App.db.bookGroupDao().getByName(item.title.toString())?.groupId ?: 0 initBookData() } } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 91732b149..4cc5333b9 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -44,10 +44,10 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener companion object { const val tag = "groupSelectDialog" - fun show(manager: FragmentManager, groupId: Int, requestCode: Int = -1) { + fun show(manager: FragmentManager, groupId: Long, requestCode: Int = -1) { val fragment = GroupSelectDialog().apply { val bundle = Bundle() - bundle.putInt("groupId", groupId) + bundle.putLong("groupId", groupId) bundle.putInt("requestCode", requestCode) arguments = bundle } @@ -59,7 +59,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener private lateinit var viewModel: GroupViewModel private lateinit var adapter: GroupAdapter private var callBack: CallBack? = null - private var groupId = 0 + private var groupId: Long = 0 override fun onStart() { super.onStart() @@ -81,7 +81,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener tool_bar.setBackgroundColor(primaryColor) callBack = activity as? CallBack arguments?.let { - groupId = it.getInt("groupId") + groupId = it.getLong("groupId") requestCode = it.getInt("requestCode", -1) } initView() @@ -214,6 +214,6 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } interface CallBack { - fun upGroup(requestCode: Int, groupId: Int) + fun upGroup(requestCode: Int, groupId: Long) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt index 23555015f..2b55c6932 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt @@ -9,9 +9,9 @@ class GroupViewModel(application: Application) : BaseViewModel(application) { fun addGroup(groupName: String) { execute { - var id = 1 + var id = 1L val idsSum = App.db.bookGroupDao().idsSum - while (id and idsSum != 0) { + while (id and idsSum != 0L) { id = id.shl(1) } val bookGroup = BookGroup( diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 011def56a..18d9c06f7 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -182,7 +182,7 @@ class BookInfoActivity : } } - private fun upGroup(groupId: Int) { + private fun upGroup(groupId: Long) { viewModel.loadGroup(groupId) { if (it.isNullOrEmpty()) { tv_group.text = getString(R.string.group_s, getString(R.string.no_group)) @@ -350,7 +350,7 @@ class BookInfoActivity : return viewModel.durChapterIndex } - override fun upGroup(requestCode: Int, groupId: Int) { + override fun upGroup(requestCode: Int, groupId: Long) { upGroup(groupId) viewModel.bookData.value?.group = groupId if (viewModel.inBookshelf) { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index fb2a16bf8..aa3c12557 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -117,7 +117,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } } - fun loadGroup(groupId: Int, success: ((groupNames: String?) -> Unit)) { + fun loadGroup(groupId: Long, success: ((groupNames: String?) -> Unit)) { execute { val groupNames = arrayListOf() App.db.bookGroupDao().all.forEach { 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 542f5a13f..af82c14f1 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 @@ -54,7 +54,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b private var bookGroupLiveData: LiveData>? = null private var noGroupLiveData: LiveData? = null private val bookGroups = mutableListOf() - private val fragmentMap = hashMapOf() + private val fragmentMap = hashMapOf() private var showGroupNone = false override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { 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 ae1287842..298b84cca 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 @@ -65,10 +65,10 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun checkGroup(groups: List) { execute { groups.forEach { group -> - if (group.groupId and (group.groupId - 1) != 0) { - var id = 1 + if (group.groupId and (group.groupId - 1) != 0L) { + var id = 1L val idsSum = App.db.bookGroupDao().idsSum - while (id and idsSum != 0) { + while (id and idsSum != 0L) { id = id.shl(1) } App.db.bookGroupDao().delete(group) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index ebbe310e8..644f7683d 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -35,11 +35,11 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), BaseBooksAdapter.CallBack { companion object { - fun newInstance(position: Int, groupId: Int): BooksFragment { + fun newInstance(position: Int, groupId: Long): BooksFragment { return BooksFragment().apply { val bundle = Bundle() bundle.putInt("position", position) - bundle.putInt("groupId", groupId) + bundle.putLong("groupId", groupId) arguments = bundle } } @@ -50,12 +50,12 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), private lateinit var booksAdapter: BaseBooksAdapter private var bookshelfLiveData: LiveData>? = null private var position = 0 - private var groupId = -1 + private var groupId = -1L override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { arguments?.let { position = it.getInt("position", 0) - groupId = it.getInt("groupId", -1) + groupId = it.getLong("groupId", -1) } initRecyclerView() upRecyclerData()