diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt index f09538ca1..4c0f3614e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt @@ -555,7 +555,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen togglePlayPause() } } else { - if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { + if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { toggleFullscreen() } } @@ -673,7 +673,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen togglePlayPause() } } else { - if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { + if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { toggleFullscreen() } } @@ -735,53 +735,6 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen video_surface.invalidate() } - private fun handleEventt(event: MotionEvent) { - when (event.actionMasked) { - MotionEvent.ACTION_MOVE -> { - val diffX = event.x - mTouchDownX - val diffY = event.y - mTouchDownY - - if (mIsDragged || (Math.abs(diffX) > mDragThreshold && Math.abs(diffX) > Math.abs(diffY))) { - if (!mIsDragged) { - arrayOf(video_curr_time, video_seekbar, video_duration).forEach { - it.animate().alpha(1f).start() - } - } - mIgnoreCloseDown = true - mIsDragged = true - var percent = ((diffX / mScreenWidth) * 100).toInt() - percent = Math.min(100, Math.max(-100, percent)) - - val skipLength = (mDuration * 1000f) * (percent / 100f) - var newProgress = mProgressAtDown + skipLength - newProgress = Math.max(Math.min(mExoPlayer!!.duration.toFloat(), newProgress), 0f) - val newSeconds = (newProgress / 1000).toInt() - setPosition(newSeconds) - resetPlayWhenReady() - } - } - MotionEvent.ACTION_UP -> { - mIgnoreCloseDown = false - if (mIsDragged) { - if (mIsFullscreen) { - arrayOf(video_curr_time, video_seekbar, video_duration).forEach { - it.animate().alpha(0f).start() - } - } - - if (!mIsPlaying) { - togglePlayPause() - } - } else { - if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { - toggleFullscreen() - } - } - mIsDragged = false - } - } - } - // taken from https://github.com/Manuiq/ZoomableTextureView private inner class ScaleListener : ScaleGestureDetector.SimpleOnScaleGestureListener() { override fun onScaleBegin(detector: ScaleGestureDetector): Boolean { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt index 5e78802a8..beebb1604 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt @@ -731,15 +731,15 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S val diffX = mTouchDownX - event.x val diffY = mTouchDownY - event.y - val downGestureDuration = System.currentTimeMillis() - mTouchDownTime - if (!mIgnoreCloseDown && Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION && mSaveScale == 1f) { - activity?.supportFinishAfterTransition() + if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { + mTextureView.performClick() + } else { + val downGestureDuration = System.currentTimeMillis() - mTouchDownTime + if (!mIgnoreCloseDown && Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION && mSaveScale == 1f) { + activity?.supportFinishAfterTransition() + } } mIgnoreCloseDown = false - - if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { - mTextureView.performClick() - } } MotionEvent.ACTION_POINTER_DOWN -> { mLastTouchX = event.x diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 53714f1db..e775ba452 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -103,6 +103,7 @@ const val GO_TO_PREV_ITEM = "go_to_prev_item" const val MAX_COLUMN_COUNT = 20 const val SHOW_TEMP_HIDDEN_DURATION = 300000L const val CLICK_MAX_DURATION = 150 +const val CLICK_MAX_DISTANCE = 100 const val MAX_CLOSE_DOWN_GESTURE_DURATION = 400 const val DRAG_THRESHOLD = 8 const val MONTH_MILLISECONDS = MONTH_SECONDS * 1000L diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/InstantItemSwitch.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/InstantItemSwitch.kt index c21e2f642..18f2f154e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/InstantItemSwitch.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/InstantItemSwitch.kt @@ -5,6 +5,7 @@ import android.util.AttributeSet import android.view.MotionEvent import android.view.ViewGroup import android.widget.RelativeLayout +import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DISTANCE import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DURATION import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD @@ -40,7 +41,9 @@ class InstantItemSwitch(context: Context, attrs: AttributeSet) : RelativeLayout( mTouchDownTime = System.currentTimeMillis() } MotionEvent.ACTION_UP -> { - if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { + val diffX = mTouchDownX - event.x + val diffY = mTouchDownY - event.y + if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { performClick() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MediaSideScroll.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MediaSideScroll.kt index 0c424b631..52ebde06e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MediaSideScroll.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MediaSideScroll.kt @@ -13,6 +13,7 @@ import android.widget.TextView import com.simplemobiletools.commons.extensions.onGlobalLayout import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.audioManager +import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DISTANCE import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DURATION import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD @@ -106,7 +107,9 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co mLastTouchY = event.y } MotionEvent.ACTION_UP -> { - if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { + val diffX = mTouchDownX - event.x + val diffY = mTouchDownY - event.y + if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { callback(event.rawX, event.rawY) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MyZoomableGifTextureView.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MyZoomableGifTextureView.kt index 60e54ec1a..be6e23a35 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MyZoomableGifTextureView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MyZoomableGifTextureView.kt @@ -89,14 +89,14 @@ class MyZoomableGifTextureView(context: Context, attrs: AttributeSet) : GifTextu val diffX = mTouchDownX - event.x val diffY = mTouchDownY - event.y mCurrZoomMode = ZOOM_MODE_NONE - if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { + if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { performClick() - } - - val downGestureDuration = System.currentTimeMillis() - mTouchDownTime - val areDiffsOK = Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold - if (mSaveScale == 1f && !mIgnoreCloseDown && areDiffsOK && context.config.allowDownGesture && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION) { - mCloseDownCallback?.invoke() + } else { + val downGestureDuration = System.currentTimeMillis() - mTouchDownTime + val areDiffsOK = Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold + if (mSaveScale == 1f && !mIgnoreCloseDown && areDiffsOK && context.config.allowDownGesture && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION) { + mCloseDownCallback?.invoke() + } } mIgnoreCloseDown = false }