diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 232708083..ab16d130f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -65,7 +65,7 @@ const val NOMEDIA = ".nomedia" const val MAX_COLUMN_COUNT = 20 const val SHOW_TEMP_HIDDEN_DURATION = 600000L const val CLICK_MAX_DURATION = 150 -const val DRAG_THRESHOLD = 10 +const val DRAG_THRESHOLD = 15 const val DIRECTORY = "directory" const val MEDIUM = "medium" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt index 43e832084..0ac4801eb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt @@ -14,6 +14,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.extensions.audioManager +// allow horizontal swipes through the layout, else it can cause glitches at zoomed in images class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs) { private val SLIDE_INFO_FADE_DELAY = 1000L private var mTouchDownX = 0f @@ -23,6 +24,7 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co private var mTempBrightness = 0 private var mLastTouchY = 0f private var mIsBrightnessScroll = false + private var mPassTouches = false private var mSlideInfoText = "" private var mSlideInfoFadeHandler = Handler() @@ -41,8 +43,22 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co mSlideInfoText = activity.getString(if (isBrightness) R.string.brightness else R.string.volume) } + override fun dispatchTouchEvent(ev: MotionEvent): Boolean { + if (mPassTouches) { + if (ev.actionMasked == MotionEvent.ACTION_DOWN) { + mPassTouches = false + } + return false + } + return super.dispatchTouchEvent(ev) + } + override fun onTouchEvent(event: MotionEvent): Boolean { - when (event.action) { + if (mPassTouches) { + return false + } + + when (event.actionMasked) { MotionEvent.ACTION_DOWN -> { mTouchDownX = event.x mTouchDownY = event.y @@ -70,10 +86,19 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co } percentChanged(percent) + } else if (Math.abs(diffX) > DRAG_THRESHOLD || Math.abs(diffY) > DRAG_THRESHOLD) { + if (!mPassTouches) { + event.action = MotionEvent.ACTION_DOWN + event.setLocation(event.rawX, event.y) + mParentView?.dispatchTouchEvent(event) + } + mPassTouches = true + mParentView?.dispatchTouchEvent(event) + return false } mLastTouchY = event.y } - MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { + MotionEvent.ACTION_UP -> { if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { callback() }