Browse Source

1.修改主页获取游戏列表接口

王鹏鹏 2 years ago
parent
commit
daffd0bc01

+ 8 - 46
workbenches/src/main/java/com/yingyang/workbenches/WorkbenchesActivity.kt

@@ -20,12 +20,6 @@ import com.yingyangfly.baselib.utils.User
 @Route(path = RouterUrlCommon.workbenches)
 class WorkbenchesActivity : BaseMVVMActivity<ActivityWorkbenchesBinding, WorkbenchesViewModel>() {
 
-    /**
-     * 第几页
-     */
-    private var page = 0
-    private var gameList = mutableListOf<Record>()
-
     /**
      * 游戏adapter
      */
@@ -37,8 +31,6 @@ class WorkbenchesActivity : BaseMVVMActivity<ActivityWorkbenchesBinding, Workben
         }
         gameAdapter.setContext(this@WorkbenchesActivity)
         binding {
-            swipeGame.setEnableRefresh(true)
-            swipeGame.setEnableLoadMore(true)
             rvGame.layoutManager = GridLayoutManager(this@WorkbenchesActivity, 4)
             rvGame.adapter = gameAdapter
         }
@@ -46,7 +38,7 @@ class WorkbenchesActivity : BaseMVVMActivity<ActivityWorkbenchesBinding, Workben
             JumpUtil.jumpActivityWithUrlAndDesn(
                 RouterUrlCommon.WEB_VIEW_INTERACTION_JS,
                 bean.gameUrl,
-                bean.desn
+                bean.desn ?: ""
             )
         }
     }
@@ -98,57 +90,27 @@ class WorkbenchesActivity : BaseMVVMActivity<ActivityWorkbenchesBinding, Workben
     }
 
     override fun initData() {
-        binding {
-            swipeGame.setOnRefreshListener {
-                getGameList(true)
-            }
-            swipeGame.setOnLoadMoreListener {
-                getGameList(false)
-            }
-        }
+
     }
 
     /**
      * 加载游戏数据
      */
     @SuppressLint("NotifyDataSetChanged")
