Jelajahi Sumber

1.添加游戏通关后重玩提示功能

王鹏鹏 2 tahun lalu
induk
melakukan
0f3bd160b5

+ 15 - 2
home/src/main/java/com/yingyangfly/home/activity/HomeActivity.kt

@@ -3,6 +3,7 @@ package com.yingyangfly.home.activity
 import android.annotation.SuppressLint
 import android.os.CountDownTimer
 import android.text.TextUtils
+import android.util.Log
 import android.view.MotionEvent
 import android.view.View
 import androidx.recyclerview.widget.GridLayoutManager
@@ -74,7 +75,7 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(),
             rvGame.layoutManager = GridLayoutManager(this@HomeActivity, 2)
             rvGame.adapter = gameAdapter
             gameAdapter.onGameImageClickListener = {
-                if (it.currentLevel == it.totalNum) {
+                if (TextUtils.equals("0", it.status)) {
                     TipsDialog.TipDialogBuilder()
                         .title("恭喜您")
                         .content("当前游戏已通关,是否重新开始?")
@@ -83,7 +84,7 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(),
                         .leftClick({
                         }, true)
                         .rightClick({
-                            jumpWebView(it)
+                            gameReplay(it)
                         }, true)
                         .show(supportFragmentManager)
                 } else {
@@ -93,6 +94,17 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(),
         }
     }
 
+    /**
+     * 游戏重玩
+     */
+    private fun gameReplay(bean: Record) {
+        viewModel.gameReplay(bean.id, fail = {
+            it.toast()
+        }, success = {
+            jumpWebView(bean)
+        })
+    }
+
     @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
@@ -720,6 +732,7 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(),
      */
     private fun addAMessageData(msg: MessageBean) {
         runOnUiThread {
+            Log.e("wpp", GsonUtil.GsonString(msg))
             aMessageList.add(msg)
             if (aCountDownTimer != null) {
                 aCountDownTimer?.cancel()

+ 6 - 9
home/src/main/java/com/yingyangfly/home/activity/HomeViewModel.kt

@@ -96,20 +96,17 @@ class HomeViewModel : BaseViewModel() {
     )
 
     /**
-     * 获取游戏详情
+     * 游戏重玩
      */
-    fun saveGameRecord(
-        requestBean: GetSaveGameRecordBean,
+    fun gameReplay(
+        id: String,
         fail: ((msg: String) -> Unit)? = null,
-        success: ((success: GameBean?) -> Unit)? = null,
-    ) = launchFlow(false) {
-        val body = XUtils.createJson(GsonUtil.GsonString(requestBean))
-        HOME_API.saveGameRecord(body)
+        success: ((success: Any?) -> Unit)? = null,
+    ) = launchFlow(true) {
+        HOME_API.gameReplay(id)
     }.runUI(
         success,
         fail
     )
 
-
-
 }

+ 6 - 7
home/src/main/java/com/yingyangfly/home/net/HomeApiService.kt

@@ -1,6 +1,5 @@
 package com.yingyangfly.home.net
 
-import com.yingyangfly.baselib.bean.GameBean
 import com.yingyangfly.baselib.bean.Record
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.net.BaseResp
@@ -67,16 +66,16 @@ interface HomeApiService {
     @POST("app/review/findReviewResult")
     suspend fun findReviewResult(@Body requestBody: RequestBody): BaseResp<EvaluationResultBean>
 
-    /**
-     * 保存游戏进度
-     */
-    @POST("game/play/record/save")
-    suspend fun saveGameRecord(@Body requestBody: RequestBody): BaseResp<GameBean>
-
     /**
      * 测评报告详情
      */
     @POST("app/review/findReviewResultDetail")
     suspend fun findReviewResultDetail(@Body requestBody: RequestBody): BaseResp<List<ReviewResultDetailBean>>
 
+    /**
+     * 游戏重玩
+     */
+    @POST("app/game/replay")
+    suspend fun gameReplay(@Query("id") id: String): BaseResp<Any>
+
 }

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

@@ -14,7 +14,7 @@ import com.yingyang.workbenches.adapter.FreeTrainTypeAdapter
 import com.yingyang.workbenches.databinding.ActivityFreeTrainBinding
 import com.yingyang.workbenches.entity.TrainTypeBean
 import com.yingyangfly.baselib.bean.Record
-import com.yingyangfly.baselib.dialog.TipDialogFragment
+import com.yingyangfly.baselib.dialog.TipsDialog
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
@@ -74,16 +74,16 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
             freeTrainListAdapter.setType(type)
             freeTrainListAdapter.onGameClickListener = { bean, position ->
                 if (TextUtils.equals("0", bean.status)) {
-                    TipDialogFragment.TipDialogBuilder()
-                        .title("提示")
+                    TipsDialog.TipDialogBuilder()
+                        .title("恭喜您")
                         .content("当前游戏已通关,是否重新开始?")
                         .leftBtnText("取消")
                         .rightBtnText("确定")
                         .leftClick({
-                        }, dimiss = true)
+                        }, true)
                         .rightClick({
                             gameReplay(bean, position)
-                        }, dimiss = true)
+                        }, true)
                         .show(supportFragmentManager)
                 } else {
                     jumeGame(bean, position)