From 237937c1622e844047097f4e590bb1709d164d67 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 22 Oct 2018 16:41:17 +0200 Subject: [PATCH] add the close-down gesture to videos too --- .../gallery/fragments/PhotoFragment.kt | 35 +++---------------- .../gallery/fragments/VideoFragment.kt | 10 ++++++ .../gallery/fragments/ViewPagerFragment.kt | 25 +++++++++++++ 3 files changed, 39 insertions(+), 31 deletions(-) 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 bc6f251cf..fab869e88 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -15,7 +15,6 @@ 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 @@ -74,13 +73,8 @@ class PhotoFragment : ViewPagerFragment() { private var storedAllowDeepZoomableImages = false private var storedShowHighestQuality = false 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 + private var storedExtendedDetails = 0 lateinit var view: ViewGroup lateinit var medium: Medium @@ -113,7 +107,9 @@ class PhotoFragment : ViewPagerFragment() { } subsampling_view.setOnTouchListener { v, event -> - handleEvent(event) + if (view.subsampling_view.scale == mOriginalSubsamplingScale) { + handleEvent(event) + } false } } @@ -559,29 +555,6 @@ 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 { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index 1edde49d9..606076791 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -86,6 +86,16 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S mBrightnessSideScroll = video_brightness_controller mVolumeSideScroll = video_volume_controller mCurrTimeView = video_curr_time + + video_preview.setOnTouchListener { v, event -> + handleEvent(event) + true + } + + video_surface.setOnTouchListener { v, event -> + handleEvent(event) + false + } } storeStateVariables() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt index bb37b58e2..3a999e10d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.gallery.fragments +import android.view.MotionEvent import androidx.fragment.app.Fragment import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH @@ -11,6 +12,11 @@ import java.io.File abstract class ViewPagerFragment : Fragment() { var listener: FragmentListener? = null + protected var mTouchDownX = 0f + protected var mTouchDownY = 0f + protected var mCloseDownThreshold = 100f + protected var mIgnoreCloseDown = false + abstract fun fullscreenToggled(isFullscreen: Boolean) interface FragmentListener { @@ -68,4 +74,23 @@ abstract class ViewPagerFragment : Fragment() { } fun getPathToLoad(medium: Medium) = if (medium.path.startsWith(OTG_PATH)) medium.path.getOTGPublicPath(context!!) else medium.path + + protected fun handleEvent(event: MotionEvent) { + 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 + } + } + } }