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 4382df7dd..26ae8208e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -15,6 +15,7 @@ import android.os.Bundle import android.os.Handler import android.util.DisplayMetrics import android.view.LayoutInflater +import android.view.MotionEvent import android.view.View import android.view.ViewGroup import com.bumptech.glide.Glide @@ -75,6 +76,12 @@ class PhotoFragment : ViewPagerFragment() { private var storedAllowOneFingerZoom = false private var storedExtendedDetails = 0 + private var mTouchDownX = 0f + private var mTouchDownY = 0f + private var mOriginalSubsamplingScale = 0f + private var mCloseDownThreshold = 100f + private var mIgnoreCloseDown = false + lateinit var view: ViewGroup lateinit var medium: Medium @@ -99,6 +106,11 @@ class PhotoFragment : ViewPagerFragment() { } } } + + subsampling_view.setOnTouchListener { v, event -> + handleEvent(event) + false + } } if (ViewPagerActivity.screenWidth == 0 || ViewPagerActivity.screenHeight == 0) { @@ -383,6 +395,7 @@ class PhotoFragment : ViewPagerFragment() { val useWidth = if (imageOrientation == ORIENTATION_ROTATE_90 || imageOrientation == ORIENTATION_ROTATE_270) sHeight else sWidth val useHeight = if (imageOrientation == ORIENTATION_ROTATE_90 || imageOrientation == ORIENTATION_ROTATE_270) sWidth else sHeight setDoubleTapZoomScale(getDoubleTapZoomScale(useWidth, useHeight)) + mOriginalSubsamplingScale = scale } override fun onTileLoadError(e: Exception?) { @@ -541,6 +554,29 @@ class PhotoFragment : ViewPagerFragment() { listener?.fragmentClicked() } + private fun handleEvent(event: MotionEvent) { + if (view.subsampling_view.scale != mOriginalSubsamplingScale) { + return + } + + when (event.actionMasked) { + MotionEvent.ACTION_DOWN -> { + mTouchDownX = event.x + mTouchDownY = event.y + } + MotionEvent.ACTION_POINTER_DOWN -> mIgnoreCloseDown = true + MotionEvent.ACTION_UP -> { + val diffX = mTouchDownX - event.x + val diffY = mTouchDownY - event.y + + if (!mIgnoreCloseDown && Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold) { + activity?.supportFinishAfterTransition() + } + mIgnoreCloseDown = false + } + } + } + override fun fullscreenToggled(isFullscreen: Boolean) { this.isFullscreen = isFullscreen view.photo_details.apply {