浏览代码

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

王鹏鹏 2 年之前
父节点
当前提交
8c0b2e5241

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

@@ -14,6 +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.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
@@ -72,19 +73,51 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
             rvTrain.adapter = freeTrainListAdapter
             freeTrainListAdapter.setType(type)
             freeTrainListAdapter.onGameClickListener = { bean, position ->
-                gameId = bean.id
-                gameIndex = position
-                ARouter.getInstance().build(RouterUrlCommon.gameIntroduction)
-                    .withString("gameCode", bean.gameCode)
-                    .withString("playClass", bean.playClass)
-                    .withString("videoUrl", bean.gameVideoUrl)
-                    .withString("desn", bean.desn)
-                    .withTransition(R.anim.leftin, R.anim.leftout)
-                    .navigation(mContext)
+                if (TextUtils.equals("0", bean.status)) {
+                    TipDialogFragment.TipDialogBuilder()
+                        .title("提示")
+                        .content("当前游戏已通关,确定重玩吗?")
+                        .leftBtnText("取消")
+                        .rightBtnText("确定")
+                        .leftClick({
+                        }, dimiss = true)
+                        .rightClick({
+                            gameReplay(bean, position)
+                        }, dimiss = true)
+                        .show(supportFragmentManager)
+                } else {
+                    jumeGame(bean, position)
+                }
             }
         }
     }
 
+    /**
+     * 游戏重玩
+     */
+    private fun gameReplay(bean: Record, position: Int) {
+        viewModel.gameReplay(bean.id, fail = {
+            it.toast()
+        }, success = {
+            jumeGame(bean, position)
+        })
+    }
+
+    /**
+     * 跳转游戏
+     */
+    private fun jumeGame(bean: Record, position: Int) {
+        gameId = bean.id
+        gameIndex = position
+        ARouter.getInstance().build(RouterUrlCommon.gameIntroduction)
+            .withString("gameCode", bean.gameCode)
+            .withString("playClass", bean.playClass)
+            .withString("videoUrl", bean.gameVideoUrl)
+            .withString("desn", bean.desn)
+            .withTransition(R.anim.leftin, R.anim.leftout)
+            .navigation(mContext)
+    }
+
     @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {

+ 14 - 0
workbenches/src/main/java/com/yingyang/workbenches/freetraining/FreeTrainViewModel.kt

@@ -54,4 +54,18 @@ class FreeTrainViewModel : BaseViewModel() {
         success,
         fail
     )
+
+    /**
+     * 游戏重玩
+     */
+    fun gameReplay(
+        id: String,
+        fail: ((msg: String) -> Unit)? = null,
+        success: ((success: Any?) -> Unit)? = null,
+    ) = launchFlow(true) {
+        WORKBENCHES_API.gameReplay(id)
+    }.runUI(
+        success,
+        fail
+    )
 }

+ 6 - 0
workbenches/src/main/java/com/yingyang/workbenches/net/WorkbenchesApiService.kt

@@ -99,4 +99,10 @@ interface WorkbenchesApiService {
      */
     @POST("app/task/variationTendencyByType")
     suspend fun getVariationTendencyByType(): BaseResp<List<VariationTendencyByTypeBean>>
+
+    /**
+     * 游戏重玩
+     */
+    @POST("app/game/replay")
+    suspend fun gameReplay(@Query("id") id: String): BaseResp<Any>
 }