improving the UX at some video gestures

This commit is contained in:
tibbi 2019-01-04 11:44:13 +01:00
parent 80d3bf4cea
commit 4957baf8e2

View file

@ -26,6 +26,7 @@ import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.isPiePlus import com.simplemobiletools.commons.helpers.isPiePlus
import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.extensions.* import com.simplemobiletools.gallery.pro.extensions.*
import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DURATION
import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD
import com.simplemobiletools.gallery.pro.helpers.MIN_SKIP_LENGTH import com.simplemobiletools.gallery.pro.helpers.MIN_SKIP_LENGTH
import kotlinx.android.synthetic.main.activity_video_player.* import kotlinx.android.synthetic.main.activity_video_player.*
@ -51,6 +52,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
private var mTouchDownX = 0f private var mTouchDownX = 0f
private var mTouchDownY = 0f private var mTouchDownY = 0f
private var mTouchDownTime = 0L
private var mProgressAtDown = 0L private var mProgressAtDown = 0L
private var mCloseDownThreshold = 100f private var mCloseDownThreshold = 100f
private var mIgnoreCloseDown = false private var mIgnoreCloseDown = false
@ -144,32 +146,22 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
fullscreenToggled(isFullscreen) fullscreenToggled(isFullscreen)
} }
// adding an empty click listener just to avoid ripple animation at toggling fullscreen
video_seekbar.setOnClickListener { }
video_curr_time.setOnClickListener { skip(false) } video_curr_time.setOnClickListener { skip(false) }
video_duration.setOnClickListener { skip(true) } video_duration.setOnClickListener { skip(true) }
video_toggle_play_pause.setOnClickListener { togglePlayPause() } video_toggle_play_pause.setOnClickListener { togglePlayPause() }
video_player_holder.setOnClickListener {
fullscreenToggled(!mIsFullscreen) video_player_holder.setOnTouchListener { view, event ->
handleEvent(event)
true
} }
if (config.allowDownGesture) { video_surface.setOnTouchListener { view, event ->
video_player_holder.setOnTouchListener { v, event -> handleEvent(event)
handleEvent(event) true
false
}
video_surface.setOnTouchListener { v, event ->
handleEvent(event)
false
}
} }
initExoPlayer() initExoPlayer()
video_surface.surfaceTextureListener = this video_surface.surfaceTextureListener = this
video_surface.setOnClickListener {
fullscreenToggled(!mIsFullscreen)
}
if (config.allowVideoGestures) { if (config.allowVideoGestures) {
video_brightness_controller.initialize(this, slide_info, true, video_player_holder) { x, y -> video_brightness_controller.initialize(this, slide_info, true, video_player_holder) { x, y ->
@ -470,6 +462,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
mTouchDownX = event.x mTouchDownX = event.x
mTouchDownY = event.y mTouchDownY = event.y
mTouchDownTime = System.currentTimeMillis()
mProgressAtDown = mExoPlayer!!.currentPosition mProgressAtDown = mExoPlayer!!.currentPosition
} }
MotionEvent.ACTION_POINTER_DOWN -> mIgnoreCloseDown = true MotionEvent.ACTION_POINTER_DOWN -> mIgnoreCloseDown = true
@ -500,9 +493,10 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
val diffX = mTouchDownX - event.x val diffX = mTouchDownX - event.x
val diffY = mTouchDownY - event.y val diffY = mTouchDownY - event.y
if (!mIgnoreCloseDown && Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold) { if (config.allowDownGesture && !mIgnoreCloseDown && Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold) {
supportFinishAfterTransition() supportFinishAfterTransition()
} }
mIgnoreCloseDown = false mIgnoreCloseDown = false
if (mIsDragged) { if (mIsDragged) {
if (mIsFullscreen) { if (mIsFullscreen) {
@ -514,6 +508,10 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
if (!mIsPlaying) { if (!mIsPlaying) {
togglePlayPause() togglePlayPause()
} }
} else {
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
fullscreenToggled(!mIsFullscreen)
}
} }
mIsDragged = false mIsDragged = false
} }