pull/32/head
kunfei 5 years ago
parent cae1a5c0fa
commit 3a723b11b6
  1. 2
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 11
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  3. 1
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  4. 9
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -40,7 +40,7 @@ interface BookDao {
fun recentRead(): DataSource.Factory<Int, Book>
@Query("SELECT * FROM books ORDER BY durChapterTime DESC limit 0,10")
fun getRecentRead(): DataSource.Factory<Int, Book>
fun getRecentRead(): List<Book>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg book: Book)

@ -33,6 +33,17 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
var callBack: CallBack? = null
fun notification(bookUrl: String) {
for (i in 0..itemCount) {
getItem(i)?.let {
if (it.bookUrl == bookUrl) {
notifyItemChanged(i)
return
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookshelf_list, parent, false))
}

@ -85,6 +85,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
bookshelfAdapter = BookshelfAdapter()
rv_bookshelf.adapter = bookshelfAdapter
bookshelfAdapter.callBack = this
viewModel.adapterNotification.observe(viewLifecycleOwner, Observer { bookshelfAdapter.notification(it) })
}
private fun initBookGroupData() {

@ -1,6 +1,7 @@
package io.legado.app.ui.main.bookshelf
import android.app.Application
import androidx.lifecycle.MediatorLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.BookType
@ -11,7 +12,7 @@ import kotlinx.coroutines.Dispatchers.IO
class BookshelfViewModel(application: Application) : BaseViewModel(application) {
val updateList = arrayListOf<String>()
val adapterNotification = MediatorLiveData<String>()
fun saveBookGroup(group: String?) {
if (!group.isNullOrBlank()) {
@ -34,13 +35,17 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
val bookSource = App.db.bookSourceDao().getBookSource(book.origin)
bookSource?.let {
updateList.add(book.bookUrl)
adapterNotification.postValue(book.bookUrl)
WebBook(bookSource).getChapterList(book).onSuccess(IO) {
it?.let {
if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) {
App.db.bookChapterDao().insert(*it.toTypedArray())
}
}
}.onFinally { updateList.remove(book.bookUrl) }
}.onFinally {
updateList.remove(book.bookUrl)
adapterNotification.postValue(book.bookUrl)
}
}
}
}

Loading…
Cancel
Save