pull/32/head
kunfei 5 years ago
parent 42f019eb43
commit 634aa2f523
  1. 15
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  2. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt

@ -17,7 +17,8 @@ import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.sdk27.listeners.onLongClick
class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) { class BookshelfAdapter(private val callBack: CallBack) :
PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object { companion object {
@JvmField @JvmField
@ -34,8 +35,6 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
} }
} }
var callBack: CallBack? = null
fun notification(bookUrl: String) { fun notification(bookUrl: String) {
for (i in 0..itemCount) { for (i in 0..itemCount) {
getItem(i)?.let { getItem(i)?.let {
@ -66,7 +65,7 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
itemView.setBackgroundColor(ThemeStore.backgroundColor(itemView.context)) itemView.setBackgroundColor(ThemeStore.backgroundColor(itemView.context))
} }
fun bind(book: Book, callBack: CallBack?) = with(itemView) { fun bind(book: Book, callBack: CallBack) = with(itemView) {
this.setBackgroundColor(context.getCompatColor(R.color.background)) this.setBackgroundColor(context.getCompatColor(R.color.background))
tv_name.text = book.name tv_name.text = book.name
tv_author.text = book.author tv_author.text = book.author
@ -79,13 +78,12 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
.centerCrop() .centerCrop()
.setAsDrawable(iv_cover) .setAsDrawable(iv_cover)
} }
itemView.onClick { callBack?.open(book) } itemView.onClick { callBack.open(book) }
itemView.onLongClick { itemView.onLongClick {
callBack?.openBookInfo(book) callBack.openBookInfo(book)
true true
} }
callBack?.let { if (book.origin != BookType.local && callBack.isUpdate(book.bookUrl)) {
if (book.origin != BookType.local && it.isUpdate(book.bookUrl)) {
bv_unread.invisible() bv_unread.invisible()
rl_loading.show() rl_loading.show()
} else { } else {
@ -93,7 +91,6 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
bv_unread.setBadgeCount(book.getUnreadChapterNum()) bv_unread.setBadgeCount(book.getUnreadChapterNum())
bv_unread.setHighlight(book.lastCheckCount > 0) bv_unread.setHighlight(book.lastCheckCount > 0)
} }
} ?: rl_loading.hide()
} }
} }

@ -85,9 +85,8 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
LinearLayoutManager.VERTICAL LinearLayoutManager.VERTICAL
) )
) )
bookshelfAdapter = BookshelfAdapter() bookshelfAdapter = BookshelfAdapter(this)
rv_bookshelf.adapter = bookshelfAdapter rv_bookshelf.adapter = bookshelfAdapter
bookshelfAdapter.callBack = this
observeEvent<String>(Bus.UP_BOOK) { bookshelfAdapter.notification(it) } observeEvent<String>(Bus.UP_BOOK) { bookshelfAdapter.notification(it) }
} }

Loading…
Cancel
Save