|
@@ -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()
|
|
|
}
|