From f3c55e1df899d3247000ea32cd5a438c4c2de4db Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 25 Sep 2020 21:23:47 +0200 Subject: [PATCH] fix #1124, properly handle playing animated WebP files --- app/build.gradle | 3 +- .../gallery/pro/extensions/Activity.kt | 3 +- .../gallery/pro/fragments/PhotoFragment.kt | 40 +++++++++++-------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d30c87e16..558eaf41c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -77,7 +77,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.30.12' + implementation 'com.simplemobiletools:commons:5.30.14' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19' @@ -92,6 +92,7 @@ dependencies { implementation 'com.github.tibbi:gestureviews:512f929d82' implementation 'com.github.tibbi:subsampling-scale-image-view:81c021514c' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' + implementation 'com.github.penfeizhou.android.animation:awebp:2.4.2' kapt 'com.github.bumptech.glide:compiler:4.10.0' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index ed7f6da3b..2c9b54f0c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -81,7 +81,8 @@ fun Activity.launchCamera() { fun SimpleActivity.launchAbout() { val licenses = LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_RTL or LICENSE_SUBSAMPLING or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GIF_DRAWABLE or - LICENSE_PICASSO or LICENSE_EXOPLAYER or LICENSE_PANORAMA_VIEW or LICENSE_SANSELAN or LICENSE_FILTERS or LICENSE_GESTURE_VIEWS + LICENSE_PICASSO or LICENSE_EXOPLAYER or LICENSE_PANORAMA_VIEW or LICENSE_SANSELAN or LICENSE_FILTERS or LICENSE_GESTURE_VIEWS or + LICENSE_APNG val faqItems = arrayListOf( FAQItem(R.string.faq_5_title_commons, R.string.faq_5_text_commons), diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index f1b3a6110..c463053d7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -36,6 +36,7 @@ import com.davemorrissey.labs.subscaleview.DecoderFactory import com.davemorrissey.labs.subscaleview.ImageDecoder import com.davemorrissey.labs.subscaleview.ImageRegionDecoder import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView +import com.github.penfeizhou.animation.webp.WebPDrawable import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.ensureBackgroundThread @@ -405,25 +406,32 @@ class PhotoFragment : ViewPagerFragment() { return } - Glide.with(context!!) - .load(getFilePathToShow()) - .apply(options) - .listener(object : RequestListener { - override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { - if (activity != null && !activity!!.isDestroyed && !activity!!.isFinishing) { - tryLoadingWithPicasso(addZoomableView) + val path = getFilePathToShow() + if (path.isWebP()) { + val drawable = WebPDrawable.fromFile(path) + drawable.setLoopLimit(0) + mView.gestures_view.setImageDrawable(drawable) + } else { + Glide.with(context!!) + .load(path) + .apply(options) + .listener(object : RequestListener { + override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { + if (activity != null && !activity!!.isDestroyed && !activity!!.isFinishing) { + tryLoadingWithPicasso(addZoomableView) + } + return false } - return false - } - override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { - mView.gestures_view.controller.settings.isZoomEnabled = mMedium.isRaw() || mCurrentRotationDegrees != 0 || context?.config?.allowZoomingImages == false - if (mIsFragmentVisible && addZoomableView) { - scheduleZoomableView() + override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { + mView.gestures_view.controller.settings.isZoomEnabled = mMedium.isRaw() || mCurrentRotationDegrees != 0 || context?.config?.allowZoomingImages == false + if (mIsFragmentVisible && addZoomableView) { + scheduleZoomableView() + } + return false } - return false - } - }).into(mView.gestures_view) + }).into(mView.gestures_view) + } } private fun tryLoadingWithPicasso(addZoomableView: Boolean) {