|
|
@ -1,12 +1,9 @@ |
|
|
|
package io.legado.app.ui.main.bookshelf |
|
|
|
package io.legado.app.ui.main.bookshelf |
|
|
|
|
|
|
|
|
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.content.Context |
|
|
|
import android.view.View |
|
|
|
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
|
|
|
import androidx.paging.PagedListAdapter |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
|
|
|
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
import io.legado.app.constant.BookType |
|
|
|
import io.legado.app.constant.BookType |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
import io.legado.app.help.ImageLoader |
|
|
@ -17,116 +14,66 @@ 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 BooksAdapter(private val callBack: CallBack) : |
|
|
|
class BooksAdapter(context: Context, private val callBack: CallBack) : |
|
|
|
PagedListAdapter<Book, BooksAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
SimpleRecyclerAdapter<Book>(context, R.layout.item_bookshelf_list) { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) = |
|
|
|
@JvmField |
|
|
|
with(holder.itemView) { |
|
|
|
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Book>() { |
|
|
|
|
|
|
|
override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean = |
|
|
|
|
|
|
|
oldItem.bookUrl == newItem.bookUrl |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean = |
|
|
|
|
|
|
|
oldItem.durChapterTitle == newItem.durChapterTitle |
|
|
|
|
|
|
|
&& oldItem.name == newItem.name |
|
|
|
|
|
|
|
&& oldItem.getDisplayCover() == newItem.getDisplayCover() |
|
|
|
|
|
|
|
&& oldItem.latestChapterTitle == newItem.latestChapterTitle |
|
|
|
|
|
|
|
&& oldItem.durChapterTitle == newItem.durChapterTitle |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun getChangePayload(oldItem: Book, newItem: Book): Any? { |
|
|
|
|
|
|
|
if (oldItem.bookUrl != newItem.bookUrl) { |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return super.getChangePayload(oldItem, newItem) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun notification(bookUrl: String) { |
|
|
|
|
|
|
|
for (i in 0 until itemCount) { |
|
|
|
|
|
|
|
getItem(i)?.let { |
|
|
|
|
|
|
|
if (it.bookUrl == bookUrl) { |
|
|
|
|
|
|
|
notifyItemChanged(i, 5) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { |
|
|
|
|
|
|
|
return MyViewHolder( |
|
|
|
|
|
|
|
LayoutInflater.from(parent.context) |
|
|
|
|
|
|
|
.inflate(R.layout.item_bookshelf_list, parent, false) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int, payloads: MutableList<Any>) { |
|
|
|
|
|
|
|
if (payloads.isEmpty()) { |
|
|
|
if (payloads.isEmpty()) { |
|
|
|
super.onBindViewHolder(holder, position, payloads) |
|
|
|
ATH.applyBackgroundTint(this) |
|
|
|
} else { |
|
|
|
tv_name.text = item.name |
|
|
|
currentList?.get(position)?.let { |
|
|
|
tv_author.text = item.author |
|
|
|
holder.bind(it, callBack, payloads[0]) |
|
|
|
tv_read.text = item.durChapterTitle |
|
|
|
} |
|
|
|
tv_last.text = item.latestChapterTitle |
|
|
|
} |
|
|
|
item.getDisplayCover()?.let { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
|
|
|
|
|
|
|
currentList?.get(position)?.let { |
|
|
|
|
|
|
|
holder.bind(it, callBack) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
|
|
|
ATH.applyBackgroundTint(itemView) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun bind(book: Book, callBack: CallBack) = with(itemView) { |
|
|
|
|
|
|
|
tv_name.text = book.name |
|
|
|
|
|
|
|
tv_author.text = book.author |
|
|
|
|
|
|
|
tv_read.text = book.durChapterTitle |
|
|
|
|
|
|
|
tv_last.text = book.latestChapterTitle |
|
|
|
|
|
|
|
book.getDisplayCover()?.let { |
|
|
|
|
|
|
|
ImageLoader.load(context, it)//Glide自动识别http://和file:// |
|
|
|
ImageLoader.load(context, it)//Glide自动识别http://和file:// |
|
|
|
.placeholder(R.drawable.image_cover_default) |
|
|
|
.placeholder(R.drawable.image_cover_default) |
|
|
|
.error(R.drawable.image_cover_default) |
|
|
|
.error(R.drawable.image_cover_default) |
|
|
|
.centerCrop() |
|
|
|
.centerCrop() |
|
|
|
.setAsDrawable(iv_cover) |
|
|
|
.setAsDrawable(iv_cover) |
|
|
|
} |
|
|
|
} |
|
|
|
itemView.onClick { callBack.open(book) } |
|
|
|
onClick { callBack.open(item) } |
|
|
|
itemView.onLongClick { |
|
|
|
onLongClick { |
|
|
|
callBack.openBookInfo(book) |
|
|
|
callBack.openBookInfo(item) |
|
|
|
true |
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
|
if (book.origin != BookType.local && callBack.isUpdate(book.bookUrl)) { |
|
|
|
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) { |
|
|
|
LogUtils.d(book.name, "loading") |
|
|
|
LogUtils.d(item.name, "loading") |
|
|
|
bv_unread.invisible() |
|
|
|
bv_unread.invisible() |
|
|
|
rl_loading.show() |
|
|
|
rl_loading.show() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LogUtils.d(book.name, "loadingHide") |
|
|
|
LogUtils.d(item.name, "loadingHide") |
|
|
|
rl_loading.hide() |
|
|
|
rl_loading.hide() |
|
|
|
bv_unread.setBadgeCount(book.getUnreadChapterNum()) |
|
|
|
bv_unread.setBadgeCount(item.getUnreadChapterNum()) |
|
|
|
bv_unread.setHighlight(book.lastCheckCount > 0) |
|
|
|
bv_unread.setHighlight(item.lastCheckCount > 0) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
when (payloads[0]) { |
|
|
|
fun bind(book: Book, callBack: CallBack, payload: Any) = with(itemView) { |
|
|
|
|
|
|
|
when (payload) { |
|
|
|
|
|
|
|
5 -> { |
|
|
|
5 -> { |
|
|
|
if (book.origin != BookType.local && callBack.isUpdate(book.bookUrl)) { |
|
|
|
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) { |
|
|
|
LogUtils.d(book.name, "loading") |
|
|
|
LogUtils.d(item.name, "loading") |
|
|
|
bv_unread.invisible() |
|
|
|
bv_unread.invisible() |
|
|
|
rl_loading.show() |
|
|
|
rl_loading.show() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LogUtils.d(book.name, "loadingHide") |
|
|
|
LogUtils.d(item.name, "loadingHide") |
|
|
|
rl_loading.hide() |
|
|
|
rl_loading.hide() |
|
|
|
bv_unread.setBadgeCount(book.getUnreadChapterNum()) |
|
|
|
bv_unread.setBadgeCount(item.getUnreadChapterNum()) |
|
|
|
bv_unread.setHighlight(book.lastCheckCount > 0) |
|
|
|
bv_unread.setHighlight(item.lastCheckCount > 0) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun notification(bookUrl: String) { |
|
|
|
|
|
|
|
for (i in 0 until itemCount) { |
|
|
|
|
|
|
|
getItem(i)?.let { |
|
|
|
|
|
|
|
if (it.bookUrl == bookUrl) { |
|
|
|
|
|
|
|
notifyItemChanged(i, 5) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|