pull/32/head
kunfei 5 years ago
parent 3a723b11b6
commit 2ef7058191
  1. 2
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  3. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -2,5 +2,5 @@ package io.legado.app.constant
object Bus { object Bus {
const val RECREATE = "RECREATE" const val RECREATE = "RECREATE"
const val SOURCE_DEBUG_LOG = "sourceDebugLog" const val UP_BOOK = "sourceDebugLog"
} }

@ -15,6 +15,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.Bus
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
@ -27,10 +28,7 @@ import io.legado.app.ui.bookinfo.BookInfoActivity
import io.legado.app.ui.bookshelf.BookshelfActivity import io.legado.app.ui.bookshelf.BookshelfActivity
import io.legado.app.ui.read.ReadActivity import io.legado.app.ui.read.ReadActivity
import io.legado.app.ui.search.SearchActivity import io.legado.app.ui.search.SearchActivity
import io.legado.app.utils.applyTint import io.legado.app.utils.*
import io.legado.app.utils.getViewModel
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.startActivity
import kotlinx.android.synthetic.main.dialog_edittext.view.* import kotlinx.android.synthetic.main.dialog_edittext.view.*
import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
@ -85,7 +83,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
bookshelfAdapter = BookshelfAdapter() bookshelfAdapter = BookshelfAdapter()
rv_bookshelf.adapter = bookshelfAdapter rv_bookshelf.adapter = bookshelfAdapter
bookshelfAdapter.callBack = this bookshelfAdapter.callBack = this
viewModel.adapterNotification.observe(viewLifecycleOwner, Observer { bookshelfAdapter.notification(it) }) observeEvent<String>(Bus.UP_BOOK) { bookshelfAdapter.notification(it) }
} }
private fun initBookGroupData() { private fun initBookGroupData() {

@ -1,18 +1,18 @@
package io.legado.app.ui.main.bookshelf package io.legado.app.ui.main.bookshelf
import android.app.Application import android.app.Application
import androidx.lifecycle.MediatorLiveData
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.constant.Bus
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
class BookshelfViewModel(application: Application) : BaseViewModel(application) { class BookshelfViewModel(application: Application) : BaseViewModel(application) {
val updateList = arrayListOf<String>() val updateList = arrayListOf<String>()
val adapterNotification = MediatorLiveData<String>()
fun saveBookGroup(group: String?) { fun saveBookGroup(group: String?) {
if (!group.isNullOrBlank()) { if (!group.isNullOrBlank()) {
@ -35,7 +35,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
val bookSource = App.db.bookSourceDao().getBookSource(book.origin) val bookSource = App.db.bookSourceDao().getBookSource(book.origin)
bookSource?.let { bookSource?.let {
updateList.add(book.bookUrl) updateList.add(book.bookUrl)
adapterNotification.postValue(book.bookUrl) postEvent(Bus.UP_BOOK, book.bookUrl)
WebBook(bookSource).getChapterList(book).onSuccess(IO) { WebBook(bookSource).getChapterList(book).onSuccess(IO) {
it?.let { it?.let {
if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) { if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) {
@ -44,7 +44,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
} }
}.onFinally { }.onFinally {
updateList.remove(book.bookUrl) updateList.remove(book.bookUrl)
adapterNotification.postValue(book.bookUrl) postEvent(Bus.UP_BOOK, book.bookUrl)
} }
} }
} }

Loading…
Cancel
Save