分组支持更多数量

pull/416/head
gedoor 4 years ago
parent d357954635
commit a16ff33b4d
  1. 6
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 7
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  3. 2
      app/src/main/java/io/legado/app/data/entities/Book.kt
  4. 2
      app/src/main/java/io/legado/app/data/entities/BookGroup.kt
  5. 16
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  6. 8
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  7. 8
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  8. 10
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  9. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt
  10. 4
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  11. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  12. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  13. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
  14. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt

@ -22,7 +22,7 @@ interface BookDao {
fun observeLocalUri(): LiveData<List<String>>
@Query("SELECT * FROM books WHERE (`group` & :group) > 0")
fun observeByGroup(group: Int): LiveData<List<Book>>
fun observeByGroup(group: Long): LiveData<List<Book>>
@Query("select * from books where (SELECT sum(groupId) FROM book_groups) & `group` = 0")
fun observeNoGroup(): LiveData<List<Book>>
@ -34,7 +34,7 @@ interface BookDao {
fun liveDataSearch(key: String): LiveData<List<Book>>
@Query("SELECT * FROM books WHERE (`group` & :group) > 0")
fun getBooksByGroup(group: Int): List<Book>
fun getBooksByGroup(group: Long): List<Book>
@Query("SELECT * FROM books WHERE `name` in (:names)")
fun findByName(vararg names: String): List<Book>
@ -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<BookProgress>

@ -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<List<BookGroup>>
@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

@ -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(), // 最近一次更新书籍信息的时间

@ -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

@ -41,10 +41,10 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
private var groupLiveData: LiveData<List<BookGroup>>? = null
private var booksLiveData: LiveData<List<Book>>? = 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<ArrangeBookViewModel>(R.layout.activi
}
override fun onClickMainAction() {
selectGroup(0, groupRequestCode)
selectGroup(groupRequestCode, 0)
}
})
}
@ -149,7 +149,7 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(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<ArrangeBookViewModel>(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<ArrangeBookViewModel>(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<Book>()

@ -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<String> {
private fun getGroupList(groupId: Long): List<String> {
val groupNames = arrayListOf<String>()
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)
}
}

@ -43,13 +43,13 @@ class CacheActivity : VMBaseActivity<CacheViewModel>(R.layout.activity_download)
private var menu: Menu? = null
private var exportPosition = -1
private val groupList: ArrayList<BookGroup> = 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<CacheViewModel>(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<CacheViewModel>(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()
}
}

@ -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)
}
}

@ -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(

@ -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) {

@ -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<String>()
App.db.bookGroupDao().all.forEach {

@ -54,7 +54,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
private var bookGroupLiveData: LiveData<List<BookGroup>>? = null
private var noGroupLiveData: LiveData<Int>? = null
private val bookGroups = mutableListOf<BookGroup>()
private val fragmentMap = hashMapOf<Int, BooksFragment>()
private val fragmentMap = hashMapOf<Long, BooksFragment>()
private var showGroupNone = false
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {

@ -65,10 +65,10 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
fun checkGroup(groups: List<BookGroup>) {
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)

@ -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<List<Book>>? = 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()

Loading…
Cancel
Save