pull/32/head
kunfei 5 years ago
parent 42f019eb43
commit 634aa2f523
  1. 29
      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.onLongClick
class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) {
class BookshelfAdapter(private val callBack: CallBack) :
PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object {
@JvmField
@ -34,8 +35,6 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
}
}
var callBack: CallBack? = null
fun notification(bookUrl: String) {
for (i in 0..itemCount) {
getItem(i)?.let {
@ -66,7 +65,7 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
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))
tv_name.text = book.name
tv_author.text = book.author
@ -79,21 +78,19 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
.centerCrop()
.setAsDrawable(iv_cover)
}
itemView.onClick { callBack?.open(book) }
itemView.onClick { callBack.open(book) }
itemView.onLongClick {
callBack?.openBookInfo(book)
callBack.openBookInfo(book)
true
}
callBack?.let {
if (book.origin != BookType.local && it.isUpdate(book.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(book.getUnreadChapterNum())
bv_unread.setHighlight(book.lastCheckCount > 0)
}
} ?: rl_loading.hide()
if (book.origin != BookType.local && callBack.isUpdate(book.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(book.getUnreadChapterNum())
bv_unread.setHighlight(book.lastCheckCount > 0)
}
}
}

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

Loading…
Cancel
Save