|
|
|
@ -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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|