Skip to content

Commit

Permalink
fixed problems with return animation and de-zooming
Browse files Browse the repository at this point in the history
  • Loading branch information
luca committed Dec 17, 2019
1 parent 7f7688a commit 2efa84e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.transition.Transition
import android.view.View
import android.widget.ImageView
import androidx.core.app.ActivityOptionsCompat
import androidx.core.transition.doOnEnd
import com.bumptech.glide.Glide
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.kirkbushman.largeimageview.ImageLoader
import com.kirkbushman.largeimageview.ImageReadyCallback
import com.kirkbushman.largeimageview.sampleapp.R
import com.kirkbushman.largeimageview.sampleapp.utils.SimpleTransitionListener
import com.kirkbushman.largeimageview.sampleapp.utils.doAsync
import com.kirkbushman.largeimageview.sampleapp.utils.loadThumbnail
import com.kirkbushman.largeimageview.scaleMin
import kotlinx.android.synthetic.main.activity_anim_second.*
import java.io.File
import java.lang.Exception
Expand All @@ -26,6 +29,8 @@ class AnimSecondActivity : BaseBackActivity() {
private const val PARAM_THUMB = "intent_param_thumb"
private const val PARAM_SOURCE = "intent_param_source"

private const val ANIM_DURATION = 300L

fun start(activity: Activity, imageView: ImageView, thumbUrl: String, sourceUrl: String) {
val intent = Intent(activity, AnimSecondActivity::class.java)
intent.putExtra(PARAM_THUMB, thumbUrl)
Expand All @@ -50,10 +55,15 @@ class AnimSecondActivity : BaseBackActivity() {

if (Build.VERSION.SDK_INT >= 21) {

window.sharedElementEnterTransition.doOnEnd {
window.sharedElementEnterTransition.addListener(object : SimpleTransitionListener() {

liv.triggerShowImage()
}
override fun onTransitionEnd(transition: Transition?) {

liv.triggerShowImage()

window.sharedElementEnterTransition.removeListener(this)
}
})
}

liv.setImageLoader(object : ImageLoader {
Expand Down Expand Up @@ -103,7 +113,32 @@ class AnimSecondActivity : BaseBackActivity() {

if (Build.VERSION.SDK_INT >= 21) {

finishAfterTransition()
val ssiv = liv.getSsiv()
if (ssiv?.scale == ssiv?.minScale) {

finishAfterTransition()
} else {

ssiv?.scaleMin(ANIM_DURATION, object : SubsamplingScaleImageView.OnAnimationEventListener {

override fun onComplete() {
finishAfterTransition()
}

override fun onInterruptedByNewAnim() {
finishAfterTransition()
}

override fun onInterruptedByUser() {
finishAfterTransition()
}
})
}
}
}

override fun finishAfterTransition() {
liv.showThumbnailView()
super.finishAfterTransition()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.kirkbushman.largeimageview.sampleapp.utils

import android.transition.Transition

abstract class SimpleTransitionListener : Transition.TransitionListener {

override fun onTransitionStart(transition: Transition?) {}
override fun onTransitionPause(transition: Transition?) {}
override fun onTransitionCancel(transition: Transition?) {}
override fun onTransitionResume(transition: Transition?) {}
override fun onTransitionEnd(transition: Transition?) {}
}

0 comments on commit 2efa84e

Please sign in to comment.