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 { 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.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile 'com.google.code.gson:gson:2.8.0' 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 '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" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'

View File

@ -130,7 +130,7 @@ fun Activity.launchCamera() {
fun SimpleActivity.launchAbout() { fun SimpleActivity.launchAbout() {
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_MULTISELECT or LICENSE_RTL 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() { fun AppCompatActivity.showSystemUI() {

View File

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