add the close-down gesture to videos too

This commit is contained in:
tibbi 2018-10-22 16:41:17 +02:00
parent 4b7adea779
commit 237937c162
3 changed files with 39 additions and 31 deletions

View file

@ -15,7 +15,6 @@ import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MotionEvent
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
@ -74,13 +73,8 @@ class PhotoFragment : ViewPagerFragment() {
private var storedAllowDeepZoomableImages = false private var storedAllowDeepZoomableImages = false
private var storedShowHighestQuality = false private var storedShowHighestQuality = false
private var storedAllowOneFingerZoom = false private var storedAllowOneFingerZoom = false
private var storedExtendedDetails = 0
private var mTouchDownX = 0f
private var mTouchDownY = 0f
private var mOriginalSubsamplingScale = 0f private var mOriginalSubsamplingScale = 0f
private var mCloseDownThreshold = 100f private var storedExtendedDetails = 0
private var mIgnoreCloseDown = false
lateinit var view: ViewGroup lateinit var view: ViewGroup
lateinit var medium: Medium lateinit var medium: Medium
@ -113,7 +107,9 @@ class PhotoFragment : ViewPagerFragment() {
} }
subsampling_view.setOnTouchListener { v, event -> subsampling_view.setOnTouchListener { v, event ->
if (view.subsampling_view.scale == mOriginalSubsamplingScale) {
handleEvent(event) handleEvent(event)
}
false false
} }
} }
@ -559,29 +555,6 @@ class PhotoFragment : ViewPagerFragment() {
listener?.fragmentClicked() 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) { override fun fullscreenToggled(isFullscreen: Boolean) {
this.isFullscreen = isFullscreen this.isFullscreen = isFullscreen
view.photo_details.apply { view.photo_details.apply {

View file

@ -86,6 +86,16 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
mBrightnessSideScroll = video_brightness_controller mBrightnessSideScroll = video_brightness_controller
mVolumeSideScroll = video_volume_controller mVolumeSideScroll = video_volume_controller
mCurrTimeView = video_curr_time mCurrTimeView = video_curr_time
video_preview.setOnTouchListener { v, event ->
handleEvent(event)
true
}
video_surface.setOnTouchListener { v, event ->
handleEvent(event)
false
}
} }
storeStateVariables() storeStateVariables()

View file

@ -1,5 +1,6 @@
package com.simplemobiletools.gallery.fragments package com.simplemobiletools.gallery.fragments
import android.view.MotionEvent
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.OTG_PATH
@ -11,6 +12,11 @@ import java.io.File
abstract class ViewPagerFragment : Fragment() { abstract class ViewPagerFragment : Fragment() {
var listener: FragmentListener? = null 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) abstract fun fullscreenToggled(isFullscreen: Boolean)
interface FragmentListener { 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 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
}
}
}
} }