From 5393ba35d42c376e65fffb95e8ff0301686a0b59 Mon Sep 17 00:00:00 2001 From: Carlos <2092019+CarlosEsco@users.noreply.github.com> Date: Fri, 15 Jan 2021 11:31:50 -0500 Subject: [PATCH] update coil and fix inconsistent color generation on manga info --- .../kanade/tachiyomi/data/cache/CoverCache.kt | 8 +- .../data/image/coil/ByteArrayFetcher.kt | 2 +- .../data/image/coil/CoverViewTarget.kt | 6 +- .../image/coil/LibraryMangaImageTarget.kt | 17 ++-- .../tachiyomi/data/image/coil/MangaFetcher.kt | 2 +- .../data/library/LibraryUpdateNotifier.kt | 14 ++-- .../data/library/LibraryUpdateService.kt | 6 +- .../tachiyomi/ui/library/LibraryGridHolder.kt | 2 +- .../tachiyomi/ui/library/LibraryListHolder.kt | 2 +- .../tachiyomi/ui/manga/MangaDetailsAdapter.kt | 2 + .../ui/manga/MangaDetailsController.kt | 79 ++++++++----------- .../ui/manga/MangaDetailsPresenter.kt | 7 +- .../tachiyomi/ui/manga/MangaHeaderHolder.kt | 46 +++++++---- .../ui/manga/merge/MergeSearchAdapter.kt | 4 +- .../ui/manga/track/TrackSearchAdapter.kt | 4 +- .../tachiyomi/ui/reader/SaveImageNotifier.kt | 6 +- .../ui/reader/viewer/pager/PagerPageHolder.kt | 13 +-- .../viewer/webtoon/WebtoonPageHolder.kt | 4 +- .../ui/recent_updates/RecentChapterHolder.kt | 2 +- .../ui/recently_read/RecentlyReadHolder.kt | 2 +- .../source/browse/BrowseSourceGridHolder.kt | 10 +-- .../source/browse/BrowseSourceListHolder.kt | 10 +-- 22 files changed, 132 insertions(+), 116 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt index 8447be96fe..3e0cefad39 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.cache import android.content.Context import android.text.format.Formatter import coil.Coil +import coil.memory.MemoryCache import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga @@ -165,7 +166,7 @@ class CoverCache(val context: Context) { fun setCustomCoverToCache(manga: Manga, inputStream: InputStream) { getCustomCoverFile(manga).outputStream().use { inputStream.copyTo(it) - Coil.imageLoader(context).invalidate(manga.key()) + Coil.imageLoader(context).memoryCache.remove(MemoryCache.Key(manga.key())) } } @@ -179,7 +180,7 @@ class CoverCache(val context: Context) { val result = getCustomCoverFile(manga).let { it.exists() && it.delete() } - Coil.imageLoader(context).invalidate(manga.key()) + Coil.imageLoader(context).memoryCache.remove(MemoryCache.Key(manga.key())) return result } @@ -204,7 +205,8 @@ class CoverCache(val context: Context) { fun deleteFromCache(name: String?) { if (name.isNullOrEmpty()) return val file = getCoverFile(MangaImpl().apply { thumbnail_url = name }) - Coil.imageLoader(context).invalidate(file.name) + Coil.imageLoader(context).memoryCache.remove(MemoryCache.Key(file.name)) + if (file.exists()) file.delete() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/ByteArrayFetcher.kt b/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/ByteArrayFetcher.kt index b30de27c47..b6beb02d0b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/ByteArrayFetcher.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/ByteArrayFetcher.kt @@ -1,6 +1,6 @@ package eu.kanade.tachiyomi.data.image.coil -import coil.bitmappool.BitmapPool +import coil.bitmap.BitmapPool import coil.decode.DataSource import coil.decode.Options import coil.fetch.FetchResult diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/CoverViewTarget.kt b/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/CoverViewTarget.kt index 57263a7954..1cf03cb99e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/CoverViewTarget.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/CoverViewTarget.kt @@ -5,7 +5,7 @@ import android.view.View import android.widget.ImageView import coil.Coil import coil.request.CachePolicy -import coil.request.LoadRequest +import coil.request.ImageRequest import coil.target.ImageViewTarget import com.mikepenz.iconics.typeface.library.materialdesigndx.MaterialDesignDx import eu.kanade.tachiyomi.util.system.iconicsDrawableLarge @@ -25,9 +25,9 @@ class CoverViewTarget( view.scaleType = ImageView.ScaleType.CENTER view.setImageDrawable(view.context.iconicsDrawableLarge(MaterialDesignDx.Icon.gmf_broken_image, color = android.R.attr.textColorSecondary)) } else { - val request = LoadRequest.Builder(view.context).data(errorUrl).memoryCachePolicy(CachePolicy.ENABLED) + val request = ImageRequest.Builder(view.context).data(errorUrl).memoryCachePolicy(CachePolicy.ENABLED) .target(CoverViewTarget(view, progress)).build() - Coil.imageLoader(view.context).execute(request) + Coil.imageLoader(view.context).enqueue(request) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/LibraryMangaImageTarget.kt b/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/LibraryMangaImageTarget.kt index e364546acb..9f81fcdbd3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/LibraryMangaImageTarget.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/LibraryMangaImageTarget.kt @@ -5,9 +5,9 @@ import android.graphics.drawable.Drawable import android.widget.ImageView import coil.Coil import coil.ImageLoader -import coil.request.LoadRequest -import coil.request.LoadRequestBuilder -import coil.request.RequestDisposable +import coil.memory.MemoryCache +import coil.request.Disposable +import coil.request.ImageRequest import coil.target.ImageViewTarget import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.models.Manga @@ -30,7 +30,8 @@ class LibraryMangaImageTarget( BitmapFactory.decodeFile(file.path, options) if (options.outWidth == -1 || options.outHeight == -1) { file.delete() - Coil.imageLoader(view.context).invalidate(manga.key()) + + Coil.imageLoader(view.context).memoryCache.remove(MemoryCache.Key(manga.key())) } } } @@ -40,12 +41,12 @@ class LibraryMangaImageTarget( inline fun ImageView.loadLibraryManga( manga: Manga, imageLoader: ImageLoader = Coil.imageLoader(context), - builder: LoadRequestBuilder.() -> Unit = {} -): RequestDisposable { - val request = LoadRequest.Builder(context) + builder: ImageRequest.Builder.() -> Unit = {} +): Disposable { + val request = ImageRequest.Builder(context) .data(manga) .target(LibraryMangaImageTarget(this, manga)) .apply(builder) .build() - return imageLoader.execute(request) + return imageLoader.enqueue(request) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/MangaFetcher.kt b/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/MangaFetcher.kt index 76a606949f..a2f1a11a08 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/MangaFetcher.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/image/coil/MangaFetcher.kt @@ -1,7 +1,7 @@ package eu.kanade.tachiyomi.data.image.coil import android.webkit.MimeTypeMap -import coil.bitmappool.BitmapPool +import coil.bitmap.BitmapPool import coil.decode.DataSource import coil.decode.Options import coil.fetch.FetchResult diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt index feaaa1cfd7..d34c07b8b1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt @@ -12,7 +12,7 @@ import androidx.core.app.NotificationManagerCompat import androidx.core.content.ContextCompat import coil.Coil import coil.request.CachePolicy -import coil.request.GetRequest +import coil.request.ImageRequest import coil.transform.CircleCropTransformation import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter @@ -136,22 +136,24 @@ class LibraryUpdateNotifier(private val context: Context) { context.notification(Notifications.CHANNEL_NEW_CHAPTERS) { setSmallIcon(R.drawable.ic_neko_notification) try { - val request = GetRequest.Builder(context).data(manga) + val request = ImageRequest.Builder(context).data(manga) .networkCachePolicy(CachePolicy.DISABLED) .transformations(CircleCropTransformation()).size(width = ICON_SIZE, height = ICON_SIZE) .build() Coil.imageLoader(context) .execute(request).drawable?.let { drawable -> - setLargeIcon((drawable as BitmapDrawable).bitmap) - } + setLargeIcon((drawable as BitmapDrawable).bitmap) + } } catch (e: Exception) { } setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY) setContentTitle(manga.title) color = ContextCompat.getColor(context, R.color.colorAccent) val chaptersNames = if (chapterNames.size > MAX_CHAPTERS) { - "${chapterNames.take(MAX_CHAPTERS - 1) - .joinToString(", ")}, " + context.resources.getQuantityString( + "${ + chapterNames.take(MAX_CHAPTERS - 1) + .joinToString(", ") + }, " + context.resources.getQuantityString( R.plurals.notification_and_n_more, (chapterNames.size - (MAX_CHAPTERS - 1)), (chapterNames.size - (MAX_CHAPTERS - 1)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 468db05763..bd41eec1c0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -9,7 +9,7 @@ import android.os.PowerManager import android.widget.Toast import coil.Coil import coil.request.CachePolicy -import coil.request.LoadRequest +import coil.request.ImageRequest import com.elvishew.xlog.XLog import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache @@ -397,9 +397,9 @@ class LibraryUpdateService( coverCache.deleteFromCache(thumbnailUrl) // load new covers in background val request = - LoadRequest.Builder(this@LibraryUpdateService).data(manga) + ImageRequest.Builder(this@LibraryUpdateService).data(manga) .memoryCachePolicy(CachePolicy.DISABLED).build() - Coil.imageLoader(this@LibraryUpdateService).execute(request) + Coil.imageLoader(this@LibraryUpdateService).enqueue(request) } db.insertManga(manga).executeAsBlocking() // add mdlist tracker if manga in library has it missing diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index b41a6c1ddf..cc98a9a921 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -4,7 +4,7 @@ import android.app.Activity import android.view.Gravity import android.view.View import android.widget.FrameLayout -import coil.api.clear +import coil.clear import coil.size.Precision import coil.size.Scale import eu.kanade.tachiyomi.data.database.models.Manga diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 3c350acd98..f08dac9ea5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.library import android.view.View import android.view.ViewGroup -import coil.api.clear +import coil.clear import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga import eu.kanade.tachiyomi.util.system.dpToPx diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt index d9c5823108..8413475618 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.manga +import android.graphics.Bitmap import android.view.View import androidx.recyclerview.widget.ItemTouchHelper import eu.davidea.flexibleadapter.items.IFlexible @@ -132,5 +133,6 @@ class MangaDetailsAdapter( fun updateScroll() fun setFavButtonPopup(popupView: View) fun showExternalSheet() + fun generatePalette(input: Bitmap) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index 82d1f7a674..09b0b8e76b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -41,10 +41,7 @@ import androidx.transition.ChangeImageTransform import androidx.transition.TransitionManager import androidx.transition.TransitionSet import coil.Coil -import coil.bitmappool.BitmapPool -import coil.request.LoadRequest -import coil.size.Size -import coil.transform.Transformation +import coil.request.ImageRequest import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.checkbox.checkBoxPrompt import com.afollestad.materialdialogs.checkbox.isCheckPromptChecked @@ -111,6 +108,9 @@ import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.manga_details_controller.* import kotlinx.android.synthetic.main.manga_grid_item.* import kotlinx.android.synthetic.main.manga_header_item.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.launch import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.File @@ -155,7 +155,6 @@ class MangaDetailsController : var colorAnimator: ValueAnimator? = null val presenter: MangaDetailsPresenter - var coverColor: Int? = null var toolbarIsColored = false private var snack: Snackbar? = null val fromCatalogue = args.getBoolean(FROM_CATALOGUE_EXTRA, false) @@ -188,11 +187,9 @@ class MangaDetailsController : //region UI Methods override fun onViewCreated(view: View) { super.onViewCreated(view) - coverColor = null fullCoverActive = false setRecycler(view) - setPaletteColor() adapter?.fastScroller = fast_scroller fast_scroller.addOnScrollStateChangeListener { activity?.appbar?.y = 0f @@ -285,7 +282,7 @@ class MangaDetailsController : return } val color = - coverColor ?: activity!!.getResourceColor(R.attr.colorPrimaryVariant) + presenter.coverColor ?: activity!!.getResourceColor(R.attr.colorPrimaryVariant) val colorFrom = if (colorAnimator?.isRunning == true) activity?.window?.statusBarColor ?: color @@ -312,37 +309,6 @@ class MangaDetailsController : } } - /** Get the color of the manga cover*/ - fun setPaletteColor() { - val view = view ?: return - - val request = LoadRequest.Builder(view.context).data(presenter.manga).allowHardware(false) - .transformations(object : Transformation { - override fun key() = "BackDropColorTransformer" - - override suspend fun transform(pool: BitmapPool, input: Bitmap, size: Size): Bitmap { - val p = Palette.from(input).generate() - if (recycler != null) { - val colorBack = view.context.getResourceColor( - android.R.attr.colorBackground - ) - // this makes the color more consistent regardless of theme - val backDropColor = - ColorUtils.blendARGB(p.getVibrantColor(colorBack), colorBack, .35f) - coverColor = backDropColor - getHeader()?.setBackDrop(backDropColor) - if (toolbarIsColored) { - val translucentColor = ColorUtils.setAlphaComponent(backDropColor, 175) - (activity as MainActivity).toolbar.setBackgroundColor(translucentColor) - activity?.window?.statusBarColor = translucentColor - } - } - return input - } - }).target(manga_cover_full).build() - Coil.imageLoader(view.context).execute(request) - } - /** Set toolbar theme for themes that are inverted (ie. light blue theme) */ private fun setActionBar(forThis: Boolean) { val activity = activity ?: return @@ -378,7 +344,7 @@ class MangaDetailsController : private fun setStatusBarAndToolbar() { activity?.window?.statusBarColor = if (toolbarIsColored) { - val translucentColor = ColorUtils.setAlphaComponent(coverColor ?: Color.TRANSPARENT, 175) + val translucentColor = ColorUtils.setAlphaComponent(presenter.coverColor ?: Color.TRANSPARENT, 175) (activity as MainActivity).toolbar.setBackgroundColor(translucentColor) translucentColor } else Color.TRANSPARENT @@ -407,8 +373,6 @@ class MangaDetailsController : presenter.refreshTracking() refreshTracker = null } - // fetch cover again in case the user set a new cover while reading - setPaletteColor() val isCurrentController = router?.backstack?.lastOrNull()?.controller() == this if (isCurrentController) { @@ -815,7 +779,7 @@ class MangaDetailsController : override fun prepareToShareManga() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - val request = LoadRequest.Builder(activity!!).data(presenter.manga).target( + val request = ImageRequest.Builder(activity!!).data(presenter.manga).target( onError = { shareManga() }, @@ -823,7 +787,7 @@ class MangaDetailsController : presenter.shareManga((it as BitmapDrawable).bitmap) } ).build() - Coil.imageLoader(activity!!).execute(request) + Coil.imageLoader(activity!!).enqueue(request) } else { shareManga() } @@ -931,7 +895,7 @@ class MangaDetailsController : } //region Interface methods - override fun coverColor(): Int? = coverColor + override fun coverColor(): Int? = presenter.coverColor override fun topCoverHeight(): Int = headerHeight override fun startDownloadNow(position: Int) { @@ -1187,6 +1151,30 @@ class MangaDetailsController : externalBottomSheet?.show() } + override fun generatePalette(input: Bitmap) { + val view = view ?: return + presenter.scope.launch(Dispatchers.Main) { + val p = async(Dispatchers.IO) { Palette.from(input).generate() } + if (recycler != null) { + val colorBack = view.context.getResourceColor( + android.R.attr.colorBackground + ) + + // this makes the color more consistent regardless of theme + val backDropColor = + ColorUtils.blendARGB(p.await().getVibrantColor(colorBack), colorBack, .35f) + presenter.coverColor = backDropColor + getHeader()?.setBackDrop(backDropColor) + setStatusBarAndToolbar() + if (toolbarIsColored) { + val translucentColor = ColorUtils.setAlphaComponent(backDropColor, 175) + (activity as MainActivity).toolbar.setBackgroundColor(translucentColor) + activity?.window?.statusBarColor = translucentColor + } + } + } + } + //endregion //region Tracking methods @@ -1454,6 +1442,7 @@ class MangaDetailsController : fun clearCoverCache() { backdrop.setImageDrawable(null) + true_backdrop.setBackgroundColor(Color.TRANSPARENT) manga_cover_full.setImageDrawable(null) manga_cover.setImageDrawable(null) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index aedc8931f8..167e552dca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -71,7 +71,9 @@ class MangaDetailsPresenter( private val chapterFilter: ChapterFilter = Injekt.get() ) : DownloadQueue.DownloadListener, LibraryServiceListener { - private var scope = CoroutineScope(Job() + Dispatchers.Default) + var scope = CoroutineScope(Job() + Dispatchers.Default) + + var coverColor: Int? = null private val customMangaManager: CustomMangaManager by injectLazy() @@ -449,9 +451,6 @@ class MangaDetailsPresenter( controller.clearCoverCache() } } - withContext(Dispatchers.Main) { - controller.setPaletteColor() - } db.insertManga(manga).executeOnIO() } fetchExternalLinks() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt index 960868553e..35ef246a43 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt @@ -2,12 +2,17 @@ package eu.kanade.tachiyomi.ui.manga import android.annotation.SuppressLint import android.app.Activity +import android.graphics.Bitmap import android.view.MotionEvent import android.view.View import android.view.ViewGroup import androidx.constraintlayout.widget.ConstraintLayout -import coil.api.loadAny +import androidx.core.graphics.drawable.toBitmap +import coil.bitmap.BitmapPool +import coil.loadAny import coil.request.CachePolicy +import coil.size.Size +import coil.transform.Transformation import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import com.mikepenz.iconics.typeface.library.materialdesigndx.MaterialDesignDx @@ -177,10 +182,6 @@ class MangaHeaderHolder( setImageDrawable(context.iconicsDrawableLarge(icon)) adapter.delegate.setFavButtonPopup(this) } - true_backdrop.setBackgroundColor( - adapter.delegate.coverColor() - ?: itemView.context.getResourceColor(android.R.attr.colorBackground) - ) val tracked = presenter.isTracked() && !item.isLocked @@ -305,20 +306,37 @@ class MangaHeaderHolder( fun updateCover(manga: Manga) { if (!manga.initialized) return - val drawable = adapter.controller.manga_cover_full?.drawable + + + adapter.controller.manga_cover?.drawable?.let { + adapter.delegate.generatePalette(it.toBitmap(10, 10)) + } + manga_cover.loadAny( - manga, - builder = { - placeholder(drawable) - error(drawable) - if (manga.favorite) networkCachePolicy(CachePolicy.DISABLED) + manga + ) { + if (manga.favorite) { + networkCachePolicy(CachePolicy.DISABLED) + memoryCachePolicy(CachePolicy.DISABLED) } - ) + transformations( + object : Transformation { + override fun key() = "paletteTransformer" + override suspend fun transform( + pool: BitmapPool, + input: Bitmap, + size: Size + ): Bitmap { + adapter.delegate.generatePalette(input) + return input + } + } + ) + } + backdrop.loadAny( manga, builder = { - placeholder(drawable) - error(drawable) if (manga.favorite) networkCachePolicy(CachePolicy.DISABLED) } ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/merge/MergeSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/merge/MergeSearchAdapter.kt index da9ecabab7..67bf40e200 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/merge/MergeSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/merge/MergeSearchAdapter.kt @@ -4,8 +4,8 @@ import android.content.Context import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter -import coil.api.clear -import coil.api.load +import coil.clear +import coil.load import coil.transform.RoundedCornersTransformation import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.model.SManga diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt index a33616d57a..afdfc5dc68 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt @@ -4,8 +4,8 @@ import android.content.Context import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter -import coil.api.clear -import coil.api.load +import coil.clear +import coil.load import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.util.view.gone diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/SaveImageNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/SaveImageNotifier.kt index 88bba6e265..7fb343d216 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/SaveImageNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/SaveImageNotifier.kt @@ -7,7 +7,7 @@ import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat import coil.Coil import coil.request.CachePolicy -import coil.request.LoadRequest +import coil.request.ImageRequest import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationHandler import eu.kanade.tachiyomi.data.notification.NotificationReceiver @@ -39,7 +39,7 @@ class SaveImageNotifier(private val context: Context) { */ fun onComplete(file: File) { - val request = LoadRequest.Builder(context).memoryCachePolicy(CachePolicy.DISABLED).diskCachePolicy(CachePolicy.DISABLED) + val request = ImageRequest.Builder(context).memoryCachePolicy(CachePolicy.DISABLED).diskCachePolicy(CachePolicy.DISABLED) .data(file) .size(720, 1280) .target( @@ -52,7 +52,7 @@ class SaveImageNotifier(private val context: Context) { } } ).build() - Coil.imageLoader(context).execute(request) + Coil.imageLoader(context).enqueue(request) } private fun showCompleteNotification(file: File, image: Bitmap) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index 9fff01aba5..83408b1746 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt @@ -19,7 +19,7 @@ import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView import androidx.core.net.toUri -import coil.api.loadAny +import coil.loadAny import coil.request.CachePolicy import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView @@ -258,9 +258,9 @@ class PagerPageHolder( if (viewer.config.readerTheme >= 2) { val imageView = initSubsamplingImageView() if (page.bg != null && page.bgType == getBGType( - viewer.config.readerTheme, - context - ) + viewer.config.readerTheme, + context + ) ) { imageView.setImage(ImageSource.inputStream(openStream!!)) imageView.background = page.bg @@ -293,7 +293,10 @@ class PagerPageHolder( // Keep the Rx stream alive to close the input stream only when unsubscribed .flatMap { Observable.never() } .doOnUnsubscribe { - try { openStream?.close() } catch (e: Exception) {} + try { + openStream?.close() + } catch (e: Exception) { + } } .subscribe({}, {}) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt index 76027a7123..07429f1b20 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt @@ -15,8 +15,8 @@ import android.widget.TextView import androidx.appcompat.widget.AppCompatButton import androidx.appcompat.widget.AppCompatImageView import androidx.core.net.toUri -import coil.api.clear -import coil.api.loadAny +import coil.clear +import coil.loadAny import coil.request.CachePolicy import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt index 41d9eaabfa..a7c5ed03f9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt @@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.ui.recent_updates import android.app.Activity import android.view.View import androidx.core.content.ContextCompat -import coil.api.clear +import coil.clear import coil.transform.CircleCropTransformation import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt index d8dd322f93..5b8fe7b3f1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt @@ -1,7 +1,7 @@ package eu.kanade.tachiyomi.ui.recently_read import android.view.View -import coil.api.clear +import coil.clear import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceGridHolder.kt index 2aa5569106..3710eae7b2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceGridHolder.kt @@ -4,15 +4,15 @@ import android.app.Activity import android.view.View import androidx.recyclerview.widget.RecyclerView import coil.Coil -import coil.api.clear -import coil.request.LoadRequest +import coil.clear +import coil.request.ImageRequest import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.potentialAltThumbnail +import eu.kanade.tachiyomi.data.image.coil.CoverViewTarget import eu.kanade.tachiyomi.ui.library.LibraryCategoryAdapter import eu.kanade.tachiyomi.util.view.gone -import eu.kanade.tachiyomi.data.image.coil.CoverViewTarget import kotlinx.android.synthetic.main.manga_grid_item.* import kotlinx.android.synthetic.main.unread_download_badge.* @@ -66,9 +66,9 @@ class BrowseSourceGridHolder( cover_thumbnail.clear() } else { val id = manga.id ?: return - val request = LoadRequest.Builder(view.context).data(manga) + val request = ImageRequest.Builder(view.context).data(manga) .target(CoverViewTarget(cover_thumbnail, progress, manga.potentialAltThumbnail())).build() - Coil.imageLoader(view.context).execute(request) + Coil.imageLoader(view.context).enqueue(request) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceListHolder.kt index 8c148b8ca6..7264d4bc7e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceListHolder.kt @@ -3,15 +3,15 @@ package eu.kanade.tachiyomi.ui.source.browse import android.view.View import androidx.recyclerview.widget.RecyclerView import coil.Coil -import coil.api.clear -import coil.request.LoadRequest +import coil.clear +import coil.request.ImageRequest import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.potentialAltThumbnail -import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.data.image.coil.CoverViewTarget +import eu.kanade.tachiyomi.util.system.getResourceColor import kotlinx.android.synthetic.main.manga_list_item.* /** @@ -48,9 +48,9 @@ class BrowseSourceListHolder(private val view: View, adapter: FlexibleAdapter