mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 04:29:18 +01:00
Fixes for setting custom cover
This commit is contained in:
parent
c49584d003
commit
a503d95bec
@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.data.image.coil
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.widget.ImageView
|
||||
import coil.Coil
|
||||
import coil.ImageLoader
|
||||
import coil.imageLoader
|
||||
import coil.memory.MemoryCache
|
||||
@ -23,30 +22,33 @@ class LibraryMangaImageTarget(
|
||||
|
||||
override fun onError(error: Drawable?) {
|
||||
super.onError(error)
|
||||
val file = coverCache.getCoverFile(manga)
|
||||
// if the file exists and the there was still an error then the file is corrupted
|
||||
if (file.exists()) {
|
||||
val options = BitmapFactory.Options()
|
||||
options.inJustDecodeBounds = true
|
||||
BitmapFactory.decodeFile(file.path, options)
|
||||
if (options.outWidth == -1 || options.outHeight == -1) {
|
||||
file.delete()
|
||||
view.context.imageLoader.memoryCache.remove(MemoryCache.Key(manga.key()))
|
||||
if (manga.favorite) {
|
||||
val file = coverCache.getCoverFile(manga)
|
||||
// if the file exists and the there was still an error then the file is corrupted
|
||||
if (file.exists()) {
|
||||
val options = BitmapFactory.Options()
|
||||
options.inJustDecodeBounds = true
|
||||
BitmapFactory.decodeFile(file.path, options)
|
||||
if (options.outWidth == -1 || options.outHeight == -1) {
|
||||
file.delete()
|
||||
view.context.imageLoader.memoryCache.remove(MemoryCache.Key(manga.key()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun ImageView.loadLibraryManga(
|
||||
inline fun ImageView.loadManga(
|
||||
manga: Manga,
|
||||
imageLoader: ImageLoader = Coil.imageLoader(context),
|
||||
imageLoader: ImageLoader = context.imageLoader,
|
||||
builder: ImageRequest.Builder.() -> Unit = {}
|
||||
): Disposable {
|
||||
val request = ImageRequest.Builder(context)
|
||||
.data(manga)
|
||||
.target(LibraryMangaImageTarget(this, manga))
|
||||
.apply(builder)
|
||||
.memoryCacheKey(manga.key())
|
||||
.build()
|
||||
return imageLoader.enqueue(request)
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import coil.clear
|
||||
import coil.size.Precision
|
||||
import coil.size.Scale
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadManga
|
||||
import eu.kanade.tachiyomi.databinding.MangaGridItemBinding
|
||||
import eu.kanade.tachiyomi.util.lang.highlightText
|
||||
|
||||
@ -95,7 +95,7 @@ class LibraryGridHolder(
|
||||
|
||||
private fun setCover(manga: Manga) {
|
||||
if ((adapter.recyclerView.context as? Activity)?.isDestroyed == true) return
|
||||
binding.coverThumbnail.loadLibraryManga(manga) {
|
||||
binding.coverThumbnail.loadManga(manga) {
|
||||
if (!fixedSize) {
|
||||
precision(Precision.INEXACT)
|
||||
scale(Scale.FIT)
|
||||
|
@ -5,7 +5,7 @@ import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import coil.clear
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadManga
|
||||
import eu.kanade.tachiyomi.databinding.MangaListItemBinding
|
||||
import eu.kanade.tachiyomi.util.lang.highlightText
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
@ -88,7 +88,7 @@ class LibraryListHolder(
|
||||
binding.coverThumbnail.clear()
|
||||
} else {
|
||||
item.manga.id ?: return
|
||||
binding.coverThumbnail.loadLibraryManga(item.manga)
|
||||
binding.coverThumbnail.loadManga(item.manga)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.image.coil.MangaFetcher
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadManga
|
||||
import eu.kanade.tachiyomi.databinding.EditMangaDialogBinding
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
@ -68,7 +69,7 @@ class EditMangaDialog : DialogController {
|
||||
}
|
||||
|
||||
fun onViewCreated() {
|
||||
binding.mangaCover.loadAny(manga)
|
||||
binding.mangaCover.loadManga(manga)
|
||||
val isLocal = manga.isLocal()
|
||||
|
||||
if (isLocal) {
|
||||
@ -152,6 +153,7 @@ class EditMangaDialog : DialogController {
|
||||
parameters(Parameters.Builder().set(MangaFetcher.realCover, true).build())
|
||||
}
|
||||
)
|
||||
customCoverUri = null
|
||||
willResetCover = true
|
||||
}
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ class MangaDetailsController :
|
||||
fun setPaletteColor() {
|
||||
val view = view ?: return
|
||||
|
||||
val request = ImageRequest.Builder(view.context).data(presenter.manga).allowHardware(false)
|
||||
val request = ImageRequest.Builder(view.context).data(presenter.manga).allowHardware(false).memoryCacheKey(presenter.manga.key())
|
||||
.target(
|
||||
onSuccess = { drawable ->
|
||||
val bitmap = (drawable as BitmapDrawable).bitmap
|
||||
|
@ -10,11 +10,11 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import coil.loadAny
|
||||
import coil.request.CachePolicy
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadManga
|
||||
import eu.kanade.tachiyomi.databinding.MangaHeaderItemBinding
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
@ -322,7 +322,7 @@ class MangaHeaderHolder(
|
||||
fun updateCover(manga: Manga) {
|
||||
if (!manga.initialized) return
|
||||
val drawable = adapter.controller.binding.mangaCoverFull.drawable
|
||||
binding.mangaCover.loadAny(
|
||||
binding.mangaCover.loadManga(
|
||||
manga,
|
||||
builder = {
|
||||
placeholder(drawable)
|
||||
@ -331,7 +331,7 @@ class MangaHeaderHolder(
|
||||
diskCachePolicy(CachePolicy.READ_ONLY)
|
||||
}
|
||||
)
|
||||
binding.backdrop.loadAny(
|
||||
binding.backdrop.loadManga(
|
||||
manga,
|
||||
builder = {
|
||||
placeholder(drawable)
|
||||
|
@ -3,9 +3,9 @@ package eu.kanade.tachiyomi.ui.migration
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.clear
|
||||
import coil.loadAny
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadManga
|
||||
import eu.kanade.tachiyomi.databinding.MangaListItemBinding
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
|
||||
@ -22,6 +22,6 @@ class MangaHolder(
|
||||
|
||||
// Update the cover.
|
||||
binding.coverThumbnail.clear()
|
||||
binding.coverThumbnail.loadAny(item.manga)
|
||||
binding.coverThumbnail.loadManga(item.manga)
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadManga
|
||||
import eu.kanade.tachiyomi.databinding.RecentMangaItemBinding
|
||||
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
||||
@ -138,7 +138,7 @@ class RecentMangaHolder(
|
||||
)
|
||||
}
|
||||
if ((itemView.context as? Activity)?.isDestroyed != true) {
|
||||
binding.coverThumbnail.loadLibraryManga(item.mch.manga)
|
||||
binding.coverThumbnail.loadManga(item.mch.manga)
|
||||
}
|
||||
if (!item.mch.manga.isLocal()) {
|
||||
notifyStatus(
|
||||
|
Loading…
Reference in New Issue
Block a user