|
|
@ -1,20 +1,17 @@ |
|
|
|
package io.legado.app.ui.main.bookshelf |
|
|
|
package io.legado.app.ui.main.bookshelf |
|
|
|
|
|
|
|
|
|
|
|
import android.text.TextUtils.isEmpty |
|
|
|
|
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import androidx.paging.PagedListAdapter |
|
|
|
import androidx.paging.PagedListAdapter |
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import com.bumptech.glide.Glide |
|
|
|
|
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
import io.legado.app.lib.theme.ThemeStore |
|
|
|
import io.legado.app.lib.theme.ThemeStore |
|
|
|
import kotlinx.android.synthetic.main.item_bookshelf_list.view.* |
|
|
|
import kotlinx.android.synthetic.main.item_bookshelf_list.view.* |
|
|
|
import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name |
|
|
|
import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name |
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
|
|
|
|
|
|
|
@ -42,6 +39,7 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D |
|
|
|
holder.bind(it, callBack) |
|
|
|
holder.bind(it, callBack) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
@ -53,21 +51,12 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D |
|
|
|
tv_author.text = book.author |
|
|
|
tv_author.text = book.author |
|
|
|
tv_read.text = book.durChapterTitle |
|
|
|
tv_read.text = book.durChapterTitle |
|
|
|
tv_last.text = book.latestChapterTitle |
|
|
|
tv_last.text = book.latestChapterTitle |
|
|
|
val cover = if (isEmpty(book.customCoverUrl)) book.coverUrl else book.customCoverUrl |
|
|
|
book.getDisplayCover()?.let { |
|
|
|
cover?.let { |
|
|
|
ImageLoader.load(context, it)//Glide自动识别http://和file:// |
|
|
|
if (it.startsWith("http")) { |
|
|
|
|
|
|
|
Glide.with(itemView).load(it) |
|
|
|
|
|
|
|
.placeholder(R.drawable.img_cover_default) |
|
|
|
|
|
|
|
.centerCrop() |
|
|
|
|
|
|
|
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) |
|
|
|
|
|
|
|
.into(iv_cover) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Glide.with(itemView).load(File(it)) |
|
|
|
|
|
|
|
.placeholder(R.drawable.img_cover_default) |
|
|
|
.placeholder(R.drawable.img_cover_default) |
|
|
|
|
|
|
|
.error(R.drawable.img_cover_default) |
|
|
|
.centerCrop() |
|
|
|
.centerCrop() |
|
|
|
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) |
|
|
|
.setAsDrawable(iv_cover) |
|
|
|
.into(iv_cover) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
itemView.setOnClickListener { callBack?.open(book) } |
|
|
|
itemView.setOnClickListener { callBack?.open(book) } |
|
|
|
} |
|
|
|
} |
|
|
|