|
|
@@ -1,16 +1,15 @@
|
|
|
package com.yingyang.workbenches.freetraining
|
|
|
|
|
|
+import android.text.TextUtils
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
-import com.scwang.smartrefresh.layout.api.RefreshLayout
|
|
|
import com.yingyang.workbenches.adapter.FreeTrainAdapter
|
|
|
import com.yingyang.workbenches.adapter.FreeTrainTypeAdapter
|
|
|
import com.yingyang.workbenches.databinding.ActivityFreeTrainBinding
|
|
|
import com.yingyang.workbenches.entity.Record
|
|
|
import com.yingyang.workbenches.entity.TrainTypeBean
|
|
|
import com.yingyangfly.baselib.ext.setOnSingleClickListener
|
|
|
-import com.yingyangfly.baselib.ext.show
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
@@ -33,6 +32,8 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
/**
|
|
|
* 自由训练游戏列表
|
|
|
*/
|
|
|
+ private var gameId = ""
|
|
|
+ private var gameIndex = 0
|
|
|
private var gridLayoutManager: GridLayoutManager? = null
|
|
|
private var freeTrainList = mutableListOf<Record>()
|
|
|
private val freeTrainListAdapter by lazy { FreeTrainAdapter() }
|
|
|
@@ -62,7 +63,9 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
rvTrain.layoutManager = gridLayoutManager
|
|
|
rvTrain.adapter = freeTrainListAdapter
|
|
|
freeTrainListAdapter.setType(type)
|
|
|
- freeTrainListAdapter.onGameClickListener = { bean ->
|
|
|
+ freeTrainListAdapter.onGameClickListener = { bean, position ->
|
|
|
+ gameId = bean.id
|
|
|
+ gameIndex = position
|
|
|
val str =
|
|
|
bean.gameUrl + "?gameCode=" + bean.gameCode + "&isFull=false&isSound=true&playClass=" + bean.playClass +
|
|
|
"&userToken=" + User.getToken()
|
|
|
@@ -96,9 +99,29 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
getSelectByDictType()
|
|
|
- freeTrainListAdapter.clearData()
|
|
|
- freeTrainListAdapter.showEmptyView = false
|
|
|
- loadData(true, true)
|
|
|
+// if (TextUtils.isEmpty(gameId)) {
|
|
|
+ freeTrainListAdapter.clearData()
|
|
|
+ freeTrainListAdapter.showEmptyView = false
|
|
|
+ loadData(true, true)
|
|
|
+// } else {
|
|
|
+// getGameDetail()
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取游戏详情
|
|
|
+ */
|
|
|
+ private fun getGameDetail() {
|
|
|
+ viewModel.getGameDetail(gameId, fail = {
|
|
|
+ it.toast()
|
|
|
+ }, success = {
|
|
|
+ if (it != null && freeTrainListAdapter.data.isNullOrEmpty().not()) {
|
|
|
+ if (TextUtils.equals(freeTrainListAdapter.data[gameIndex].id, it.id)) {
|
|
|
+ freeTrainListAdapter.data.set(gameIndex, it)
|
|
|
+ freeTrainListAdapter.notifyItemChanged(gameIndex)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -144,7 +167,7 @@ class FreeTrainActivity : BaseMVVMActivity<ActivityFreeTrainBinding, FreeTrainVi
|
|
|
if (freeTrainList.isNullOrEmpty()) {
|
|
|
gridLayoutManager?.spanCount = 1
|
|
|
} else {
|
|
|
- gridLayoutManager?.spanCount = 1
|
|
|
+ gridLayoutManager?.spanCount = 4
|
|
|
}
|
|
|
freeTrainListAdapter.showEmptyView = freeTrainList.isNullOrEmpty()
|
|
|
freeTrainListAdapter.setData(freeTrainList)
|