diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt index 4f5a271c2..4c2dd9d6e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.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(DIFF_CALLBACK) { +class BookshelfAdapter(private val callBack: CallBack) : + PagedListAdapter(DIFF_CALLBACK) { companion object { @JvmField @@ -34,8 +35,6 @@ class BookshelfAdapter : PagedListAdapter(D } } - var callBack: CallBack? = null - fun notification(bookUrl: String) { for (i in 0..itemCount) { getItem(i)?.let { @@ -66,7 +65,7 @@ class BookshelfAdapter : PagedListAdapter(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(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) + } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 415a7cafe..77a91e0a6 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -85,9 +85,8 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b LinearLayoutManager.VERTICAL ) ) - bookshelfAdapter = BookshelfAdapter() + bookshelfAdapter = BookshelfAdapter(this) rv_bookshelf.adapter = bookshelfAdapter - bookshelfAdapter.callBack = this observeEvent(Bus.UP_BOOK) { bookshelfAdapter.notification(it) } }