fix #972, use GifTextureView for displaying gifs, do not pause/resume them

This commit is contained in:
tibbi 2018-10-02 19:08:31 +02:00
parent ab06f366f8
commit f9000830f5
2 changed files with 18 additions and 27 deletions

View file

@ -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()
}
}

View file

@ -11,6 +11,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<pl.droidsonroids.gif.GifTextureView
android:id="@+id/gif_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/subsampling_view"
android:layout_width="match_parent"
@ -45,8 +51,8 @@
android:id="@+id/photo_brightness_controller"
android:layout_width="@dimen/media_side_slider_width"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/slide_info"
@ -58,10 +64,10 @@
android:alpha="0"
android:background="@drawable/black_rounded_background"
android:gravity="center"
android:paddingBottom="@dimen/medium_margin"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingBottom="@dimen/medium_margin"
android:textColor="@android:color/white"
android:textSize="@dimen/extra_big_text_size"/>