mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-03-13 15:20:26 +08:00
double tap delegate: cleanup
This commit is contained in:
@@ -13,7 +13,7 @@ import com.google.android.exoplayer2.ui.PlayerView
|
||||
/**
|
||||
* Custom player class for Double-Tapping listening
|
||||
*/
|
||||
open class DoubleTapDelegate(context: Context, val playerView: View) {
|
||||
class DoubleTapDelegate(context: Context, playerView: View) {
|
||||
private val gestureDetector: GestureDetectorCompat
|
||||
private val gestureListener: DoubleTapGestureListener = DoubleTapGestureListener(playerView.rootView)
|
||||
|
||||
@@ -24,8 +24,6 @@ open class DoubleTapDelegate(context: Context, val playerView: View) {
|
||||
field = value
|
||||
}
|
||||
|
||||
private var controllerRef: Int = -1
|
||||
|
||||
init {
|
||||
gestureDetector = GestureDetectorCompat(context, gestureListener)
|
||||
}
|
||||
@@ -87,22 +85,6 @@ open class DoubleTapDelegate(context: Context, val playerView: View) {
|
||||
return false
|
||||
}
|
||||
|
||||
fun onAttachedToWindow() {
|
||||
// If the PlayerView is set by XML then call the corresponding setter method
|
||||
if (controllerRef != -1) {
|
||||
try {
|
||||
val view: View = (playerView.parent as View).findViewById(controllerRef)
|
||||
if (view is PlayerDoubleTapListener) {
|
||||
controller(view)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Log.e("DoubleTapPlayerView",
|
||||
"controllerRef is either invalid or not PlayerDoubleTapListener: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gesture Listener for double tapping
|
||||
*
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.github.vkay94.dtpv.youtube.views.CircleClipTapView
|
||||
import com.github.vkay94.dtpv.youtube.views.SecondsView
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.ui.PlayerView
|
||||
import androidx.core.content.withStyledAttributes
|
||||
|
||||
|
||||
/**
|
||||
@@ -74,50 +75,57 @@ class YouTubeOverlay(context: Context, private val attrs: AttributeSet?) :
|
||||
*/
|
||||
private fun initializeAttributes() {
|
||||
if (attrs != null) {
|
||||
val a = context.obtainStyledAttributes(attrs,
|
||||
R.styleable.YouTubeOverlay, 0, 0)
|
||||
context.withStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.YouTubeOverlay, 0, 0
|
||||
) {
|
||||
|
||||
// PlayerView => see onAttachToWindow
|
||||
playerViewRef = a.getResourceId(R.styleable.YouTubeOverlay_yt_playerView, -1)
|
||||
// PlayerView => see onAttachToWindow
|
||||
playerViewRef = getResourceId(R.styleable.YouTubeOverlay_yt_playerView, -1)
|
||||
|
||||
// Durations
|
||||
animationDuration = a.getInt(
|
||||
R.styleable.YouTubeOverlay_yt_animationDuration, 650).toLong()
|
||||
// Durations
|
||||
animationDuration = getInt(
|
||||
R.styleable.YouTubeOverlay_yt_animationDuration, 650
|
||||
).toLong()
|
||||
|
||||
seekSeconds = a.getInt(
|
||||
R.styleable.YouTubeOverlay_yt_seekSeconds, 10)
|
||||
seekSeconds = getInt(
|
||||
R.styleable.YouTubeOverlay_yt_seekSeconds, 10
|
||||
)
|
||||
|
||||
iconAnimationDuration = a.getInt(
|
||||
R.styleable.YouTubeOverlay_yt_iconAnimationDuration, 750).toLong()
|
||||
iconAnimationDuration = getInt(
|
||||
R.styleable.YouTubeOverlay_yt_iconAnimationDuration, 750
|
||||
).toLong()
|
||||
|
||||
// Arc size
|
||||
arcSize = a.getDimensionPixelSize(
|
||||
R.styleable.YouTubeOverlay_yt_arcSize,
|
||||
context.resources.getDimensionPixelSize(R.dimen.dtpv_yt_arc_size)).toFloat()
|
||||
// Arc size
|
||||
arcSize = getDimensionPixelSize(
|
||||
R.styleable.YouTubeOverlay_yt_arcSize,
|
||||
context.resources.getDimensionPixelSize(R.dimen.dtpv_yt_arc_size)
|
||||
).toFloat()
|
||||
|
||||
// Colors
|
||||
tapCircleColor = a.getColor(
|
||||
R.styleable.YouTubeOverlay_yt_tapCircleColor,
|
||||
ContextCompat.getColor(context, R.color.dtpv_yt_tap_circle_color)
|
||||
)
|
||||
// Colors
|
||||
tapCircleColor = getColor(
|
||||
R.styleable.YouTubeOverlay_yt_tapCircleColor,
|
||||
ContextCompat.getColor(context, R.color.dtpv_yt_tap_circle_color)
|
||||
)
|
||||
|
||||
circleBackgroundColor = a.getColor(
|
||||
R.styleable.YouTubeOverlay_yt_backgroundCircleColor,
|
||||
ContextCompat.getColor(context, R.color.dtpv_yt_background_circle_color)
|
||||
)
|
||||
circleBackgroundColor = getColor(
|
||||
R.styleable.YouTubeOverlay_yt_backgroundCircleColor,
|
||||
ContextCompat.getColor(context, R.color.dtpv_yt_background_circle_color)
|
||||
)
|
||||
|
||||
// Seconds TextAppearance
|
||||
textAppearance = a.getResourceId(
|
||||
R.styleable.YouTubeOverlay_yt_textAppearance,
|
||||
R.style.YTOSecondsTextAppearance)
|
||||
// Seconds TextAppearance
|
||||
textAppearance = getResourceId(
|
||||
R.styleable.YouTubeOverlay_yt_textAppearance,
|
||||
R.style.YTOSecondsTextAppearance
|
||||
)
|
||||
|
||||
// Seconds icon
|
||||
icon = a.getResourceId(
|
||||
R.styleable.YouTubeOverlay_yt_icon,
|
||||
R.drawable.ic_play_triangle
|
||||
)
|
||||
// Seconds icon
|
||||
icon = getResourceId(
|
||||
R.styleable.YouTubeOverlay_yt_icon,
|
||||
R.drawable.ic_play_triangle
|
||||
)
|
||||
|
||||
a.recycle()
|
||||
}
|
||||
|
||||
} else {
|
||||
// Set defaults
|
||||
|
||||
Reference in New Issue
Block a user