Browse Source

1.修改从游戏页面多次切换返回到游戏介绍页面bug

王鹏鹏 2 years ago
parent
commit
9e6cd2c23c

+ 20 - 21
game/src/main/java/com/yingyangfly/game/introduction/GameIntroductionActivity.kt

@@ -7,7 +7,6 @@ import android.content.Context
 import android.content.Intent
 import android.text.TextUtils
 import android.text.method.ScrollingMovementMethod
-import android.util.Log
 import android.view.MotionEvent
 import android.view.View
 import com.alibaba.android.arouter.facade.annotation.Route
@@ -41,14 +40,17 @@ class GameIntroductionActivity :
 
     private var id = ""
     private var desn = ""
-    private var isEnterGame = false
     private var gameCode: String = ""
     private var playClass: String = ""
     private var gameBean: GameBean? = null
-    private var homePage: Boolean = false
     private var mVodPlayer: TXVodPlayer? = null
     private var loadingOver = false
 
+    /**
+     * 是否从游戏页面跳转
+     */
+    private var isPlayGameJump = false
+
     /**
      * 语音合成
      */
@@ -59,10 +61,10 @@ class GameIntroductionActivity :
         desn = intent.getStringExtra("desn") ?: ""
         gameCode = intent.getStringExtra("gameCode") ?: ""
         playClass = intent.getStringExtra("playClass") ?: ""
-        homePage = intent.getBooleanExtra("homePage", false)
+        isPlayGameJump = intent.getBooleanExtra("isPlayGameJump", false)
         voicePlayer = VoicePlayer.getInstance(mContext)
         mVodPlayer = TXVodPlayer(mContext)
