|
|
@ -1,12 +1,9 @@ |
|
|
|
package io.legado.app.ui.chapterlist |
|
|
|
package io.legado.app.ui.chapterlist |
|
|
|
|
|
|
|
|
|
|
|
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.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.help.BookHelp |
|
|
@ -15,46 +12,22 @@ import io.legado.app.utils.getCompatColor |
|
|
|
import kotlinx.android.synthetic.main.item_bookmark.view.* |
|
|
|
import kotlinx.android.synthetic.main.item_bookmark.view.* |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
|
|
|
|
|
|
|
class ChapterListAdapter(val callback: Callback) : |
|
|
|
class ChapterListAdapter(context: Context, val callback: Callback) : |
|
|
|
PagedListAdapter<BookChapter, ChapterListAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
SimpleRecyclerAdapter<BookChapter>(context, R.layout.item_chapter_list) { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
override fun convert(holder: ItemViewHolder, item: BookChapter, payloads: MutableList<Any>) { |
|
|
|
|
|
|
|
with(holder.itemView) { |
|
|
|
@JvmField |
|
|
|
if (callback.durChapterIndex() == item.index) { |
|
|
|
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<BookChapter>() { |
|
|
|
|
|
|
|
override fun areItemsTheSame(oldItem: BookChapter, newItem: BookChapter): Boolean = |
|
|
|
|
|
|
|
oldItem.bookUrl == newItem.bookUrl |
|
|
|
|
|
|
|
&& oldItem.url == newItem.url |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun areContentsTheSame(oldItem: BookChapter, newItem: BookChapter): Boolean = |
|
|
|
|
|
|
|
oldItem.title == newItem.title |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { |
|
|
|
|
|
|
|
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_chapter_list, parent, false)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
|
|
|
|
|
|
|
getItem(position)?.let { |
|
|
|
|
|
|
|
holder.bind(it, callback) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun bind(bookChapter: BookChapter, callback: Callback) = with(itemView) { |
|
|
|
|
|
|
|
if (callback.durChapterIndex() == bookChapter.index) { |
|
|
|
|
|
|
|
tv_chapter_name.setTextColor(context.accentColor) |
|
|
|
tv_chapter_name.setTextColor(context.accentColor) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
tv_chapter_name.setTextColor(context.getCompatColor(R.color.tv_text_default)) |
|
|
|
tv_chapter_name.setTextColor(context.getCompatColor(R.color.tv_text_default)) |
|
|
|
} |
|
|
|
} |
|
|
|
tv_chapter_name.text = bookChapter.title |
|
|
|
tv_chapter_name.text = item.title |
|
|
|
itemView.onClick { |
|
|
|
this.onClick { |
|
|
|
callback.openChapter(bookChapter) |
|
|
|
callback.openChapter(item) |
|
|
|
} |
|
|
|
} |
|
|
|
callback.book()?.let { |
|
|
|
callback.book()?.let { |
|
|
|
tv_chapter_name.paint.isFakeBoldText = BookHelp.hasContent(it, bookChapter) |
|
|
|
tv_chapter_name.paint.isFakeBoldText = BookHelp.hasContent(it, item) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|