Fix crash when opening animated manga covers

Fixes #957
This commit is contained in:
Jays2Kings 2021-08-10 16:58:26 -04:00
parent 18d385d5ac
commit 962247b2f4
4 changed files with 29 additions and 21 deletions

View File

@ -154,7 +154,7 @@ class LibraryUpdateNotifier(private val context: Context) {
Coil.imageLoader(context) Coil.imageLoader(context)
.execute(request).drawable?.let { drawable -> .execute(request).drawable?.let { drawable ->
setLargeIcon((drawable as BitmapDrawable).bitmap) setLargeIcon((drawable as? BitmapDrawable)?.bitmap)
} }
} catch (e: Exception) { } catch (e: Exception) {
} }

View File

@ -5,6 +5,7 @@ import android.animation.ValueAnimator
import android.app.Dialog import android.app.Dialog
import android.graphics.Color import android.graphics.Color
import android.graphics.Rect import android.graphics.Rect
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.view.LayoutInflater import android.view.LayoutInflater
@ -12,6 +13,7 @@ import android.view.View
import android.view.animation.DecelerateInterpolator import android.view.animation.DecelerateInterpolator
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.animation.addListener import androidx.core.animation.addListener
import androidx.core.view.isVisible
import androidx.transition.ChangeBounds import androidx.transition.ChangeBounds
import androidx.transition.ChangeImageTransform import androidx.transition.ChangeImageTransform
import androidx.transition.TransitionManager import androidx.transition.TransitionManager
@ -25,7 +27,7 @@ import eu.kanade.tachiyomi.util.view.animateBlur
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class FullCoverDialog(val controller: MangaDetailsController, drawable: Drawable, val thumbView: View) : class FullCoverDialog(val controller: MangaDetailsController, drawable: Drawable, private val thumbView: View) :
Dialog(controller.activity!!, R.style.FullCoverDialogTheme) { Dialog(controller.activity!!, R.style.FullCoverDialogTheme) {
val activity = controller.activity val activity = controller.activity
@ -64,6 +66,9 @@ class FullCoverDialog(val controller: MangaDetailsController, drawable: Drawable
.build() .build()
expandedImageView.setImageDrawable(drawable) expandedImageView.setImageDrawable(drawable)
if (drawable !is BitmapDrawable) {
binding.buttonContainer.isVisible = false
}
val rect = Rect() val rect = Rect()
thumbView.getGlobalVisibleRect(rect) thumbView.getGlobalVisibleRect(rect)

View File

@ -355,23 +355,26 @@ class MangaDetailsController :
val request = ImageRequest.Builder(view.context).data(presenter.manga).allowHardware(false).memoryCacheKey(presenter.manga.key()) 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
// Generate the Palette on a background thread. // Generate the Palette on a background thread.
Palette.from(bitmap).generate { if (bitmap != null) {
if (it == null) return@generate Palette.from(bitmap).generate {
val colorBack = view.context.getResourceColor( if (it == null) return@generate
android.R.attr.colorBackground val colorBack = view.context.getResourceColor(
) android.R.attr.colorBackground
// this makes the color more consistent regardless of theme )
val backDropColor = // this makes the color more consistent regardless of theme
ColorUtils.blendARGB(it.getVibrantColor(colorBack), colorBack, .35f) val backDropColor =
ColorUtils.blendARGB(it.getVibrantColor(colorBack), colorBack, .35f)
coverColor = backDropColor coverColor = backDropColor
getHeader()?.setBackDrop(backDropColor) getHeader()?.setBackDrop(backDropColor)
if (toolbarIsColored) { if (toolbarIsColored) {
val translucentColor = ColorUtils.setAlphaComponent(backDropColor, 175) val translucentColor =
activityBinding?.toolbar?.setBackgroundColor(translucentColor) ColorUtils.setAlphaComponent(backDropColor, 175)
activity?.window?.statusBarColor = translucentColor activityBinding?.toolbar?.setBackgroundColor(translucentColor)
activity?.window?.statusBarColor = translucentColor
}
} }
} }
binding.mangaCoverFull.setImageDrawable(drawable) binding.mangaCoverFull.setImageDrawable(drawable)
@ -1379,11 +1382,12 @@ class MangaDetailsController :
override fun zoomImageFromThumb(thumbView: View) { override fun zoomImageFromThumb(thumbView: View) {
if (fullCoverActive) return if (fullCoverActive) return
val drawable = binding.mangaCoverFull.drawable ?: return
fullCoverActive = true fullCoverActive = true
val expandedImageView = binding.mangaCoverFull drawable.alpha = 255
val fullCoverDialog = FullCoverDialog( val fullCoverDialog = FullCoverDialog(
this, this,
expandedImageView.drawable, drawable,
thumbView thumbView
) )
fullCoverDialog.setOnDismissListener { fullCoverDialog.setOnDismissListener {
@ -1393,7 +1397,6 @@ class MangaDetailsController :
fullCoverActive = false fullCoverActive = false
} }
fullCoverDialog.show() fullCoverDialog.show()
return
} }
companion object { companion object {

View File

@ -73,7 +73,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:fastScrollerBubbleEnabled="true" /> app:fastScrollerBubbleEnabled="true" />
<ImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/manga_cover_full" android:id="@+id/manga_cover_full"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"