mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-30 17:31:50 +01:00
Better handle saving animated drawables
This commit is contained in:
parent
77bfd0c099
commit
cdc1c5efa3
@ -6,7 +6,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.net.Uri
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
@ -23,6 +22,7 @@ import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.util.lang.chop
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.getBitmapOrNull
|
||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||
import eu.kanade.tachiyomi.util.system.notify
|
||||
import tachiyomi.core.Constants
|
||||
@ -274,7 +274,7 @@ class LibraryUpdateNotifier(private val context: Context) {
|
||||
.size(NOTIF_ICON_SIZE)
|
||||
.build()
|
||||
val drawable = context.imageLoader.execute(request).drawable
|
||||
return (drawable as? BitmapDrawable)?.bitmap
|
||||
return drawable?.getBitmapOrNull()
|
||||
}
|
||||
|
||||
private fun getNewChaptersDescription(chapters: Array<Chapter>): String {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.manga
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.net.Uri
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||
@ -16,6 +15,7 @@ import eu.kanade.tachiyomi.data.saver.Image
|
||||
import eu.kanade.tachiyomi.data.saver.ImageSaver
|
||||
import eu.kanade.tachiyomi.data.saver.Location
|
||||
import eu.kanade.tachiyomi.util.editCover
|
||||
import eu.kanade.tachiyomi.util.system.getBitmapOrNull
|
||||
import eu.kanade.tachiyomi.util.system.toShareIntent
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
@ -98,7 +98,7 @@ class MangaCoverScreenModel(
|
||||
val result = context.imageLoader.execute(req).drawable
|
||||
|
||||
// TODO: Handle animated cover
|
||||
val bitmap = (result as? BitmapDrawable)?.bitmap ?: return@withIOContext null
|
||||
val bitmap = result?.getBitmapOrNull() ?: return@withIOContext null
|
||||
imageSaver.save(
|
||||
Image.Cover(
|
||||
bitmap = bitmap,
|
||||
|
@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.net.Uri
|
||||
import androidx.core.app.NotificationCompat
|
||||
import coil.imageLoader
|
||||
@ -13,6 +12,7 @@ import eu.kanade.tachiyomi.data.notification.NotificationHandler
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.getBitmapOrNull
|
||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||
import eu.kanade.tachiyomi.util.system.notify
|
||||
|
||||
@ -35,7 +35,7 @@ class SaveImageNotifier(private val context: Context) {
|
||||
.memoryCachePolicy(CachePolicy.DISABLED)
|
||||
.size(720, 1280)
|
||||
.target(
|
||||
onSuccess = { showCompleteNotification(uri, (it as? BitmapDrawable)?.bitmap) },
|
||||
onSuccess = { showCompleteNotification(uri, it.getBitmapOrNull()) },
|
||||
onError = { onError(null) },
|
||||
)
|
||||
.build()
|
||||
|
@ -277,10 +277,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
||||
)
|
||||
|
||||
when (image) {
|
||||
is Drawable -> {
|
||||
val bitmap = (image as BitmapDrawable).bitmap
|
||||
setImage(ImageSource.bitmap(bitmap))
|
||||
}
|
||||
is BitmapDrawable -> setImage(ImageSource.bitmap(image.bitmap))
|
||||
is InputStream -> setImage(ImageSource.inputStream(image))
|
||||
else -> throw IllegalArgumentException("Not implemented for class ${image::class.simpleName}")
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package eu.kanade.tachiyomi.util.system
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import coil.drawable.ScaleDrawable
|
||||
|
||||
fun Drawable.getBitmapOrNull(): Bitmap? = when (this) {
|
||||
is BitmapDrawable -> bitmap
|
||||
is ScaleDrawable -> child.toBitmap()
|
||||
else -> null
|
||||
}
|
Loading…
Reference in New Issue
Block a user