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