SeekOverlay: Add seek overlay logic to player
This commit is contained in:
parent
f7e7ebfbe0
commit
6252704bbc
8 changed files with 206 additions and 57 deletions
|
|
@ -11,7 +11,7 @@ import org.schabi.newpipe.player.event.DisplayPortion
|
|||
class CircleClipTapView(context: Context?, attrs: AttributeSet) : View(context, attrs) {
|
||||
|
||||
companion object {
|
||||
const val COLOR_DARK = 0x40000000
|
||||
const val COLOR_DARK = 0x45000000
|
||||
const val COLOR_DARK_TRANSPARENT = 0x30000000
|
||||
const val COLOR_LIGHT_TRANSPARENT = 0x25EEEEEE
|
||||
|
||||
|
|
|
|||
|
|
@ -5,24 +5,30 @@ import android.util.AttributeSet
|
|||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.annotation.*
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.annotation.DimenRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StyleRes
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.END
|
||||
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID
|
||||
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.START
|
||||
import androidx.constraintlayout.widget.ConstraintSet
|
||||
import androidx.constraintlayout.widget.ConstraintSet.*
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.widget.TextViewCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import kotlinx.android.synthetic.main.player_seek_overlay.view.*
|
||||
import org.schabi.newpipe.MainActivity
|
||||
import org.schabi.newpipe.R
|
||||
import org.schabi.newpipe.player.event.DisplayPortion
|
||||
import org.schabi.newpipe.player.event.DoubleTapListener
|
||||
|
||||
class PlayerSeekOverlay(context: Context?, private val attrs: AttributeSet?) :
|
||||
class PlayerSeekOverlay(context: Context, private val attrs: AttributeSet?) :
|
||||
ConstraintLayout(context, attrs), DoubleTapListener {
|
||||
|
||||
private var secondsView: SecondsView
|
||||
private var circleClipTapView: CircleClipTapView
|
||||
private var rootConstraintLayout: ConstraintLayout
|
||||
|
||||
private var isForwarding: Boolean? = null
|
||||
|
||||
|
|
@ -31,6 +37,7 @@ class PlayerSeekOverlay(context: Context?, private val attrs: AttributeSet?) :
|
|||
|
||||
secondsView = findViewById(R.id.seconds_view)
|
||||
circleClipTapView = findViewById(R.id.circle_clip_tap_view)
|
||||
rootConstraintLayout = findViewById(R.id.root_constraint_layout)
|
||||
|
||||
initializeAttributes()
|
||||
secondsView.isForward = true
|
||||
|
|
@ -161,11 +168,14 @@ class PlayerSeekOverlay(context: Context?, private val attrs: AttributeSet?) :
|
|||
val shouldForward: Boolean = performListener?.shouldFastForward(portion) ?: return
|
||||
|
||||
if (DEBUG)
|
||||
Log.d(TAG,"onDoubleTapProgressDown called with " +
|
||||
"shouldForward = [$shouldForward], " +
|
||||
"isForwarding = [$isForwarding], " +
|
||||
"secondsView#isForward = [${secondsView.isForward}], " +
|
||||
"initTap = [$initTap], ")
|
||||
Log.d(
|
||||
TAG,
|
||||
"onDoubleTapProgressDown called with " +
|
||||
"shouldForward = [$shouldForward], " +
|
||||
"isForwarding = [$isForwarding], " +
|
||||
"secondsView#isForward = [${secondsView.isForward}], " +
|
||||
"initTap = [$initTap], "
|
||||
)
|
||||
|
||||
// Using this check prevents from fast switching (one touches)
|
||||
if (isForwarding != null && isForwarding != shouldForward) {
|
||||
|
|
@ -234,18 +244,22 @@ class PlayerSeekOverlay(context: Context?, private val attrs: AttributeSet?) :
|
|||
private fun changeConstraints(forward: Boolean) {
|
||||
val constraintSet = ConstraintSet()
|
||||
with(constraintSet) {
|
||||
clone(root_constraint_layout)
|
||||
clone(rootConstraintLayout)
|
||||
if (forward) {
|
||||
clear(seconds_view.id, START)
|
||||
connect(seconds_view.id, END,
|
||||
PARENT_ID, END)
|
||||
clear(secondsView.id, START)
|
||||
connect(
|
||||
secondsView.id, END,
|
||||
PARENT_ID, END
|
||||
)
|
||||
} else {
|
||||
clear(seconds_view.id, END)
|
||||
connect(seconds_view.id, START,
|
||||
PARENT_ID, START)
|
||||
clear(secondsView.id, END)
|
||||
connect(
|
||||
secondsView.id, START,
|
||||
PARENT_ID, START
|
||||
)
|
||||
}
|
||||
secondsView.start()
|
||||
applyTo(root_constraint_layout)
|
||||
applyTo(rootConstraintLayout)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|||
import kotlinx.android.synthetic.main.player_seek_seconds_view.view.*
|
||||
import org.schabi.newpipe.R
|
||||
|
||||
class SecondsView(context: Context?, attrs: AttributeSet?) :
|
||||
class SecondsView(context: Context, attrs: AttributeSet?) :
|
||||
ConstraintLayout(context, attrs) {
|
||||
|
||||
companion object {
|
||||
|
|
@ -45,7 +45,6 @@ class SecondsView(context: Context?, attrs: AttributeSet?) :
|
|||
val textView: TextView
|
||||
get() = tv_seconds
|
||||
|
||||
|
||||
@DrawableRes
|
||||
var icon: Int = R.drawable.ic_play_seek_triangle
|
||||
set(value) {
|
||||
|
|
@ -87,9 +86,11 @@ class SecondsView(context: Context?, attrs: AttributeSet?) :
|
|||
icon_1.alpha = 0f
|
||||
icon_2.alpha = 0f
|
||||
icon_3.alpha = 0f
|
||||
}, {
|
||||
},
|
||||
{
|
||||
icon_1.alpha = it
|
||||
}, {
|
||||
},
|
||||
{
|
||||
secondAnimator.start()
|
||||
}
|
||||
)
|
||||
|
|
@ -99,9 +100,11 @@ class SecondsView(context: Context?, attrs: AttributeSet?) :
|
|||
icon_1.alpha = 1f
|
||||
icon_2.alpha = 0f
|
||||
icon_3.alpha = 0f
|
||||
}, {
|
||||
},
|
||||
{
|
||||
icon_2.alpha = it
|
||||
}, {
|
||||
},
|
||||
{
|
||||
thirdAnimator.start()
|
||||
}
|
||||
)
|
||||
|
|
@ -111,10 +114,12 @@ class SecondsView(context: Context?, attrs: AttributeSet?) :
|
|||
icon_1.alpha = 1f
|
||||
icon_2.alpha = 1f
|
||||
icon_3.alpha = 0f
|
||||
}, {
|
||||
},
|
||||
{
|
||||
icon_1.alpha = 1f - icon_3.alpha
|
||||
icon_3.alpha = it
|
||||
}, {
|
||||
},
|
||||
{
|
||||
fourthAnimator.start()
|
||||
}
|
||||
)
|
||||
|
|
@ -124,9 +129,11 @@ class SecondsView(context: Context?, attrs: AttributeSet?) :
|
|||
icon_1.alpha = 0f
|
||||
icon_2.alpha = 1f
|
||||
icon_3.alpha = 1f
|
||||
}, {
|
||||
},
|
||||
{
|
||||
icon_2.alpha = 1f - it
|
||||
}, {
|
||||
},
|
||||
{
|
||||
fifthAnimator.start()
|
||||
}
|
||||
)
|
||||
|
|
@ -136,16 +143,20 @@ class SecondsView(context: Context?, attrs: AttributeSet?) :
|
|||
icon_1.alpha = 0f
|
||||
icon_2.alpha = 0f
|
||||
icon_3.alpha = 1f
|
||||
}, {
|
||||
},
|
||||
{
|
||||
icon_3.alpha = 1f - it
|
||||
}, {
|
||||
},
|
||||
{
|
||||
firstAnimator.start()
|
||||
}
|
||||
)
|
||||
|
||||
private inner class CustomValueAnimator(
|
||||
start: () -> Unit, update: (value: Float) -> Unit, end: () -> Unit
|
||||
): ValueAnimator() {
|
||||
start: () -> Unit,
|
||||
update: (value: Float) -> Unit,
|
||||
end: () -> Unit
|
||||
) : ValueAnimator() {
|
||||
|
||||
init {
|
||||
duration = cycleDuration / 5
|
||||
|
|
@ -164,7 +175,6 @@ class SecondsView(context: Context?, attrs: AttributeSet?) :
|
|||
override fun onAnimationCancel(animation: Animator?) = Unit
|
||||
|
||||
override fun onAnimationRepeat(animation: Animator?) = Unit
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue