|
@@ -20,8 +20,10 @@ import com.swago.baseswago.model.live.pk.ProcessPKModel
|
|
|
import com.swago.baseswago.model.live.pk.PunishPKModel
|
|
|
import com.swago.baseswago.model.live.pk.StartPKModel
|
|
|
import com.swago.baseswago.model.live.pk.StopPKModel
|
|
|
+import com.swago.baseswago.util.AppContext
|
|
|
import com.swago.baseswago.util.DpPxUtil
|
|
|
import com.swago.baseswago.util.TimeUtil
|
|
|
+import com.swago.loadUrl
|
|
|
import com.swago.room.R
|
|
|
import com.swago.room.databinding.LayoutPkViewBinding
|
|
|
import java.io.File
|
|
@@ -31,6 +33,7 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
|
|
|
private var binding:LayoutPkViewBinding? = null
|
|
|
private var svgParser:SVGAParser? = null
|
|
|
+ private var svgParserProgress:SVGAParser? = null
|
|
|
private var mProgress = 50
|
|
|
private val selfAdapter by lazy {
|
|
|
PKAudienceAdapter()
|
|
@@ -43,6 +46,11 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
|
|
|
var pkResult = 3
|
|
|
|
|
|
+ private var pkEndTime = 0
|
|
|
+
|
|
|
+ //主播获取PK信息
|
|
|
+ var doGetPKInfoFun:(()->Unit)? = null
|
|
|
+
|
|
|
constructor(context: Context) : this(context, null)
|
|
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
|
|
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
|
|
@@ -59,6 +67,8 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
PKStateManager.addPKListener(this)
|
|
|
RoomTimer.timeTickList.add(this)
|
|
|
svgParser = SVGAParser(context)
|
|
|
+ svgParserProgress = SVGAParser(context)
|
|
|
+ playProgress("laugh.svga")
|
|
|
binding?.let {
|
|
|
it.rvSelf.layoutManager = LinearLayoutManager(context)
|
|
|
it.rvSelf.adapter = selfAdapter
|
|
@@ -74,10 +84,23 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun initProgressPosition(){
|
|
|
+ binding?.apply {
|
|
|
+ val svgProcessLayoutParams = ConstraintLayout.LayoutParams(DpPxUtil.dip2px(20f),DpPxUtil.dip2px(20f))
|
|
|
+ svgProcessLayoutParams.startToStart = R.id.view
|
|
|
+ svgProcessLayoutParams.topToBottom = R.id.view
|
|
|
+ svgProcessLayoutParams.topMargin = DpPxUtil.dip2px(-3f)
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/2
|
|
|
+ svgProgress.layoutParams = svgProcessLayoutParams
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
override fun changeRoom(iRoomInfo: IRoomInfo) {
|
|
|
}
|
|
|
|
|
|
override fun leaveRoom(iRoomInfo: IRoomInfo) {
|
|
|
+ visibility = View.GONE
|
|
|
resetSvg()
|
|
|
resetData()
|
|
|
}
|
|
@@ -95,16 +118,31 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
PKStateManager.removePKListener(this)
|
|
|
}
|
|
|
|
|
|
+ private var startPKModel:StartPKModel? = null
|
|
|
+
|
|
|
override fun startPK(startPKModel: StartPKModel,isGetDataFromIM:Boolean) {
|
|
|
binding?.apply {
|
|
|
+ this@PKLayoutView.startPKModel = startPKModel
|
|
|
+ pkEndTime = startPKModel.pkEndTime-startPKModel.pkResultTime
|
|
|
+ if (isGetDataFromIM){
|
|
|
+ initProgressPosition()
|
|
|
+ }
|
|
|
+ tvSelf.text = "0"
|
|
|
+ tvPeer.text = "0"
|
|
|
visibility = View.VISIBLE
|
|
|
pkTime = startPKModel.pkResultTime
|
|
|
tvPkTime.text = TimeUtil.convertMinSecond(pkTime.toLong())
|
|
|
- playProgress("file:///android_asset/progress.svga",2)
|
|
|
+ playProgress("progress.svga")
|
|
|
clPKTime.visibility = View.VISIBLE
|
|
|
clPunishTime.visibility = View.GONE
|
|
|
+ tvPeerName.text = startPKModel.oppositeName
|
|
|
+ tvPeerId.text = AppContext.getContext().resources.getString(R.string.id_x).format(startPKModel.oppositeUserId)
|
|
|
+ try {
|
|
|
+ ivPeerAvatar.loadUrl(context,startPKModel.oppositeAvatar)
|
|
|
+ }catch (e:Exception){
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
override fun stopPK(stopPKModel: StopPKModel) {
|
|
@@ -114,30 +152,41 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
|
|
|
override fun punishPK(punishPKModel: PunishPKModel,isGetDataFromIM:Boolean) {
|
|
|
binding?.apply {
|
|
|
+ if (!isGetDataFromIM){
|
|
|
+ ivPeerAvatar.loadUrl(context,punishPKModel.oppositeAvatar)
|
|
|
+ tvPeerName.text = punishPKModel.oppositeName
|
|
|
+ tvPeerId.text = AppContext.getContext().resources.getString(R.string.id_x).format(punishPKModel.oppositeUserId)
|
|
|
+ }else{
|
|
|
+ startPKModel?.let {
|
|
|
+ pkTime = it.pkEndTime - it.pkResultTime
|
|
|
+ }
|
|
|
+ }
|
|
|
visibility = View.VISIBLE
|
|
|
clPKTime.visibility = View.GONE
|
|
|
clPunishTime.visibility = View.VISIBLE
|
|
|
if (svgProgress.isAnimating){
|
|
|
svgProgress.stopAnimation()
|
|
|
}
|
|
|
- // 1赢 2输 3平局
|
|
|
+ // 3赢 4输 5平局
|
|
|
pkResult =punishPKModel.roomResult
|
|
|
when(punishPKModel.roomResult){
|
|
|
- 1 -> {
|
|
|
- playProgress("file:///android_asset/pk_win.svga",1)
|
|
|
+ 3 -> {
|
|
|
+ playPKResultSvg("pk_win.svga")
|
|
|
+ playProgress("laugh.svga")
|
|
|
}
|
|
|
- 2 -> {
|
|
|
- playProgress("file:///android_asset/pk_fail.svga",1)
|
|
|
+ 4 -> {
|
|
|
+ playPKResultSvg("pk_fail.svga")
|
|
|
+ playProgress("cry.svga")
|
|
|
}
|
|
|
- 3 -> {
|
|
|
- playProgress("file:///android_asset/pk_balance.svga",1)
|
|
|
+ 5 -> {
|
|
|
+ playPKResultSvg("pk_balance.svga")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override fun processChangePK(processPKModel: ProcessPKModel) {
|
|
|
+ override fun processChangePK(processPKModel: ProcessPKModel,isGetDataFromIM: Boolean) {
|
|
|
binding?.apply {
|
|
|
if (processPKModel.roomAudienceList.isNotEmpty()){
|
|
|
selfAdapter.setNewData(processPKModel.roomAudienceList)
|
|
@@ -145,14 +194,17 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
if (processPKModel.oppositeRoomAudienceList.isNotEmpty()){
|
|
|
peerAdapter.setNewData(processPKModel.oppositeRoomAudienceList)
|
|
|
}
|
|
|
-
|
|
|
- if (tvSelf.text.toString().toInt() < processPKModel.progressValue || tvPeer.text.toString().toInt() < processPKModel.oppositeProgressValue) {
|
|
|
+ if (!isGetDataFromIM){
|
|
|
tvSelf.text = processPKModel.progressValue.toString()
|
|
|
tvPeer.text = processPKModel.oppositeProgressValue.toString()
|
|
|
- } else {
|
|
|
- return
|
|
|
+ }else{
|
|
|
+ if (tvSelf.text.toString().toInt() < processPKModel.progressValue || tvPeer.text.toString().toInt() < processPKModel.oppositeProgressValue) {
|
|
|
+ tvSelf.text = processPKModel.progressValue.toString()
|
|
|
+ tvPeer.text = processPKModel.oppositeProgressValue.toString()
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
val selfProgressValue = if (processPKModel.progressValue == 0) {
|
|
|
0.01
|
|
|
} else {
|
|
@@ -177,11 +229,74 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
progressBar.progress = mProgress
|
|
|
|
|
|
|
|
|
- val svgProcessLayoutParams = ConstraintLayout.LayoutParams(WRAP_CONTENT,DpPxUtil.dip2px(15f))
|
|
|
- svgProcessLayoutParams.startToStart = R.id.svgProgress
|
|
|
- svgProcessLayoutParams.topToTop = R.id.svgProgress
|
|
|
- svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/100*mProgress
|
|
|
- svgProgress.layoutParams = svgProcessLayoutParams
|
|
|
+ if (isGetDataFromIM){
|
|
|
+ if (processPKModel.progressValue == 0&&processPKModel.oppositeProgressValue != 0){
|
|
|
+ val svgProcessLayoutParams = ConstraintLayout.LayoutParams(DpPxUtil.dip2px(20f),DpPxUtil.dip2px(20f))
|
|
|
+ svgProcessLayoutParams.startToStart = R.id.view
|
|
|
+ svgProcessLayoutParams.topToBottom = R.id.view
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/10 - DpPxUtil.dip2px(10f)
|
|
|
+ svgProcessLayoutParams.topMargin = DpPxUtil.dip2px(-3f)
|
|
|
+ svgProgress.layoutParams = svgProcessLayoutParams
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (processPKModel.oppositeProgressValue == 0&&processPKModel.progressValue != 0){
|
|
|
+ val svgProcessLayoutParams = ConstraintLayout.LayoutParams(DpPxUtil.dip2px(20f),DpPxUtil.dip2px(20f))
|
|
|
+ svgProcessLayoutParams.startToStart = R.id.view
|
|
|
+ svgProcessLayoutParams.topToBottom = R.id.view
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/10*9 - DpPxUtil.dip2px(10f)
|
|
|
+ svgProcessLayoutParams.topMargin = DpPxUtil.dip2px(-3f)
|
|
|
+ svgProgress.layoutParams = svgProcessLayoutParams
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ val svgProcessLayoutParams = ConstraintLayout.LayoutParams(DpPxUtil.dip2px(20f),DpPxUtil.dip2px(20f))
|
|
|
+ svgProcessLayoutParams.startToStart = R.id.view
|
|
|
+ svgProcessLayoutParams.topToBottom = R.id.view
|
|
|
+ if (mProgress>50){
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/100*mProgress + DpPxUtil.dip2px(10f)
|
|
|
+ }else if(mProgress<50){
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/100*mProgress - DpPxUtil.dip2px(10f)
|
|
|
+ }else{
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/100*mProgress
|
|
|
+ }
|
|
|
+
|
|
|
+ svgProcessLayoutParams.topMargin = DpPxUtil.dip2px(-3f)
|
|
|
+ svgProgress.layoutParams = svgProcessLayoutParams
|
|
|
+ }else{
|
|
|
+ if (processPKModel.progressValue == 0&&processPKModel.oppositeProgressValue != 0){
|
|
|
+ val svgProcessLayoutParams = ConstraintLayout.LayoutParams(DpPxUtil.dip2px(20f),DpPxUtil.dip2px(20f))
|
|
|
+ svgProcessLayoutParams.startToStart = R.id.view
|
|
|
+ svgProcessLayoutParams.topToBottom = R.id.view
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/10 - DpPxUtil.dip2px(10f)
|
|
|
+ svgProcessLayoutParams.topMargin = DpPxUtil.dip2px(-3f)
|
|
|
+ svgProgress.layoutParams = svgProcessLayoutParams
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (processPKModel.oppositeProgressValue == 0&&processPKModel.progressValue != 0){
|
|
|
+ val svgProcessLayoutParams = ConstraintLayout.LayoutParams(DpPxUtil.dip2px(20f),DpPxUtil.dip2px(20f))
|
|
|
+ svgProcessLayoutParams.startToStart = R.id.view
|
|
|
+ svgProcessLayoutParams.topToBottom = R.id.view
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/10*9 - DpPxUtil.dip2px(10f)
|
|
|
+ svgProcessLayoutParams.topMargin = DpPxUtil.dip2px(-3f)
|
|
|
+ svgProgress.layoutParams = svgProcessLayoutParams
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ val svgProcessLayoutParams = ConstraintLayout.LayoutParams(DpPxUtil.dip2px(20f),DpPxUtil.dip2px(20f))
|
|
|
+ svgProcessLayoutParams.startToStart = R.id.view
|
|
|
+ svgProcessLayoutParams.topToBottom = R.id.view
|
|
|
+ if (mProgress>50){
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/100*mProgress + DpPxUtil.dip2px(10f)
|
|
|
+ }else if(mProgress<50){
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/100*mProgress - DpPxUtil.dip2px(10f)
|
|
|
+ }else{
|
|
|
+ svgProcessLayoutParams.marginStart = DpPxUtil.getScreenWidth()/100*mProgress
|
|
|
+ }
|
|
|
+ svgProcessLayoutParams.topMargin = DpPxUtil.dip2px(-3f)
|
|
|
+ svgProgress.layoutParams = svgProcessLayoutParams
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -190,9 +305,19 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
binding?.apply {
|
|
|
pkTime--
|
|
|
if (PKStateManager.roomState==PKStateManager.PK){
|
|
|
- tvPkTime.text = TimeUtil.convertMinSecond(pkTime.toLong())
|
|
|
+ if (pkTime>=0){
|
|
|
+ tvPkTime.text = TimeUtil.convertMinSecond(pkTime.toLong())
|
|
|
+ }
|
|
|
+ if (pkTime==-5 ){
|
|
|
+ doGetPKInfoFun?.invoke()
|
|
|
+ }
|
|
|
}else if(PKStateManager.roomState==PKStateManager.PUNISH){
|
|
|
- tvPunishTime.text = TimeUtil.convertMinSecond(pkTime.toLong())
|
|
|
+ if (pkTime>=0){
|
|
|
+ tvPunishTime.text = TimeUtil.convertMinSecond(pkTime.toLong())
|
|
|
+ }
|
|
|
+ if (pkTime==-5 ){
|
|
|
+ doGetPKInfoFun?.invoke()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -232,37 +357,49 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
/**
|
|
|
* type 1 播放PK结果动画 2 播放正在PK进度条动画
|
|
|
*/
|
|
|
- private fun playProgress(path:String,type:Int){
|
|
|
- svgParser?.let {
|
|
|
+ private fun playProgress(path:String){
|
|
|
+ svgParserProgress?.let {
|
|
|
it.decodeFromAssets(path,object:SVGAParser.ParseCompletion{
|
|
|
override fun onComplete(videoItem: SVGAVideoEntity) {
|
|
|
binding?.apply {
|
|
|
val drawable = SVGADrawable(videoItem)
|
|
|
- when(type){
|
|
|
- 1 -> {
|
|
|
- svgPKResult.setImageDrawable(drawable)
|
|
|
- svgPKResult.callback = callback
|
|
|
- svgPKResult.visibility = View.VISIBLE
|
|
|
- svgPKResult.loops = 1
|
|
|
- svgPKResult.startAnimation()
|
|
|
- }
|
|
|
-
|
|
|
- 2 -> {
|
|
|
- svgProgress.setImageDrawable(drawable)
|
|
|
- svgProgress.callback = callback
|
|
|
- svgProgress.visibility = View.VISIBLE
|
|
|
- svgProgress.loops = 99999
|
|
|
- svgProgress.startAnimation()
|
|
|
- }
|
|
|
- }
|
|
|
+ svgProgress.setImageDrawable(drawable)
|
|
|
+ svgProgress.loops = 99999
|
|
|
+ svgProgress.startAnimation()
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ override fun onError() {
|
|
|
+ binding?.apply {
|
|
|
}
|
|
|
+ }
|
|
|
+ },object:SVGAParser.PlayCallback{
|
|
|
+ override fun onPlay(file: List<File>) {
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ private fun playPKResultSvg(path:String){
|
|
|
+ svgParser?.let {
|
|
|
+ it.decodeFromAssets(path,object:SVGAParser.ParseCompletion{
|
|
|
+ override fun onComplete(videoItem: SVGAVideoEntity) {
|
|
|
+ binding?.apply {
|
|
|
+ val drawable = SVGADrawable(videoItem)
|
|
|
+ svgPKResult.setImageDrawable(drawable)
|
|
|
+ svgPKResult.callback = playResultCallback
|
|
|
+ svgPKResult.visibility = View.VISIBLE
|
|
|
+ svgPKResult.loops = 1
|
|
|
+ svgPKResult.startAnimation()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onError() {
|
|
|
binding?.apply {
|
|
|
- svgProgress.visibility = View.GONE
|
|
|
+ svgPKResult.visibility = View.GONE
|
|
|
}
|
|
|
}
|
|
|
},object:SVGAParser.PlayCallback{
|
|
@@ -274,23 +411,26 @@ class PKLayoutView : ConstraintLayout, IRoomActiveListener, IPKListener,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private var callback = object: SVGACallback {
|
|
|
+
|
|
|
+ private var playResultCallback = object: SVGACallback {
|
|
|
|
|
|
override fun onFinished() {
|
|
|
binding?.apply {
|
|
|
- svgProgress.visibility = View.GONE
|
|
|
- ivSelfPKResult.visibility = View.VISIBLE
|
|
|
- ivPeerPKResult.visibility = View.VISIBLE
|
|
|
+ if (PKStateManager.roomState == PKStateManager.PUNISH){
|
|
|
+ ivSelfPKResult.visibility = View.VISIBLE
|
|
|
+ ivPeerPKResult.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+ svgPKResult.visibility = View.GONE
|
|
|
when(pkResult){
|
|
|
- 1 -> {
|
|
|
+ 3 -> {
|
|
|
ivSelfPKResult.setImageResource(R.mipmap.icon_pk_win)
|
|
|
ivPeerPKResult.setImageResource(R.mipmap.icon_pk_fail)
|
|
|
}
|
|
|
- 2 -> {
|
|
|
+ 4 -> {
|
|
|
ivSelfPKResult.setImageResource(R.mipmap.icon_pk_fail)
|
|
|
ivPeerPKResult.setImageResource(R.mipmap.icon_pk_win)
|
|
|
}
|
|
|
- 3 -> {
|
|
|
+ 5 -> {
|
|
|
ivSelfPKResult.setImageResource(R.mipmap.icon_pk_draw)
|
|
|
ivPeerPKResult.setImageResource(R.mipmap.icon_pk_draw)
|
|
|
}
|