diff --git a/app/src/main/java/com/gamedog/vididin/main/fragments/home/fragment/HomeItemFragment.kt b/app/src/main/java/com/gamedog/vididin/main/fragments/home/fragment/HomeItemFragment.kt index 26749f1..b0003fb 100644 --- a/app/src/main/java/com/gamedog/vididin/main/fragments/home/fragment/HomeItemFragment.kt +++ b/app/src/main/java/com/gamedog/vididin/main/fragments/home/fragment/HomeItemFragment.kt @@ -32,6 +32,8 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment() { private var mPlayer: YouTubePlayer? = null private var mVideoData: YoutubeVideo? = null private var mIsPlaying: Boolean = false + private var mCurPlayedSecond: Float = 0F + private var mTotalDuration: Float = -1F override fun inflateViewBinding( @@ -199,6 +201,17 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment() { } } + override fun onCurrentSecond(youTubePlayer: YouTubePlayer, second: Float) { + super.onCurrentSecond(youTubePlayer, second) + mCurPlayedSecond = second + updateProgressbar() + } + + override fun onVideoDuration(youTubePlayer: YouTubePlayer, duration: Float) { + super.onVideoDuration(youTubePlayer, duration) + mTotalDuration = duration + } + override fun onStateChange( youTubePlayer: YouTubePlayer, state: PlayerConstants.PlayerState @@ -242,6 +255,16 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment() { mPlayer?.pause() } + private fun updateProgressbar() { + with(binding?.progressBarPlayer!!) { + setMax(100) + if (mTotalDuration > 0) { + setProgress((100*mCurPlayedSecond/mTotalDuration).toInt()) + } + } + } + + private fun hidePlayIconAnim() { if (!binding?.playIcon!!.isVisible) { return diff --git a/app/src/main/res/layout/vididinapp_feature_home_item_layout.xml b/app/src/main/res/layout/vididinapp_feature_home_item_layout.xml index 546eb2a..b1b4607 100644 --- a/app/src/main/res/layout/vididinapp_feature_home_item_layout.xml +++ b/app/src/main/res/layout/vididinapp_feature_home_item_layout.xml @@ -155,4 +155,21 @@ + + + + \ No newline at end of file diff --git a/core/architecture/src/main/java/com/ama/core/architecture/widget/CustomProgressBar.kt b/core/architecture/src/main/java/com/ama/core/architecture/widget/CustomProgressBar.kt new file mode 100644 index 0000000..a78aa57 --- /dev/null +++ b/core/architecture/src/main/java/com/ama/core/architecture/widget/CustomProgressBar.kt @@ -0,0 +1,49 @@ +package com.ama.core.architecture.widget + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint +import android.util.AttributeSet +import android.view.View + +class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, attrs) { + + private var progress = 0 + private var max = 100 + + private val grayColor = Color.parseColor("#1affffff") + private val greenColor = Color.parseColor("#ff00ff09") + + + + private val paint = Paint().apply { + isAntiAlias = true + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + val width = measuredWidth.toFloat() + val height = measuredHeight.toFloat() + + paint.color = grayColor + canvas.drawRoundRect(0f, 0f, width, height, width/2, 0F, paint) + + val progressWidth = (width) * progress / max + if (progressWidth > 0) { + paint.color = greenColor + canvas.drawRoundRect(0f, 0f, progressWidth, height, width/2, 0F, paint) + } + } + + + fun setProgress(progress: Int) { + this.progress = progress.coerceIn(0, max) + invalidate() + } + + fun setMax(max: Int) { + this.max = max + invalidate() + } +} \ No newline at end of file