浏览代码

1.优化代码

王鹏鹏 1 年之前
父节点
当前提交
d9a19d96ce

+ 2 - 2
baselib/build.gradle

@@ -40,7 +40,7 @@ android {
             buildConfigField "String", "BAIDU_SECRETKEY", "\"41Fzb2ZIuKRGNtrVcQOHxEI3vFM4Rkxi\""
             buildConfigField "Boolean", "SINGLE_MODULE", "${singleModule}"
             buildConfigField "String", "BUGLY_APPID", "\"d400f20398\""
-            buildConfigField "String", "API_URL", "\"http://192.168.0.66:8110\""
+            buildConfigField "String", "API_URL", "\"http://192.168.0.122:8110\""
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
 
@@ -54,7 +54,7 @@ android {
             buildConfigField "String", "BAIDU_SECRETKEY", "\"41Fzb2ZIuKRGNtrVcQOHxEI3vFM4Rkxi\""
             buildConfigField "Boolean", "SINGLE_MODULE", "${singleModule}"
             buildConfigField "String", "BUGLY_APPID", "\"ad3db4d529\""
-            buildConfigField "String", "API_URL", "\"http://192.168.0.66:8110\""
+            buildConfigField "String", "API_URL", "\"http://192.168.0.122:8110\""
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
     }

+ 26 - 0
game/src/main/java/com/yingyangfly/game/entity/GameBean.kt

@@ -0,0 +1,26 @@
+package com.yingyangfly.game.entity
+
+/**
+ * 游戏详情
+ */
+data class GameBean(
+    val desn: String,
+    val gameBackgroundImage: Any,
+    val gameCode: String,
+    val gameCoverImage: String,
+    val gameDifficulty: String,
+    val gameDifficultyRate: String,
+    val gameDuration: Int,
+    val gameId: Any,
+    val gameLevel: Int,
+    val gameMaxScore: String,
+    val gameName: String,
+    val gameTotalScore: String,
+    val gameTotalTime: Any,
+    val gameType: String,
+    val gameUrl: String,
+    val gameVideoUrl: Any,
+    val patientId: Any,
+    val playClass: String,
+    val totalNum: Int
+)

+ 10 - 19
game/src/main/java/com/yingyangfly/game/introduction/GameIntroductionActivity.kt

@@ -2,7 +2,6 @@ package com.yingyangfly.game.introduction
 
 import android.annotation.SuppressLint
 import android.os.Bundle
-import android.text.TextUtils
 import android.view.MotionEvent
 import android.view.View
 import com.alibaba.android.arouter.facade.annotation.Route
@@ -23,10 +22,12 @@ class GameIntroductionActivity :
     BaseMVVMActivity<ActivityGameIntroductionBinding, GameIntroductionViewModel>(),
     View.OnTouchListener {
 
-    private var id: String = ""
+    private var gameCode: String = ""
+    private var playClass: String = ""
 
     override fun onCreate(savedInstanceState: Bundle?) {
-        id = intent.getStringExtra("url") ?: ""
+        gameCode = intent.getStringExtra("gameCode") ?: ""
+        playClass = intent.getStringExtra("playClass") ?: ""
         super.onCreate(savedInstanceState)
     }
 
@@ -49,29 +50,19 @@ class GameIntroductionActivity :
 
     override fun onResume() {
         super.onResume()
-        if (TextUtils.isEmpty(id).not()) {
-            viewModel.getGameDetail(id, fail = {
-
-            }, success = {
-                if (it != null) {
-                    binding.data = it
-                    if (TextUtils.isEmpty(it.gameVideoUrl).not()) {
-                        initPalyer(it)
-                    }
-                    getGameDetailByCode(it.gameCode, it.playClass)
-                }
-            })
-        }
+        getGameDetailByCode()
     }
 
     /**
      * 获取游戏信息
      */
-    private fun getGameDetailByCode(gameCode: String, playClass: String) {
+    private fun getGameDetailByCode() {
         viewModel.getGameDetailByCode(gameCode, playClass, fail = {
 
         }, success = {
-
+            if (it != null) {
+                binding.data = it
+            }
         })
     }
 
@@ -95,7 +86,7 @@ class GameIntroductionActivity :
                 if (v.id == R.id.homeImage) {
                     JumpUtil.jumpActivity(RouterUrlCommon.home, mContext)
                 } else if (v.id == R.id.btnStartGame) {
-                    JumpUtil.jumpActivityWithUrl(RouterUrlCommon.playGame, id, mContext)
+//                    JumpUtil.jumpActivityWithUrl(RouterUrlCommon.playGame, id, mContext)
                 }
             }
             MotionEvent.ACTION_CANCEL -> {

+ 2 - 15
game/src/main/java/com/yingyangfly/game/introduction/GameIntroductionViewModel.kt

@@ -4,6 +4,7 @@ import com.yingyangfly.baselib.bean.Record
 import com.yingyangfly.baselib.mvvm.BaseViewModel
 import com.yingyangfly.baselib.net.XUtils
 import com.yingyangfly.baselib.utils.GsonUtil
+import com.yingyangfly.game.entity.GameBean
 import com.yingyangfly.game.entity.GetGameDetailByCodeBean
 import com.yingyangfly.game.net.GAME_API
 
@@ -12,20 +13,6 @@ import com.yingyangfly.game.net.GAME_API
  */
 class GameIntroductionViewModel : BaseViewModel() {
 
-    /**
-     * 获取游戏详情
-     */
-    fun getGameDetail(
-        id: String,
-        fail: ((msg: String) -> Unit)? = null,
-        success: ((success: Record?) -> Unit)? = null,
-    ) = launchFlow(false) {
-        GAME_API.getGameDetail(id)
-    }.runUI(
-        success,
-        fail
-    )
-
     /**
      * 获取游戏详情
      */
@@ -33,7 +20,7 @@ class GameIntroductionViewModel : BaseViewModel() {
         code: String,
         playClasses: String,
         fail: ((msg: String) -> Unit)? = null,
-        success: ((success: Unit?) -> Unit)? = null,
+        success: ((success: GameBean?) -> Unit)? = null,
     ) = launchFlow(false) {
         val requestBean = GetGameDetailByCodeBean().apply {
             gameCode = code

+ 16 - 17
game/src/main/java/com/yingyangfly/game/loading/GameLoadingActivity.kt

@@ -1,14 +1,12 @@
 package com.yingyangfly.game.loading
 
 import android.os.Bundle
-import android.text.TextUtils
 import com.alibaba.android.arouter.facade.annotation.Route
+import com.alibaba.android.arouter.launcher.ARouter
 import com.bumptech.glide.Glide
 import com.yingyangfly.baselib.R
 import com.yingyangfly.baselib.base.BaseActivity
-import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.baselib.router.RouterUrlCommon
-import com.yingyangfly.baselib.utils.JumpUtil
 import com.yingyangfly.baselib.utils.RxTimer
 import com.yingyangfly.game.databinding.ActivityGameLoadingBinding
 
@@ -18,29 +16,30 @@ import com.yingyangfly.game.databinding.ActivityGameLoadingBinding
 @Route(path = RouterUrlCommon.gameLoading)
 class GameLoadingActivity : BaseActivity<ActivityGameLoadingBinding>() {
 
-    private var url: String = ""
+    private var gameCode: String = ""
+    private var playClass: String = ""
     private lateinit var rxTimer: RxTimer
     private var time: Long = 3
 
     override fun onCreate(savedInstanceState: Bundle?) {
-        url = intent.getStringExtra("url") ?: ""
+        gameCode = intent.getStringExtra("gameCode") ?: ""
+        playClass = intent.getStringExtra("playClass") ?: ""
         super.onCreate(savedInstanceState)
     }
 
     override fun initViews() {
-        if (TextUtils.isEmpty(url).not()) {
-            rxTimer = RxTimer()
-            val m: Long = 1000
-            rxTimer.interval(m) {
-                binding.progressBar.progress = it.toInt() + 1
-                if (time == it) {
-                    JumpUtil.jumpActivityWithUrl(RouterUrlCommon.gameIntroduction, url, mContext)
-                    finish()
-                }
+        rxTimer = RxTimer()
+        val m: Long = 1000
+        rxTimer.interval(m) {
+            binding.progressBar.progress = it.toInt() + 1
+            if (time == it) {
+                ARouter.getInstance().build(RouterUrlCommon.gameIntroduction)
+                    .withString("gameCode", gameCode)
+                    .withString("playClass", playClass)
+                    .withTransition(R.anim.leftin, R.anim.leftout)
+                    .navigation(mContext)
+                finish()
             }
-        } else {
-            "数据错误".toast()
-            finish()
         }
     }
 

+ 2 - 9
game/src/main/java/com/yingyangfly/game/net/GameApiService.kt

@@ -1,23 +1,16 @@
 package com.yingyangfly.game.net
 
-import com.yingyangfly.baselib.bean.Record
 import com.yingyangfly.baselib.net.BaseResp
+import com.yingyangfly.game.entity.GameBean
 import okhttp3.RequestBody
 import retrofit2.http.Body
 import retrofit2.http.POST
-import retrofit2.http.Query
 
 interface GameApiService {
 
-    /**
-     * 获取游戏详情
-     */
-    @POST("game/params/user/detail")
-    suspend fun getGameDetail(@Query("id") id: String): BaseResp<Record>
-
     /**
      * 获取游戏详情
      */
     @POST("app/game/detailByCode")
-    suspend fun getGameDetailByCode(@Body requestBody: RequestBody): BaseResp<Unit>
+    suspend fun getGameDetailByCode(@Body requestBody: RequestBody): BaseResp<GameBean>
 }

+ 0 - 6
game/src/main/java/com/yingyangfly/game/play/PlayGameActivity.kt

@@ -43,12 +43,6 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
      * 加载游戏内容
      */
     private fun loadGame() {
-        viewModel.getGameDetail(id, fail = {
 
-        }, success = {
-            if (it != null) {
-
-            }
-        })
     }
 }

+ 0 - 16
game/src/main/java/com/yingyangfly/game/play/PlayGameViewModel.kt

@@ -1,26 +1,10 @@
 package com.yingyangfly.game.play
 
-import com.yingyangfly.baselib.bean.Record
 import com.yingyangfly.baselib.mvvm.BaseViewModel
-import com.yingyangfly.game.net.GAME_API
 
 /**
  * @author 王鹏鹏
  */
 class PlayGameViewModel : BaseViewModel() {
 
-    /**
-     * 获取游戏详情
-     */
-    fun getGameDetail(
-        id: String,
-        fail: ((msg: String) -> Unit)? = null,
-        success: ((success: Record?) -> Unit)? = null,
-    ) = launchFlow(false) {
-        GAME_API.getGameDetail(id)
-    }.runUI(
-        success,
-        fail
-    )
-
 }

+ 2 - 2
game/src/main/res/layout/activity_game_introduction.xml

@@ -8,7 +8,7 @@
 
         <variable
             name="data"
-            type="com.yingyangfly.baselib.bean.Record" />
+            type="com.yingyangfly.game.entity.GameBean" />
     </data>
 
     <androidx.constraintlayout.widget.ConstraintLayout
@@ -109,7 +109,7 @@
             android:layout_marginBottom="@dimen/divider_43px"
             android:background="@drawable/bg_game_record"
             android:gravity="center"
-            android:text='@{"最佳纪录 "+data.gameScore}'
+            android:text='@{"最佳纪录 "+data.gameTotalScore}'
             android:textColor="@color/color_FFFFA413"
             android:textSize="@dimen/divider_28px"
             app:layout_constraintBottom_toBottomOf="parent"

+ 24 - 1
game/src/main/res/layout/activity_play_game.xml

@@ -1,11 +1,34 @@
 <?xml version="1.0" encoding="utf-8"?>
 <layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     tools:ignore="ResourceName">
 
     <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_width="match_parent"
-        android:layout_height="match_parent">
+        android:layout_height="match_parent"
+        android:background="@drawable/bg_game_introduction">
+
+        <androidx.appcompat.widget.AppCompatImageView
+            android:id="@+id/homeImage"
+            android:layout_width="@dimen/divider_48px"
+            android:layout_height="@dimen/divider_43px"
+            android:layout_marginStart="@dimen/divider_65px"
+            android:layout_marginTop="@dimen/divider_35px"
+            android:background="@mipmap/bg_home"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+        <com.google.android.material.card.MaterialCardView
+            android:layout_width="match_parent"
+            android:layout_height="0dp"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/homeImage">
+
+
+        </com.google.android.material.card.MaterialCardView>
 
 
     </androidx.constraintlayout.widget.ConstraintLayout>

+ 5 - 1
workbenches/src/main/java/com/yingyang/workbenches/freetraining/FreeTrainActivity.kt

@@ -76,7 +76,11 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
 //                val str =
 //                    bean.gameUrl + "?gameCode=" + bean.gameCode + "&isFull=false&isSound=true&playClass=" + bean.playClass +
 //                            "&userToken=" + User.getToken()
-                JumpUtil.jumpActivityWithUrl(RouterUrlCommon.gameLoading, bean.id, mContext)
+                ARouter.getInstance().build(RouterUrlCommon.gameLoading)
+                    .withString("gameCode", bean.gameCode)
+                    .withString("playClass", bean.playClass)
+                    .withTransition(R.anim.leftin, R.anim.leftout)
+                    .navigation(mContext)
             }
         }
     }