-        if (isEnterGame.not()) {
+        if (isPlayGameJump.not()) {
             val gameLoadingDialog = GameLoadingDialog()
             gameLoadingDialog.onDialogClickListener = {
                 speak()
@@ -82,6 +84,11 @@ class GameIntroductionActivity :
     }
 
     override fun initData() {
+        if (isPlayGameJump) {
+            binding.btnStartGame.setBackgroundResource(R.mipmap.icon_game_continue)
+        } else {
+            binding.btnStartGame.setBackgroundResource(R.mipmap.icon_staret_game_bg)
+        }
         initLiveData()
         getGameDetailByCode()
         binding.tvScientificPrincipleInfo.setMovementMethod(ScrollingMovementMethod.getInstance())
@@ -93,9 +100,9 @@ class GameIntroductionActivity :
             id = intent.getStringExtra("id") ?: ""
             gameCode = intent.getStringExtra("gameCode") ?: ""
             playClass = intent.getStringExtra("playClass") ?: ""
+            isPlayGameJump = intent.getBooleanExtra("isPlayGameJump", false)
             getGameDetailByCode()
         }
-        isEnterGame = true
         if (mVodPlayer != null) {
             mVodPlayer?.resume()
         }
@@ -201,7 +208,7 @@ class GameIntroductionActivity :
                 when (v.id) {
                     R.id.homeImage -> {
                         runOnUiThread {
-                            if (isEnterGame) {
+                            if (isPlayGameJump) {
                                 val exitGameDialog = ExitGameDialog()
                                 exitGameDialog.onDialogClickListener = {
                                     runOnUiThread {
@@ -225,26 +232,18 @@ class GameIntroductionActivity :
                     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
+                                    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("id", id)
-                                    .withString("playClass", playClass)
-                                    .withString("url", url)
+                                    .withString("gameCode", gameCode).withString("id", id)
+                                    .withString("playClass", playClass).withString("url", url)
                                     .withString("gameType", gameBean!!.gameType)
                                     .withString("gameTotalScore", gameBean!!.gameTotalScore)
+                                    .withBoolean("isPlayGameJump", isPlayGameJump)
                                     .withString("gameInbetweenImage", gameBean!!.gameInbetweenImage)
                                     .withString(
-                                        "gameBackgroundImage",
-                                        gameBean!!.gameBackgroundImage
-                                    )
-                                    .withString("gameShortDesn", gameBean!!.gameShortDesn)
+                                        "gameBackgroundImage", gameBean!!.gameBackgroundImage
+                                    ).withString("gameShortDesn", gameBean!!.gameShortDesn)
                                     .withString("fullFlag", gameBean!!.fullFlag)
                                     .withString("frameImg", gameBean!!.frameImg)
                                     .withString("gameName", gameBean!!.gameName)

+ 48 - 19
game/src/main/java/com/yingyangfly/game/play/PlayGameActivity.kt

@@ -21,6 +21,7 @@ import androidx.constraintlayout.widget.ConstraintSet
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.alibaba.android.arouter.launcher.ARouter
 import com.bumptech.glide.Glide
+import com.tencent.bugly.crashreport.CrashReport
 import com.yingyangfly.baselib.bean.GameDataBean
 import com.yingyangfly.baselib.bean.GetSaveGameRecordBean
 import com.yingyangfly.baselib.db.VoicePlayerBean
@@ -35,7 +36,9 @@ import com.yingyangfly.baselib.utils.GsonUtil
 import com.yingyangfly.baselib.utils.JumpUtil
 import com.yingyangfly.baselib.utils.LiveEventBusUtil
 import com.yingyangfly.baselib.utils.RxBusCodes
+import com.yingyangfly.baselib.utils.User
 import com.yingyangfly.baselib.utils.img.ImgUtil
+import com.yingyangfly.game.BuildConfig
 import com.yingyangfly.game.R
 import com.yingyangfly.game.databinding.ActivityPlayGameBinding
 import com.yingyangfly.game.dialog.CompletionTrainingDialog
@@ -64,7 +67,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
     /**
      * 是否第一次启动activity
      */
-    private var newStartGame = true
+    private var isNewPlayGameJump = false
 
     /**
      * 倒计时是否结束
@@ -103,6 +106,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
         url = intent.getStringExtra("url") ?: ""
         gameType = intent.getStringExtra("gameType") ?: ""
         gameTotalScore = intent.getStringExtra("gameTotalScore") ?: ""
+        isNewPlayGameJump = intent.getBooleanExtra("isPlayGameJump", false)
         if (TextUtils.isEmpty(gameTotalScore)) {
             gameTotalScore = "0"
         }
@@ -172,13 +176,13 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
             id = intent.getStringExtra("id") ?: ""
             gameCode = intent.getStringExtra("gameCode") ?: ""
             playClass = intent.getStringExtra("playClass") ?: ""
+            isNewPlayGameJump = intent.getBooleanExtra("isPlayGameJump", false)
         }
-        newStartGame = false
         runOnUiThread {
             binding.webView.evaluateJavascript(
                 "javascript:CallContinueGame()"
             ) {
-
+                Log.e("wpp", "----------------继续游戏")
             }
         }
     }
@@ -275,19 +279,27 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
                 when (v.id) {
                     R.id.imagePause -> {
                         runOnUiThread {
-                            if (TextUtils.equals("D", playClass)) {
+                            if (callQuitGame) {
+                                reportGameCrashInfo("游戏结束退出失败,通过返回键退出游戏")
+                                ActivityManagers.instance.finishActivity(GameIntroductionActivity::class.java)
                                 finish()
                             } else {
-                                Log.e("wpp", "游戏暂停")
-                                binding.webView.evaluateJavascript(
-                                    "javascript:CallPauseGame()"
-                                ) {
-                                    Log.e("wpp", "游戏暂停成功跳转介绍")
-                                    ARouter.getInstance().build(RouterUrlCommon.gameIntroduction)
-                                        .withString("gameCode", gameCode).withString("id", id)
-                                        .withString("playClass", playClass)
-                                        .withTransition(R.anim.leftin, R.anim.leftout)
-                                        .navigation(mContext)
+                                if (TextUtils.equals("D", playClass)) {
+                                    finish()
+                                } else {
+                                    Log.e("wpp", "游戏暂停")
+                                    binding.webView.evaluateJavascript(
+                                        "javascript:CallPauseGame()"
+                                    ) {
+                                        Log.e("wpp", "游戏暂停成功跳转介绍")
+                                        ARouter.getInstance()
+                                            .build(RouterUrlCommon.gameIntroduction)
+                                            .withString("gameCode", gameCode).withString("id", id)
+                                            .withString("playClass", playClass)
+                                            .withBoolean("isPlayGameJump", true)
+                                            .withTransition(R.anim.leftin, R.anim.leftout)
+                                            .navigation(mContext)
+                                    }
                                 }
                             }
                         }
@@ -319,8 +331,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
 
     override fun onResume() {
         super.onResume()
-        if (newStartGame) {
-            newStartGame = false
+        if (isNewPlayGameJump.not()) {
             if (gameSoundDao != null) {
                 val gameSoundbeans = gameSoundDao?.getAllGameSoundBean()
                 if (gameSoundbeans.isNullOrEmpty().not()) {
@@ -450,9 +461,9 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
         }
         //游戏进度
         LiveEventBusUtil.observer<String>(this, RxBusCodes.SAVEDATA) {
-            binding.tvScore.postDelayed({
+            runOnUiThread {
                 if (TextUtils.isEmpty(it).not()) {
-                    Log.e("wpp", "游戏保存-----------" + it)
+                    Log.e("wpp", "游戏保存-----------$it")
                     val gameDataBean = GsonUtil.GsonToBean(it, GameDataBean::class.java)
                     if (gameDataBean != null) {
                         val score: Int = gameTotalScore.toInt() + gameDataBean.curLevelScore.toInt()
@@ -475,9 +486,13 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
                         } else {
                             parsingData(gameDataBean, isPass)
                         }
+                    } else {
+                        reportGameCrashInfo("h5返回信息解析失败")
                     }
+                } else {
+                    reportGameCrashInfo("h5返回游戏信息为空")
                 }
-            }, 100)
+            }
         }
         //游戏加载完成
         LiveEventBusUtil.observer<String>(this, RxBusCodes.LOADINGOVER) {
@@ -707,4 +722,18 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
         val cn = am.getRunningTasks(1)[0].topActivity
         return cn!!.className == activity.javaClass.name
     }
+
+    /**
+     * 上报游戏异常
+     */
+    private fun reportGameCrashInfo(msg: String) {
+        if (BuildConfig.DEBUG) {
+            Log.e("wpp", "游戏页面日志上报----------------->$msg")
+            CrashReport.postCatchedException(
+                Throwable(
+                    msg + "\n用户信息:" + User.getName() + User.getUserId() + "\n游戏名称: " + gameName + "游戏code: " + gameCode
+                )
+            )
+        }
+    }
 }