diff --git a/app/src/main/kotlin/org/fossify/voicerecorder/views/PlayerSeekBar.kt b/app/src/main/kotlin/org/fossify/voicerecorder/views/PlayerSeekBar.kt new file mode 100644 index 000000000..cd79f392f --- /dev/null +++ b/app/src/main/kotlin/org/fossify/voicerecorder/views/PlayerSeekBar.kt @@ -0,0 +1,48 @@ +package org.fossify.voicerecorder.views + +import android.content.Context +import android.util.AttributeSet +import android.view.MotionEvent +import org.fossify.commons.views.MySeekBar + +class PlayerSeekBar : MySeekBar { + private var isParentInterceptionDisallowed = false + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + + constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) + + override fun onTouchEvent(event: MotionEvent): Boolean { + val action = event.actionMasked + if (action == MotionEvent.ACTION_DOWN) { + setParentInterceptionDisallowed(true) + } + + val handled = super.onTouchEvent(event) + if (action == MotionEvent.ACTION_UP && handled) { + performClick() + } + + if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || !handled) { + setParentInterceptionDisallowed(false) + } + + return handled + } + + override fun performClick() = super.performClick() + + override fun onDetachedFromWindow() { + setParentInterceptionDisallowed(false) + super.onDetachedFromWindow() + } + + private fun setParentInterceptionDisallowed(disallowed: Boolean) { + if (isParentInterceptionDisallowed != disallowed) { + parent?.requestDisallowInterceptTouchEvent(disallowed) + isParentInterceptionDisallowed = disallowed + } + } +} diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 195911fc5..344c6aec1 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -90,7 +90,7 @@ android:paddingEnd="@dimen/medium_margin" android:text="00:00" /> -