Show available manga info on view load (closes #3367)

This commit is contained in:
arkon 2020-06-22 22:28:53 -04:00
parent 0258422527
commit d44503cb19

View File

@ -40,8 +40,8 @@ class MangaInfoHeaderAdapter(
) : ) :
RecyclerView.Adapter<MangaInfoHeaderAdapter.HeaderViewHolder>() { RecyclerView.Adapter<MangaInfoHeaderAdapter.HeaderViewHolder>() {
private var manga: Manga? = null private var manga: Manga = controller.presenter.manga
private var source: Source? = null private var source: Source = controller.presenter.source
private var numChapters: Int? = null private var numChapters: Int? = null
private val scope = CoroutineScope(Job() + Dispatchers.Main) private val scope = CoroutineScope(Job() + Dispatchers.Main)
@ -66,7 +66,7 @@ class MangaInfoHeaderAdapter(
* @param manga manga object containing information about manga. * @param manga manga object containing information about manga.
* @param source the source of the manga. * @param source the source of the manga.
*/ */
fun update(manga: Manga, source: Source?) { fun update(manga: Manga, source: Source) {
this.manga = manga this.manga = manga
this.source = source this.source = source
@ -81,10 +81,6 @@ class MangaInfoHeaderAdapter(
inner class HeaderViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { inner class HeaderViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
fun bind() { fun bind() {
if (manga == null) {
return
}
// For rounded corners // For rounded corners
binding.mangaCover.clipToOutline = true binding.mangaCover.clipToOutline = true
@ -177,7 +173,7 @@ class MangaInfoHeaderAdapter(
} }
.launchIn(scope) .launchIn(scope)
setMangaInfo(manga!!, source) setMangaInfo(manga, source)
setChapterInfo() setChapterInfo()
} }
@ -237,21 +233,17 @@ class MangaInfoHeaderAdapter(
setFavoriteButtonState(manga.favorite) setFavoriteButtonState(manga.favorite)
// Set cover if it wasn't already. // Set cover if it wasn't already.
if (binding.mangaCover.drawable == null) {
val mangaThumbnail = manga.toMangaThumbnail() val mangaThumbnail = manga.toMangaThumbnail()
listOf(binding.mangaCover, binding.backdrop)
GlideApp.with(view.context) .forEach {
.load(mangaThumbnail)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
.into(binding.mangaCover)
binding.backdrop?.let {
GlideApp.with(view.context) GlideApp.with(view.context)
.load(mangaThumbnail) .load(mangaThumbnail)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop() .centerCrop()
.into(it) .into(it)
} }
}
// Manga info section // Manga info section
if (manga.description.isNullOrBlank() && manga.genre.isNullOrBlank()) { if (manga.description.isNullOrBlank() && manga.genre.isNullOrBlank()) {