replace PhotoView with GifDrawable

it will replace zoomable gifs with smooth gifs
This commit is contained in:
tibbi 2017-10-28 11:02:02 +02:00
parent 05386e4720
commit 286955ab83
4 changed files with 39 additions and 38 deletions

View file

@ -37,13 +37,13 @@ android {
}
dependencies {
compile 'com.simplemobiletools:commons:2.32.5'
compile 'com.simplemobiletools:commons:2.32.6'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.github.chrisbanes:PhotoView:2.1.2'
compile 'it.sephiroth.android.exif:library:1.0.1'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'

View file

@ -130,7 +130,7 @@ fun Activity.launchCamera() {
fun SimpleActivity.launchAbout() {
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_MULTISELECT or LICENSE_RTL
or LICENSE_PHOTOVIEW or LICENSE_SUBSAMPLING or LICENSE_PATTERN, BuildConfig.VERSION_NAME)
or LICENSE_SUBSAMPLING or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GIF_DRAWABLE, BuildConfig.VERSION_NAME)
}
fun AppCompatActivity.showSystemUI() {

View file

@ -13,12 +13,10 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.bumptech.glide.Priority
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
@ -33,6 +31,7 @@ import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium
import it.sephiroth.android.library.exif2.ExifInterface
import kotlinx.android.synthetic.main.pager_photo_item.view.*
import pl.droidsonroids.gif.GifDrawable
import java.io.File
import java.io.FileOutputStream
@ -41,6 +40,7 @@ class PhotoFragment : ViewPagerFragment() {
private var wasInit = false
private var storedShowExtendedDetails = false
private var storedExtendedDetails = 0
private var gifDrawable: GifDrawable? = null
lateinit var view: ViewGroup
lateinit var medium: Medium
@ -80,18 +80,8 @@ class PhotoFragment : ViewPagerFragment() {
}
}
view.subsampling_view.setOnClickListener({ photoClicked() })
view.photo_view.apply {
maximumScale = 8f
mediumScale = 3f
setOnOutsidePhotoTapListener {
photoClicked()
}
setOnPhotoTapListener { view, x, y ->
photoClicked()
}
}
view.subsampling_view.setOnClickListener { photoClicked() }
view.gif_view.setOnClickListener { photoClicked() }
loadImage()
checkExtendedDetails()
@ -117,7 +107,24 @@ class PhotoFragment : ViewPagerFragment() {
super.setMenuVisibility(menuVisible)
isFragmentVisible = menuVisible
if (wasInit) {
if (menuVisible) {
if (medium.isGif()) {
gifFragmentVisibilityChanged(menuVisible)
} else {
photoFragmentVisibilityChanged(menuVisible)
}
}
}
private fun gifFragmentVisibilityChanged(isVisible: Boolean) {
if (isVisible) {
gifDrawable?.start()
} else {
gifDrawable?.stop()
}
}
private fun photoFragmentVisibilityChanged(isVisible: Boolean) {
if (isVisible) {
addZoomableView()
} else {
view.subsampling_view.apply {
@ -127,7 +134,6 @@ class PhotoFragment : ViewPagerFragment() {
}
}
}
}
private fun degreesForRotation(orientation: Int) = when (orientation) {
8 -> 270
@ -149,16 +155,11 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadImage() {
if (medium.isGif()) {
val options = RequestOptions()
.priority(if (isFragmentVisible) Priority.IMMEDIATE else Priority.LOW)
.diskCacheStrategy(DiskCacheStrategy.DATA)
gifDrawable = GifDrawable(medium.path)
if (!isFragmentVisible)
gifDrawable!!.stop()
Glide.with(this)
.asGif()
.load(medium.path)
.transition(DrawableTransitionOptions.withCrossFade())
.apply(options)
.into(view.photo_view)
view.gif_view.setImageDrawable(gifDrawable)
} else {
loadBitmap()
}
@ -187,7 +188,7 @@ class PhotoFragment : ViewPagerFragment() {
addZoomableView()
return false
}
}).into(view.photo_view)
}).into(view.gif_view)
} else {
val options = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE)
@ -198,7 +199,7 @@ class PhotoFragment : ViewPagerFragment() {
.load(medium.path)
.thumbnail(0.2f)
.apply(options)
.into(view.photo_view)
.into(view.gif_view)
}
}
@ -286,7 +287,7 @@ class PhotoFragment : ViewPagerFragment() {
super.onDestroyView()
context.isKitkatPlus()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !activity.isDestroyed) {
Glide.with(context).clear(view.photo_view)
Glide.with(context).clear(view.gif_view)
}
}

View file

@ -6,8 +6,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
<pl.droidsonroids.gif.GifImageView
android:id="@+id/gif_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>