fix some glitches with swiping to sides with Instant media change enabled
This commit is contained in:
parent
a2b973c233
commit
2a2d37e221
|
@ -61,6 +61,10 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
gif_view.setOnClickListener { photoClicked() }
|
||||
instant_prev_item.setOnClickListener { listener?.goToPrevItem() }
|
||||
instant_next_item.setOnClickListener { listener?.goToNextItem() }
|
||||
|
||||
instant_prev_item.parentView = container
|
||||
instant_next_item.parentView = container
|
||||
|
||||
photo_brightness_controller.setOnTouchListener { v, event ->
|
||||
mediaSideScroll.handleBrightnessTouched(event)
|
||||
true
|
||||
|
|
|
@ -64,6 +64,8 @@ const val SLIDESHOW_SCROLL_DURATION = 500L
|
|||
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 DIRECTORY = "directory"
|
||||
const val MEDIUM = "medium"
|
||||
|
|
|
@ -11,7 +11,6 @@ import com.simplemobiletools.gallery.activities.ViewPagerActivity
|
|||
import com.simplemobiletools.gallery.extensions.audioManager
|
||||
|
||||
class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val callback: () -> Unit) {
|
||||
private val CLICK_MAX_DURATION = 150
|
||||
private val SLIDE_INFO_FADE_DELAY = 1000L
|
||||
private var mTouchDownX = 0f
|
||||
private var mTouchDownY = 0f
|
||||
|
@ -38,7 +37,7 @@ class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val c
|
|||
val diffX = mTouchDownX - event.x
|
||||
val diffY = mTouchDownY - event.y
|
||||
|
||||
if (Math.abs(diffY) > 20 && Math.abs(diffY) > Math.abs(diffX)) {
|
||||
if (Math.abs(diffY) > DRAG_THRESHOLD && Math.abs(diffY) > Math.abs(diffX)) {
|
||||
var percent = ((diffY / ViewPagerActivity.screenHeight) * 100).toInt() * 3
|
||||
percent = Math.min(100, Math.max(-100, percent))
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package com.simplemobiletools.gallery.views
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.gallery.helpers.CLICK_MAX_DURATION
|
||||
import com.simplemobiletools.gallery.helpers.DRAG_THRESHOLD
|
||||
|
||||
// handle only one finger clicks, pass other events to the parent view and ignore it when received again
|
||||
class InstantItemSwitch(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs) {
|
||||
private var mTouchDownTime = 0L
|
||||
private var mTouchDownX = 0f
|
||||
private var mTouchDownY = 0f
|
||||
private var passTouches = false
|
||||
|
||||
var parentView: ViewGroup? = null
|
||||
|
||||
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
||||
if (passTouches) {
|
||||
if (ev.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
passTouches = false
|
||||
}
|
||||
return false
|
||||
}
|
||||
return super.dispatchTouchEvent(ev)
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
if (passTouches) {
|
||||
return false
|
||||
}
|
||||
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
mTouchDownX = event.x
|
||||
mTouchDownY = event.y
|
||||
mTouchDownTime = System.currentTimeMillis()
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
performClick()
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
if (passTouches) {
|
||||
return false
|
||||
}
|
||||
|
||||
val diffX = mTouchDownX - event.x
|
||||
val diffY = mTouchDownY - event.y
|
||||
if (Math.abs(diffX) > DRAG_THRESHOLD || Math.abs(diffY) > DRAG_THRESHOLD) {
|
||||
if (!passTouches) {
|
||||
event.action = MotionEvent.ACTION_DOWN
|
||||
event.setLocation(event.rawX, event.y)
|
||||
parentView?.dispatchTouchEvent(event)
|
||||
}
|
||||
passTouches = true
|
||||
parentView?.dispatchTouchEvent(event)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -35,8 +35,8 @@
|
|||
android:id="@+id/photo_brightness_controller"
|
||||
android:layout_width="@dimen/media_side_slider_width"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"/>
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/slide_info"
|
||||
|
@ -55,12 +55,12 @@
|
|||
android:textColor="@android:color/white"
|
||||
android:textSize="@dimen/extra_big_text_size"/>
|
||||
|
||||
<RelativeLayout
|
||||
<com.simplemobiletools.gallery.views.InstantItemSwitch
|
||||
android:id="@+id/instant_prev_item"
|
||||
android:layout_width="@dimen/instant_change_bar_width"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<RelativeLayout
|
||||
<com.simplemobiletools.gallery.views.InstantItemSwitch
|
||||
android:id="@+id/instant_next_item"
|
||||
android:layout_width="@dimen/instant_change_bar_width"
|
||||
android:layout_height="match_parent"
|
||||
|
|
Loading…
Reference in New Issue