From ae8433d8bd930c89e9afca3bb6ad73fef3d9cfd4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BC=A0=E7=8E=89=E4=B9=85?= <1484288157@qq.com>
Date: Thu, 28 Jan 2021 14:45:14 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A6=96=E9=A1=B5=E6=B8=B8?=
=?UTF-8?q?=E6=88=8F=E9=81=AE=E7=BD=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/gh/common/view/RadiusCardView.kt | 54 +++++++++++++
.../gh/gamecenter/home/HomeFragmentAdapter.kt | 24 ++----
.../gamecenter/home/HomeGameItemViewHolder.kt | 1 -
.../home/video/AutomaticVideoView.kt | 81 ++++++++++++++++---
.../main/res/layout/empty_control_video.xml | 27 ++-----
app/src/main/res/layout/home_game_item.xml | 32 ++++----
app/src/main/res/values/attrs.xml | 6 ++
7 files changed, 160 insertions(+), 65 deletions(-)
create mode 100644 app/src/main/java/com/gh/common/view/RadiusCardView.kt
diff --git a/app/src/main/java/com/gh/common/view/RadiusCardView.kt b/app/src/main/java/com/gh/common/view/RadiusCardView.kt
new file mode 100644
index 0000000000..bda6ba1b0b
--- /dev/null
+++ b/app/src/main/java/com/gh/common/view/RadiusCardView.kt
@@ -0,0 +1,54 @@
+package com.gh.common.view
+
+import android.annotation.SuppressLint
+import android.content.Context
+import android.graphics.*
+import android.graphics.drawable.ColorDrawable
+import android.util.AttributeSet
+import androidx.cardview.widget.CardView
+import com.gh.common.util.dip2px
+import com.gh.gamecenter.R
+
+class RadiusCardView : CardView {
+ var topLeftRadius = 0f
+ var topRightRadius = 0f
+ var bottomLeftRadius = 0f
+ var bottomRightRadius = 0f
+
+ constructor(context: Context) : this(context, null)
+ constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
+ constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
+ radius = 0f
+ val array = context.obtainStyledAttributes(attrs, R.styleable.RadiusCardView)
+ topLeftRadius = array.getDimensionPixelSize(R.styleable.RadiusCardView_topLeftRadius, 0).toFloat()
+ topRightRadius = array.getDimensionPixelSize(R.styleable.RadiusCardView_topRightRadius, 0).toFloat()
+ bottomLeftRadius = array.getDimensionPixelSize(R.styleable.RadiusCardView_bottomLeftRadius, 0).toFloat()
+ bottomRightRadius = array.getDimensionPixelSize(R.styleable.RadiusCardView_bottomRightRadius, 0).toFloat()
+ background = ColorDrawable()
+ array.recycle()
+ }
+
+ @SuppressLint("DrawAllocation")
+ override fun onDraw(canvas: Canvas?) {
+ val path = Path()
+ val rectF: RectF = getRectF()
+ val radius = floatArrayOf(topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomLeftRadius, bottomLeftRadius, bottomLeftRadius, bottomLeftRadius)
+ path.addRoundRect(rectF, radius, Path.Direction.CW)
+ canvas?.clipPath(path, Region.Op.INTERSECT)
+ super.onDraw(canvas)
+ }
+
+ fun setRadius(tLRadius: Float, tRRadius: Float, bLRadius: Float, bRRadius: Float) {
+ topLeftRadius = tLRadius.dip2px().toFloat()
+ topRightRadius = tRRadius.dip2px().toFloat()
+ bottomLeftRadius = bLRadius.dip2px().toFloat()
+ bottomRightRadius = bRRadius.dip2px().toFloat()
+ invalidate()
+ }
+
+ private fun getRectF(): RectF {
+ val rect = Rect()
+ getDrawingRect(rect)
+ return RectF(rect)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/gh/gamecenter/home/HomeFragmentAdapter.kt b/app/src/main/java/com/gh/gamecenter/home/HomeFragmentAdapter.kt
index 3dd2574ef4..7fdef160be 100644
--- a/app/src/main/java/com/gh/gamecenter/home/HomeFragmentAdapter.kt
+++ b/app/src/main/java/com/gh/gamecenter/home/HomeFragmentAdapter.kt
@@ -2,10 +2,8 @@ package com.gh.gamecenter.home
import android.content.Context
import android.graphics.Color
-import android.graphics.drawable.ColorDrawable
import android.view.View
import android.view.ViewGroup
-import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.gh.common.constant.ItemViewType
@@ -14,6 +12,7 @@ import com.gh.common.exposure.ExposureSource
import com.gh.common.exposure.ExposureType
import com.gh.common.exposure.IExposable
import com.gh.common.util.*
+import com.gh.common.view.DrawableView
import com.gh.gamecenter.AboutActivity
import com.gh.gamecenter.GameDetailActivity
import com.gh.gamecenter.R
@@ -190,8 +189,8 @@ class HomeFragmentAdapter(context: Context,
eTrace = null,
event = ExposureType.EXPOSURE)
- holder.binding.gameImage.goneIf(homeItemData.attachGame?.displayContent == "video" && homeItemData.attachGame?.linkGame?.topVideo != null)
- holder.binding.gameBrief.goneIf(homeItemData.attachGame?.displayContent == "video" && homeItemData.attachGame?.linkGame?.topVideo != null)
+ holder.binding.gameBrief.text = homeItemData.attachGame?.recommendText
+ holder.binding.gameImage.visibleIf(!(homeItemData.attachGame?.displayContent == "video" && homeItemData.attachGame?.linkGame?.topVideo != null))
holder.binding.autoVideoView.goneIf(homeItemData.attachGame?.displayContent != "video" || homeItemData.attachGame?.linkGame?.topVideo == null)
if (!holder.binding.autoVideoView.isInPlayingState
&& homeItemData.attachGame?.displayContent == "video"
@@ -209,23 +208,12 @@ class HomeFragmentAdapter(context: Context,
.setShowFullAnimation(false)
.build(holder.binding.autoVideoView)
holder.binding.autoVideoView.updateThumb(topVideo?.poster ?: "")
- holder.binding.autoVideoView.setGameEntity(homeItemData.attachGame?.linkGame)
- if (!homeSetting?.placeholderColor.isNullOrEmpty()) {
- try {
- holder.binding.autoVideoView.detailBtn.background = ColorDrawable(Color.parseColor(game.homeSetting.placeholderColor))
- } catch (e: Exception) {
- val color = RandomUtils.getRandomPlaceholderColor()
- holder.binding.autoVideoView.detailBtn.setBackgroundColor(ContextCompat.getColor(holder.itemView.context, color))
- }
- } else {
- val color = RandomUtils.getRandomPlaceholderColor()
- holder.binding.autoVideoView.detailBtn.setBackgroundColor(ContextCompat.getColor(holder.itemView.context, color))
- }
- holder.binding.autoVideoView.detailBtn.setOnClickListener {
+ holder.binding.autoVideoView.setData(homeItemData.attachGame?.linkGame,homeSetting?.placeholderColor)
+ holder.binding.autoVideoView.detailBtn?.setOnClickListener {
holder.itemView.performClick()
holder.binding.autoVideoView.uploadVideoStreamingPlaying("点击遮罩")
}
- holder.binding.autoVideoView.setOnclickListener(View.OnClickListener { holder.itemView.performClick() })
+ holder.binding.autoVideoView.setOnVideoClickListener(View.OnClickListener { holder.itemView.performClick() })
}
holder.binding.gameImage.setOnClickListener {
diff --git a/app/src/main/java/com/gh/gamecenter/home/HomeGameItemViewHolder.kt b/app/src/main/java/com/gh/gamecenter/home/HomeGameItemViewHolder.kt
index 4470fdb00a..377bc90e54 100644
--- a/app/src/main/java/com/gh/gamecenter/home/HomeGameItemViewHolder.kt
+++ b/app/src/main/java/com/gh/gamecenter/home/HomeGameItemViewHolder.kt
@@ -13,7 +13,6 @@ class HomeGameItemViewHolder(val binding: HomeGameItemBinding) : BaseRecyclerVie
fun bindGame(game: GameEntity) {
binding.data = game
- binding.gameBrief.text = game.brief
binding.gameTags.postDelayed({
binding.gameTags.visibility = if (game.tagStyle.isNotEmpty()) {
diff --git a/app/src/main/java/com/gh/gamecenter/home/video/AutomaticVideoView.kt b/app/src/main/java/com/gh/gamecenter/home/video/AutomaticVideoView.kt
index a31e4a1cb2..9a4f640af5 100644
--- a/app/src/main/java/com/gh/gamecenter/home/video/AutomaticVideoView.kt
+++ b/app/src/main/java/com/gh/gamecenter/home/video/AutomaticVideoView.kt
@@ -1,15 +1,22 @@
package com.gh.gamecenter.home.video
+import android.animation.AnimatorSet
+import android.animation.ValueAnimator
import android.content.Context
+import android.graphics.Color
import android.util.AttributeSet
import android.view.Surface
import android.view.View
+import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
+import androidx.constraintlayout.widget.ConstraintLayout
import com.gh.common.constant.Constants
import com.gh.common.runOnIoThread
import com.gh.common.runOnUiThread
import com.gh.common.util.*
+import com.gh.common.view.DrawableView
+import com.gh.common.view.RadiusCardView
import com.gh.download.cache.ExoCacheManager
import com.gh.gamecenter.R
import com.gh.gamecenter.entity.GameEntity
@@ -18,26 +25,28 @@ import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
import com.shuyu.gsyvideoplayer.video.base.GSYVideoViewBridge
import com.squareup.picasso.Picasso
import io.reactivex.disposables.Disposable
-import moe.codeest.enviews.ENDownloadView
import java.util.*
class AutomaticVideoView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : StandardGSYVideoPlayer(context, attrs) {
var thumbImage: ImageView = findViewById(R.id.thumbImage)
- var detailBtn: TextView = findViewById(R.id.detailBtn)
+ var containerView: RadiusCardView = findViewById(R.id.container)
+ var detailBtn: TextView? = null
private var mMuteDisposable: Disposable? = null
private var mMaskDisposable: Disposable? = null
private val mUUID = UUID.randomUUID().toString()
private var shouldShowMask = true
private var mContentLength = 0.0
private var gameEntity: GameEntity? = null
+ private var placeholderColor: String? = null
private var mClickListener: OnClickListener? = null
override fun getLayoutId(): Int {
return R.layout.empty_control_video
}
- fun setGameEntity(entity: GameEntity?) {
+ fun setData(entity: GameEntity?, color: String?) {
gameEntity = entity
+ placeholderColor = color
}
fun startPlayLogic(showMask: Boolean) {
@@ -84,25 +93,73 @@ class AutomaticVideoView @JvmOverloads constructor(context: Context, attrs: Attr
}
private fun showDetailMask() {
+ detailBtn = (parent as ViewGroup).findViewById(R.id.detailBtn)
if (mMaskDisposable != null) {
mMaskDisposable?.dispose()
mMaskDisposable = null
}
+ setDetailMaskBackground()
mMaskDisposable = countDownTimer(5) { finish, _ ->
if (finish) {
val offset = 44f.dip2px().toFloat()
- detailBtn.translationY = offset
- detailBtn.alpha = 0f
- detailBtn.visibility = View.VISIBLE
- detailBtn.animate().translationY(0f).alpha(1f).setDuration(800).doOnEnd {
- uploadVideoStreamingPlaying("出现遮罩")
- }.start()
+ containerView.setRadius(6f, 6f, 0f, 0f)
+
+ detailBtn?.let { mask ->
+ var params = mask.layoutParams as ConstraintLayout.LayoutParams
+ params.height = 0
+ mask.layoutParams = params
+ mask.alpha = 0f
+ mask.visibility = View.VISIBLE
+ val heightAnimator = ValueAnimator.ofFloat(0f, offset).apply {
+ addUpdateListener {
+ params = mask.layoutParams as ConstraintLayout.LayoutParams
+ params.height = (it.animatedValue as Float).toInt()
+ mask.layoutParams = params
+ }
+ }
+ val alphaAnimator = ValueAnimator.ofFloat(0f, 1F).apply {
+ addUpdateListener {
+ mask.alpha = it.animatedValue as Float
+ }
+ }
+ val animatorSet = AnimatorSet()
+ animatorSet.playTogether(heightAnimator, alphaAnimator)
+ animatorSet.duration = 800L
+ animatorSet.doOnEnd {
+ uploadVideoStreamingPlaying("出现遮罩")
+ }
+ animatorSet.start()
+ }
}
}
}
+ private fun setDetailMaskBackground() {
+ if (!placeholderColor.isNullOrEmpty()) {
+ try {
+ //去掉透明度
+ val color = if (placeholderColor!!.length == 9) {
+ "#${placeholderColor!!.substring(3)}"
+ } else {
+ placeholderColor
+ }
+ val drawable = DrawableView.getCornerDrawable(Color.parseColor(color), 0f, 0f, 6f, 6f)
+ detailBtn?.background = drawable
+ } catch (e: Exception) {
+ val color = RandomUtils.getRandomPlaceholderColor()
+ val drawable = DrawableView.getCornerDrawable(color, 0f, 0f, 6f, 6f)
+ detailBtn?.background = drawable
+ }
+ } else {
+ val color = RandomUtils.getRandomPlaceholderColor()
+ val drawable = DrawableView.getCornerDrawable(color, 0f, 0f, 6f, 6f)
+ detailBtn?.background = drawable
+ }
+ }
+
fun resetDetailMask() {
- detailBtn.visibility = View.GONE
+ detailBtn?.visibility = View.GONE
+ containerView.setRadius(6f, 6f, 6f, 6f)
if (mMaskDisposable != null && !mMaskDisposable!!.isDisposed) {
mMaskDisposable?.dispose()
mMaskDisposable = null
@@ -184,7 +241,7 @@ class AutomaticVideoView @JvmOverloads constructor(context: Context, attrs: Attr
resetDetailMask()
}
- fun setOnclickListener(listener: OnClickListener) {
+ fun setOnVideoClickListener(listener: OnClickListener) {
mClickListener = listener
}
@@ -207,7 +264,7 @@ class AutomaticVideoView @JvmOverloads constructor(context: Context, attrs: Attr
//https://exoplayer.dev/hello-world.html#a-note-on-threading
runOnUiThread {
- LogUtils.uploadHomeVideoStreamingPlaying(action, detailBtn.visibility == View.VISIBLE, topVideo.id, topVideo.title,
+ LogUtils.uploadHomeVideoStreamingPlaying(action, detailBtn?.visibility == View.VISIBLE, topVideo.id, topVideo.title,
gameEntity?.id, gameEntity?.name, mContentLength, videoTotalTime, videoPlayTs, progress.toInt())
}
}
diff --git a/app/src/main/res/layout/empty_control_video.xml b/app/src/main/res/layout/empty_control_video.xml
index 12b4c59ade..84589f6444 100644
--- a/app/src/main/res/layout/empty_control_video.xml
+++ b/app/src/main/res/layout/empty_control_video.xml
@@ -1,10 +1,14 @@
-
-
-
-
+
diff --git a/app/src/main/res/layout/home_game_item.xml b/app/src/main/res/layout/home_game_item.xml
index 06dca0fe98..bf4832ec74 100644
--- a/app/src/main/res/layout/home_game_item.xml
+++ b/app/src/main/res/layout/home_game_item.xml
@@ -17,8 +17,7 @@
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingTop="11dp"
- android:paddingRight="16dp"
- android:paddingBottom="16dp">
+ android:paddingRight="16dp">
-
+
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
index 67141bdf81..42d149c43d 100644
--- a/app/src/main/res/values/attrs.xml
+++ b/app/src/main/res/values/attrs.xml
@@ -150,4 +150,10 @@
+
+
+
+
+
+
\ No newline at end of file