-    private fun getGameList(isRefresh: Boolean) {
-        if (isRefresh) {
-            gameList.clear()
-            binding.swipeGame.resetNoMoreData()
-            page = 1
-        } else {
-            page++
-        }
-        viewModel.getGameList(page, fail = {
-            endRefresh()
-            "数据加载失败,请重试".toast()
+    private fun getGameList() {
+        viewModel.getGameList(fail = {
+            it.toast()
         }, success = {
-            endRefresh()
-            if (it.records.isNullOrEmpty().not()) {
-                gameList.addAll(it.records)
-            }
-            gameAdapter.setData(gameList)
-            if (page >= it.pages) {
-                binding.swipeGame.finishLoadMoreWithNoMoreData()
+            if (it.isNullOrEmpty().not()) {
+                gameAdapter.setData(it)
             }
         })
     }
 
-    /**
-     * 加载完成取消旋转框
-     */
-    private fun endRefresh() {
-        binding {
-            swipeGame.finishRefresh()
-            swipeGame.finishLoadMore()
-        }
-    }
-
     override fun onResume() {
         super.onResume()
         //加载游戏列表
-        getGameList(true)
+        getGameList()
         //获取脑力值和训练时长接口
         getCountTrain()
     }

+ 3 - 12
workbenches/src/main/java/com/yingyang/workbenches/WorkbenchesViewModel.kt

@@ -1,12 +1,9 @@
 package com.yingyang.workbenches
 
 import com.yingyang.workbenches.entity.CountTrainBean
-import com.yingyang.workbenches.entity.WorkBenchesBean
-import com.yingyang.workbenches.entity.WorkBenchesRequestBodyBean
+import com.yingyang.workbenches.entity.Record
 import com.yingyang.workbenches.net.WORKBENCHES_API
 import com.yingyangfly.baselib.mvvm.BaseViewModel
-import com.yingyangfly.baselib.net.XUtils
-import com.yingyangfly.baselib.utils.GsonUtil
 
 /**
  * @author 王鹏鹏
@@ -18,16 +15,10 @@ class WorkbenchesViewModel : BaseViewModel() {
      * 获取游戏列表
      */
     fun getGameList(
-        pageStr: Int,
         fail: ((msg: String) -> Unit)? = null,
-        success: ((success: WorkBenchesBean) -> Unit)? = null,
+        success: ((success: List<Record>) -> Unit)? = null,
     ) = launchFlow(false) {
-        val requestBean = WorkBenchesRequestBodyBean().apply {
-            page = pageStr.toString()
-            limit = "12"
-        }
-        val body = XUtils.createJson(GsonUtil.GsonString(requestBean))
-        WORKBENCHES_API.getGameList(body)
+        WORKBENCHES_API.getGameList()
     }.runUI(
         success,
         fail

+ 3 - 13
workbenches/src/main/java/com/yingyang/workbenches/entity/WorkBenchesBean.kt

@@ -1,18 +1,8 @@
 package com.yingyang.workbenches.entity
 
-data class WorkBenchesBean(
-    val countId: Any,
-    val current: Int,
-    val maxLimit: Any,
-    val optimizeCountSql: Boolean,
-    val orders: List<Any>,
-    val pages: Int,
-    val records: List<Record>,
-    val searchCount: Boolean,
-    val size: Int,
-    val total: Int
-)
-
+/**
+ * 游戏列表bean
+ */
 data class Record(
     val createBy: String,
     val createTime: String,

+ 3 - 10
workbenches/src/main/java/com/yingyang/workbenches/net/WorkbenchesApiService.kt

@@ -1,12 +1,7 @@
 package com.yingyang.workbenches.net
 
-import com.yingyang.workbenches.entity.CountTrainBean
-import com.yingyang.workbenches.entity.LeisureBrainListBean
-import com.yingyang.workbenches.entity.ServicePackageBean
-import com.yingyang.workbenches.entity.WorkBenchesBean
+import com.yingyang.workbenches.entity.*
 import com.yingyangfly.baselib.net.BaseResp
-import okhttp3.RequestBody
-import retrofit2.http.Body
 import retrofit2.http.POST
 
 interface WorkbenchesApiService {
@@ -14,10 +9,8 @@ interface WorkbenchesApiService {
     /**
      * 获取首页游戏列表
      */
-    @POST("game/list")
-    suspend fun getGameList(
-        @Body requestBody: RequestBody
-    ): BaseResp<WorkBenchesBean>
+    @POST("app/game/selectMyList")
+    suspend fun getGameList(): BaseResp<List<Record>>
 
     /**
      * 获取脑力值和累计训练时长

+ 6 - 16
workbenches/src/main/res/layout/activity_workbenches.xml

@@ -65,7 +65,8 @@
                         android:layout_height="@dimen/divider_35px"
                         android:layout_marginTop="@dimen/divider_37px"
                         android:background="@mipmap/icon_live_broadcast"
-                        android:scaleType="centerInside" />
+                        android:scaleType="centerInside"
+                        tools:ignore="ContentDescription" />
 
                     <TextView
                         style="@style/workbenches_home_text"
@@ -159,25 +160,14 @@
             android:layout_marginTop="@dimen/divider_5px"
             android:orientation="horizontal">
 
-            <com.scwang.smart.refresh.layout.SmartRefreshLayout
-                android:id="@+id/swipeGame"
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/rvGame"
                 android:layout_width="0dp"
                 android:layout_height="match_parent"
                 android:layout_marginStart="@dimen/divider_48px"
                 android:layout_marginTop="@dimen/divider_12px"
-                android:layout_weight="1">
-
-                <com.scwang.smart.refresh.header.ClassicsHeader
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content" />
-
-                <androidx.recyclerview.widget.RecyclerView
-                    android:id="@+id/rvGame"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    tools:listitem="@layout/item_game_list" />
-
-            </com.scwang.smart.refresh.layout.SmartRefreshLayout>
+                android:layout_weight="1"
+                tools:listitem="@layout/item_game_list" />
 
             <androidx.cardview.widget.CardView
                 android:layout_width="@dimen/divider_200px"