pull/51/head
kunfei 5 years ago
parent c9ae7978df
commit 98eacc26d2
  1. 1
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  2. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapter.kt
  3. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt
  4. 14
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt
  5. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksViewModel.kt

@ -3,6 +3,7 @@ package io.legado.app.ui.main.bookshelf
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import io.legado.app.data.entities.BookGroup
import io.legado.app.ui.main.bookshelf.books.BooksFragment
class BookshelfAdapter(fragment: Fragment, val callBack: CallBack) :

@ -1,4 +1,4 @@
package io.legado.app.ui.main.bookshelf
package io.legado.app.ui.main.bookshelf.books
import android.content.Context
import io.legado.app.R
@ -16,7 +16,6 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick
class BooksAdapter(context: Context, private val callBack: CallBack) :
SimpleRecyclerAdapter<Book>(context, R.layout.item_bookshelf_list) {
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) {
with(holder.itemView) {
if (payloads.isEmpty()) {

@ -1,4 +1,4 @@
package io.legado.app.ui.main.bookshelf
package io.legado.app.ui.main.bookshelf.books
import androidx.recyclerview.widget.DiffUtil
import io.legado.app.data.entities.Book

@ -1,4 +1,4 @@
package io.legado.app.ui.main.bookshelf
package io.legado.app.ui.main.bookshelf.books
import android.os.Bundle
import android.view.View
@ -75,7 +75,10 @@ class BooksFragment : VMBaseFragment<BooksViewModel>(R.layout.fragment_books),
this.setDrawable(it)
}
})
booksAdapter = BooksAdapter(requireContext(), this)
booksAdapter = BooksAdapter(
requireContext(),
this
)
rv_bookshelf.adapter = booksAdapter
}
@ -89,7 +92,12 @@ class BooksFragment : VMBaseFragment<BooksViewModel>(R.layout.fragment_books),
}
bookshelfLiveData?.observe(this, Observer {
val diffResult =
DiffUtil.calculateDiff(BooksDiffCallBack(booksAdapter.getItems(), it))
DiffUtil.calculateDiff(
BooksDiffCallBack(
booksAdapter.getItems(),
it
)
)
booksAdapter.setItems(it, false)
diffResult.dispatchUpdatesTo(booksAdapter)
})

@ -1,4 +1,4 @@
package io.legado.app.ui.main.bookshelf
package io.legado.app.ui.main.bookshelf.books
import android.app.Application
import io.legado.app.base.BaseViewModel
Loading…
Cancel
Save