From f9000830f5646223609c7993a788ddf237b52ab6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 2 Oct 2018 19:08:31 +0200 Subject: [PATCH] fix #972, use GifTextureView for displaying gifs, do not pause/resume them --- .../gallery/fragments/PhotoFragment.kt | 31 +++++-------------- app/src/main/res/layout/pager_photo_item.xml | 14 ++++++--- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index abaa96355..3a2a156b9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -45,7 +45,7 @@ import it.sephiroth.android.library.exif2.ExifInterface import kotlinx.android.synthetic.main.pager_photo_item.view.* import org.apache.sanselan.common.byteSources.ByteSourceInputStream import org.apache.sanselan.formats.jpeg.JpegImageParser -import pl.droidsonroids.gif.GifDrawable +import pl.droidsonroids.gif.InputSource import java.io.File import java.io.FileOutputStream import java.util.* @@ -66,7 +66,6 @@ class PhotoFragment : ViewPagerFragment() { private var isPanorama = false private var isSubsamplingVisible = false // checking view.visibility is unreliable, use an extra variable for it private var imageOrientation = -1 - private var gifDrawable: GifDrawable? = null private var loadZoomableViewHandler = Handler() private var storedShowExtendedDetails = false @@ -187,9 +186,7 @@ class PhotoFragment : ViewPagerFragment() { super.setMenuVisibility(menuVisible) isFragmentVisible = menuVisible if (wasInit) { - if (medium.isGIF()) { - gifFragmentVisibilityChanged(menuVisible) - } else { + if (!medium.isGIF()) { photoFragmentVisibilityChanged(menuVisible) } } @@ -220,14 +217,6 @@ class PhotoFragment : ViewPagerFragment() { } } - private fun gifFragmentVisibilityChanged(isVisible: Boolean) { - if (isVisible) { - gifDrawable?.start() - } else { - gifDrawable?.stop() - } - } - private fun photoFragmentVisibilityChanged(isVisible: Boolean) { if (isVisible) { scheduleZoomableView() @@ -269,22 +258,18 @@ class PhotoFragment : ViewPagerFragment() { private fun loadGif() { try { val pathToLoad = getPathToLoad(medium) - gifDrawable = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) { - GifDrawable(context!!.contentResolver, Uri.parse(pathToLoad)) + val source = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) { + InputSource.UriSource(context!!.contentResolver, Uri.parse(pathToLoad)) } else { - GifDrawable(pathToLoad) + InputSource.FileSource(pathToLoad) } - if (!isFragmentVisible) { - gifDrawable!!.stop() - } - - view.photo_view.setImageDrawable(gifDrawable) + view.photo_view.beGone() + view.gif_view.beVisible() + view.gif_view.setInputSource(source) } catch (e: Exception) { - gifDrawable = null loadBitmap() } catch (e: OutOfMemoryError) { - gifDrawable = null loadBitmap() } } diff --git a/app/src/main/res/layout/pager_photo_item.xml b/app/src/main/res/layout/pager_photo_item.xml index 96cb2b6c3..9be779d15 100644 --- a/app/src/main/res/layout/pager_photo_item.xml +++ b/app/src/main/res/layout/pager_photo_item.xml @@ -11,6 +11,12 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> + + + android:layout_alignParentStart="true" + android:layout_alignParentLeft="true"/>