瀏覽代碼

1.优化代码

王鹏鹏 1 年之前
父節點
當前提交
03b17524f9

+ 55 - 40
game/src/main/java/com/yingyangfly/game/introduction/GameIntroductionActivity.kt

@@ -16,10 +16,7 @@ import com.tencent.rtmp.TXVodPlayer
 import com.yingyangfly.baselib.db.GameSoundBean
 import com.yingyangfly.baselib.db.VoicePlayerBean
 import com.yingyangfly.baselib.dialog.GameLoadingDialog
-import com.yingyangfly.baselib.ext.getEndAnimation
-import com.yingyangfly.baselib.ext.getScaleAnimation
-import com.yingyangfly.baselib.ext.show
-import com.yingyangfly.baselib.ext.toast
+import com.yingyangfly.baselib.ext.*
 import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
 import com.yingyangfly.baselib.player.VoicePlayer
 import com.yingyangfly.baselib.router.RouterUrlCommon
@@ -71,6 +68,7 @@ class GameIntroductionActivity :
         binding {
             homeImage.setOnTouchListener(this@GameIntroductionActivity)
             btnStartGame.setOnTouchListener(this@GameIntroductionActivity)
+            viewLayout.setOnTouchListener(this@GameIntroductionActivity)
         }
     }
 
