pull/94/head
kunfei 5 years ago
parent fdf32fd559
commit a845fe192f
  1. 5
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  2. 5
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  3. 34
      app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt
  4. 11
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  5. 25
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -27,7 +27,6 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
import io.legado.app.ui.main.bookshelf.BookshelfViewModel
import io.legado.app.utils.applyTint
import io.legado.app.utils.getVerticalDivider
import io.legado.app.utils.getViewModel
@ -38,7 +37,7 @@ import kotlinx.android.synthetic.main.item_group_manage.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: BookshelfViewModel
private lateinit var viewModel: GroupViewModel
private lateinit var adapter: GroupAdapter
private var callBack: CallBack? = null
@ -54,7 +53,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
viewModel = getViewModel(BookshelfViewModel::class.java)
viewModel = getViewModel(GroupViewModel::class.java)
return inflater.inflate(R.layout.dialog_recycler_view, container)
}

@ -26,7 +26,6 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
import io.legado.app.ui.main.bookshelf.BookshelfViewModel
import io.legado.app.utils.applyTint
import io.legado.app.utils.getVerticalDivider
import io.legado.app.utils.getViewModel
@ -52,7 +51,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
}
private var requestCode: Int = -1
private lateinit var viewModel: BookshelfViewModel
private lateinit var viewModel: GroupViewModel
private lateinit var adapter: GroupAdapter
private var callBack: CallBack? = null
@ -68,7 +67,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
viewModel = getViewModel(BookshelfViewModel::class.java)
viewModel = getViewModel(GroupViewModel::class.java)
return inflater.inflate(R.layout.dialog_recycler_view, container)
}

@ -0,0 +1,34 @@
package io.legado.app.ui.book.group
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.BookGroup
class GroupViewModel(application: Application) : BaseViewModel(application) {
fun addGroup(groupName: String) {
execute {
val bookGroup = BookGroup(
groupId = App.db.bookGroupDao().maxId.plus(1),
groupName = groupName,
order = App.db.bookGroupDao().maxOrder.plus(1)
)
App.db.bookGroupDao().insert(bookGroup)
}
}
fun upGroup(vararg bookGroup: BookGroup) {
execute {
App.db.bookGroupDao().update(*bookGroup)
}
}
fun delGroup(vararg bookGroup: BookGroup) {
execute {
App.db.bookGroupDao().delete(*bookGroup)
}
}
}

@ -9,12 +9,23 @@ import io.legado.app.ui.main.bookshelf.books.BooksFragment
class BookshelfAdapter(fragment: Fragment, val callBack: CallBack) :
FragmentStateAdapter(fragment) {
private val ids = hashSetOf<Long>()
override fun getItemCount(): Int {
return callBack.groupSize
}
override fun getItemId(position: Int): Long {
return callBack.getGroup(position).groupId.toLong()
}
override fun containsItem(itemId: Long): Boolean {
return ids.contains(itemId)
}
override fun createFragment(position: Int): Fragment {
val groupId = callBack.getGroup(position).groupId
ids.add(groupId.toLong())
return BooksFragment.newInstance(position, groupId)
}

@ -5,7 +5,6 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup
import io.legado.app.data.entities.BookSource
import io.legado.app.model.WebBook
import io.legado.app.utils.NetworkUtils
@ -13,30 +12,6 @@ import kotlinx.coroutines.Dispatchers.IO
class BookshelfViewModel(application: Application) : BaseViewModel(application) {
fun addGroup(groupName: String) {
execute {
val bookGroup = BookGroup(
groupId = App.db.bookGroupDao().maxId.plus(1),
groupName = groupName,
order = App.db.bookGroupDao().maxOrder.plus(1)
)
App.db.bookGroupDao().insert(bookGroup)
}
}
fun upGroup(vararg bookGroup: BookGroup) {
execute {
App.db.bookGroupDao().update(*bookGroup)
}
}
fun delGroup(vararg bookGroup: BookGroup) {
execute {
App.db.bookGroupDao().delete(*bookGroup)
}
}
fun addBookByUrl(bookUrls: String) {
var successCount = 0
execute {

Loading…
Cancel
Save