|
|
@@ -33,6 +33,7 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
/**
|
|
|
* 自由训练游戏列表
|
|
|
*/
|
|
|
+ private var gridLayoutManager: GridLayoutManager? = null
|
|
|
private var freeTrainList = mutableListOf<Record>()
|
|
|
private val freeTrainListAdapter by lazy { FreeTrainAdapter() }
|
|
|
|
|
|
@@ -52,19 +53,18 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
binding.tvTitle.text = bean.dictLabel
|
|
|
type = bean.dictValue
|
|
|
freeTrainListAdapter.setType(type)
|
|
|
- binding {
|
|
|
- rvTrain.show(true)
|
|
|
- emptyLayout.show(false)
|
|
|
- }
|
|
|
- loadData(true)
|
|
|
+ freeTrainListAdapter.clearData()
|
|
|
+ freeTrainListAdapter.showEmptyView = false
|
|
|
+ loadData(true, true)
|
|
|
}
|
|
|
//自由训练游戏列表
|
|
|
- rvTrain.layoutManager = GridLayoutManager(this@FreeTrainActivity, 4)
|
|
|
+ gridLayoutManager = GridLayoutManager(this@FreeTrainActivity, 4)
|
|
|
+ rvTrain.layoutManager = gridLayoutManager
|
|
|
rvTrain.adapter = freeTrainListAdapter
|
|
|
freeTrainListAdapter.setType(type)
|
|
|
freeTrainListAdapter.onGameClickListener = { bean ->
|
|
|
val str =
|
|
|
- bean.gameUrl + "?gameCode=" + bean.gameCode + "&playClass=" + bean.playClass +
|
|
|
+ bean.gameUrl + "?gameCode=" + bean.gameCode + "&isFull=true&isSound=true&playClass=" + bean.playClass +
|
|
|
"&userToken=" + User.getToken()
|
|
|
JumpUtil.jumpActivityWithUrl(RouterUrlCommon.WEB_VIEW_INTERACTION_JS, str, mContext)
|
|
|
}
|
|
|
@@ -78,11 +78,13 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
}
|
|
|
|
|
|
freeTrainSwipe.setOnRefreshListener {
|
|
|
- loadData(true)
|
|
|
+ freeTrainListAdapter.showEmptyView = false
|
|
|
+ freeTrainListAdapter.clearData()
|
|
|
+ loadData(true, false)
|
|
|
}
|
|
|
|
|
|
freeTrainSwipe.setOnLoadMoreListener {
|
|
|
- loadData(false)
|
|
|
+ loadData(false, false)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -94,7 +96,9 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
getSelectByDictType()
|
|
|
- loadData(true)
|
|
|
+ freeTrainListAdapter.clearData()
|
|
|
+ freeTrainListAdapter.showEmptyView = false
|
|
|
+ loadData(true, true)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -116,7 +120,7 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
/**
|
|
|
* 加载列表
|
|
|
*/
|
|
|
- private fun loadData(isRefresh: Boolean) {
|
|
|
+ private fun loadData(isRefresh: Boolean, showLoading: Boolean) {
|
|
|
if (isRefresh) {
|
|
|
page = 1
|
|
|
binding.freeTrainSwipe.resetNoMoreData()
|
|
|
@@ -125,7 +129,7 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
} else {
|
|
|
page++
|
|
|
}
|
|
|
- viewModel.getFreeTrainList(type, page, fail = {
|
|
|
+ viewModel.getFreeTrainList(showLoading, type, page, fail = {
|
|
|
endRefresh()
|
|
|
it.toast()
|
|
|
}, success = {
|
|
|
@@ -137,8 +141,12 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
if (page >= it.pages) {
|
|
|
binding.freeTrainSwipe.finishLoadMoreWithNoMoreData()
|
|
|
}
|
|
|
- binding.freeTrainSwipe.show(freeTrainList.isNullOrEmpty().not())
|
|
|
- binding.emptyLayout.show(freeTrainList.isNullOrEmpty())
|
|
|
+ if (freeTrainList.isNullOrEmpty()) {
|
|
|
+ gridLayoutManager?.spanCount = 1
|
|
|
+ } else {
|
|
|
+ gridLayoutManager?.spanCount = 1
|
|
|
+ }
|
|
|
+ freeTrainListAdapter.showEmptyView = freeTrainList.isNullOrEmpty()
|
|
|
freeTrainListAdapter.setData(freeTrainList)
|
|
|
}
|
|
|
})
|