@@ -183,55 +181,72 @@ class GameIntroductionActivity :
     override fun onTouch(v: View, event: MotionEvent): Boolean {
         when (event.action) {
             MotionEvent.ACTION_DOWN -> {
-                if (v.id == R.id.homeImage || v.id == R.id.btnStartGame) {
+                if (v.id == R.id.homeImage || v.id == R.id.btnStartGame || v.id == R.id.viewLayout) {
                     v.startAnimation(getScaleAnimation())
                 }
             }
             MotionEvent.ACTION_UP -> {
                 v.startAnimation(getEndAnimation())
-                if (v.id == R.id.homeImage) {
-                    runOnUiThread {
-                        if (isEnterGame) {
-                            val exitGameDialog = ExitGameDialog()
-                            exitGameDialog.onDialogClickListener = {
-                                LiveEventBusUtil.send(RxBusCodes.CALLQUITGAME, "")
+                when (v.id) {
+                    R.id.homeImage -> {
+                        runOnUiThread {
+                            if (isEnterGame) {
+                                val exitGameDialog = ExitGameDialog()
+                                exitGameDialog.onDialogClickListener = {
+                                    LiveEventBusUtil.send(RxBusCodes.CALLQUITGAME, "")
+                                }
+                                exitGameDialog.show(supportFragmentManager, "exitGameDialog")
+                            } else {
+                                finish()
                             }
-                            exitGameDialog.show(supportFragmentManager, "exitGameDialog")
-                        } else {
-                            finish()
                         }
-                    }
 
-                } else if (v.id == R.id.btnStartGame) {
-                    runOnUiThread {
-                        if (gameBean != null) {
-                            isEnterGame = true
-                            val url =
-                                gameBean!!.gameUrl + "?startLv=" + gameBean!!.gameLevel + "&maxLv=" +
-                                        gameBean!!.totalNum + "&gameSetTime=" + gameBean!!.gameDuration +
-                                        "&difficultyRate=" + gameBean!!.gameDifficultyRate + "&totalTime=" +
-                                        gameBean!!.gameTotalTime + "&totalScore=" + gameBean!!.gameTotalScore +
-                                        "&playClass=" + playClass
-                            ARouter.getInstance().build(RouterUrlCommon.playGame)
-                                .withString("gameCode", gameCode)
-                                .withString("playClass", playClass)
-                                .withString("url", url)
-                                .withString("gameType", gameBean!!.gameType)
-                                .withString("gameTotalScore", gameBean!!.gameTotalScore)
-                                .withString("gameInbetweenImage", gameBean!!.gameInbetweenImage)
-                                .withString("gameBackgroundImage", gameBean!!.gameBackgroundImage)
-                                .withString("gameShortDesn", gameBean!!.gameShortDesn)
-                                .withString("fullFlag", gameBean!!.fullFlag)
-                                .withString("frameImg", gameBean!!.frameImg)
-                                .withString("gameName", gameBean!!.gameName)
-                                .withTransition(R.anim.leftin, R.anim.leftout)
-                                .navigation(mContext)
+                    }
+                    R.id.btnStartGame -> {
+                        runOnUiThread {
+                            if (gameBean != null) {
+                                isEnterGame = true
+                                val url =
+                                    gameBean!!.gameUrl + "?startLv=" + gameBean!!.gameLevel + "&maxLv=" +
+                                            gameBean!!.totalNum + "&gameSetTime=" + gameBean!!.gameDuration +
+                                            "&difficultyRate=" + gameBean!!.gameDifficultyRate + "&totalTime=" +
+                                            gameBean!!.gameTotalTime + "&totalScore=" + gameBean!!.gameTotalScore +
+                                            "&playClass=" + playClass
+                                ARouter.getInstance().build(RouterUrlCommon.playGame)
+                                    .withString("gameCode", gameCode)
+                                    .withString("playClass", playClass)
+                                    .withString("url", url)
+                                    .withString("gameType", gameBean!!.gameType)
+                                    .withString("gameTotalScore", gameBean!!.gameTotalScore)
+                                    .withString("gameInbetweenImage", gameBean!!.gameInbetweenImage)
+                                    .withString(
+                                        "gameBackgroundImage",
+                                        gameBean!!.gameBackgroundImage
+                                    )
+                                    .withString("gameShortDesn", gameBean!!.gameShortDesn)
+                                    .withString("fullFlag", gameBean!!.fullFlag)
+                                    .withString("frameImg", gameBean!!.frameImg)
+                                    .withString("gameName", gameBean!!.gameName)
+                                    .withTransition(R.anim.leftin, R.anim.leftout)
+                                    .navigation(mContext)
+                            }
+                        }
+                    }
+                    R.id.viewLayout -> {
+                        if (mVodPlayer != null) {
+                            if (mVodPlayer?.isPlaying == true) {
+                                mVodPlayer?.pause()
+                                binding.imagePause.show(true)
+                            } else {
+                                mVodPlayer?.resume()
+                                binding.imagePause.show(false)
+                            }
                         }
                     }
                 }
             }
             MotionEvent.ACTION_CANCEL -> {
-                if (v.id == R.id.homeImage || v.id == R.id.btnStartGame) {
+                if (v.id == R.id.homeImage || v.id == R.id.btnStartGame || v.id == R.id.viewLayout) {
                     v.startAnimation(getEndAnimation())
                 }
             }

+ 18 - 3
game/src/main/res/layout/activity_game_introduction.xml

@@ -125,12 +125,27 @@
                 app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintTop_toBottomOf="@+id/tvTitle">
 
-                <com.tencent.rtmp.ui.TXCloudVideoView
-                    android:id="@+id/videoView"
+                <FrameLayout
+                    android:id="@+id/viewLayout"
                     android:layout_width="@dimen/divider_445px"
                     android:layout_height="@dimen/divider_396px"
                     android:layout_marginStart="@dimen/divider_85px"
-                    android:layout_marginTop="@dimen/divider_80px" />
+                    android:layout_marginTop="@dimen/divider_80px"
+                    android:descendantFocusability="blocksDescendants">
+
+                    <com.tencent.rtmp.ui.TXCloudVideoView
+                        android:id="@+id/videoView"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent" />
+
+                    <androidx.appcompat.widget.AppCompatImageView
+                        android:id="@+id/imagePause"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_gravity="center"
+                        android:background="@mipmap/superplayer_ic_vod_play_normal"
+                        android:visibility="gone" />
+                </FrameLayout>
 
                 <androidx.appcompat.widget.AppCompatImageView
                     android:layout_width="match_parent"

二進制
game/src/main/res/mipmap-xxhdpi/superplayer_ic_vod_play_normal.png