feat:玩法列表支持最多 3 行並滾動
This commit is contained in:
@@ -11,6 +11,7 @@ import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.avroom.adapter.RoomGameListAdapter
|
||||
import com.chwl.app.base.BaseActivity
|
||||
@@ -38,7 +39,7 @@ class RoomGameListDialog :
|
||||
private var compositeDisposable: CompositeDisposable? = null
|
||||
private val adapter = RoomGameListAdapter()
|
||||
private var dialogManager: DialogManager? = null
|
||||
|
||||
private lateinit var recycleView: RecyclerView
|
||||
override fun getTheme(): Int {
|
||||
return R.style.ErbanBottomSheetDialogDimFalse
|
||||
}
|
||||
@@ -61,6 +62,8 @@ class RoomGameListDialog :
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
initView()
|
||||
val recyclerView: RecyclerView = view.findViewById(R.id.recyclerView)
|
||||
recycleView = recyclerView
|
||||
switchStatus(0)
|
||||
requestData()
|
||||
}
|
||||
@@ -89,6 +92,14 @@ class RoomGameListDialog :
|
||||
binding?.recyclerView?.adapter = adapter
|
||||
}
|
||||
|
||||
private fun updateDialogHeight(count: Int) {
|
||||
if (count > 10) {
|
||||
val layoutParams = recycleView.layoutParams
|
||||
layoutParams.height = 600
|
||||
recycleView.layoutParams = layoutParams
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestData() {
|
||||
val dataService =
|
||||
AudioRoomContext.get()
|
||||
@@ -96,6 +107,7 @@ class RoomGameListDialog :
|
||||
val cacheKey = "game_list#${parentFragment.hashCode()}"
|
||||
val list = dataService?.getData(cacheKey) as? List<GameInfo>
|
||||
if (!list.isNullOrEmpty()) {
|
||||
updateDialogHeight(list.size)
|
||||
loadData(list)
|
||||
return
|
||||
}
|
||||
@@ -106,6 +118,7 @@ class RoomGameListDialog :
|
||||
}
|
||||
.subscribe { it: List<GameInfo> ->
|
||||
dataService?.putData(cacheKey, it)
|
||||
updateDialogHeight(it.size)
|
||||
loadData(it)
|
||||
}
|
||||
getCompositeDisposable().add(disposable)
|
||||
|
@@ -10,6 +10,7 @@ import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.avroom.activity.CreatePKActivity
|
||||
@@ -43,6 +44,8 @@ import io.reactivex.disposables.CompositeDisposable
|
||||
class RoomGameplayDialog : BottomSheetDialogFragment() {
|
||||
|
||||
var isOnlyPK = false
|
||||
private lateinit var recycleView: RecyclerView
|
||||
|
||||
private var binding: RoomGameplayDialogBinding? = null
|
||||
private var compositeDisposable: CompositeDisposable? = null
|
||||
private val adapter = RoomGameplayAdapter()
|
||||
@@ -71,13 +74,12 @@ class RoomGameplayDialog : BottomSheetDialogFragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
initView()
|
||||
switchStatus(0)
|
||||
requestData()
|
||||
|
||||
val recyclerView: RecyclerView = view.findViewById(R.id.recyclerView)
|
||||
recyclerView.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
val itemHeight = resources
|
||||
}
|
||||
recycleView = recyclerView
|
||||
|
||||
switchStatus(0)
|
||||
requestData()
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
@@ -114,10 +116,8 @@ class RoomGameplayDialog : BottomSheetDialogFragment() {
|
||||
val list = dataService?.getData(cacheKey) as? List<RoomIcon>
|
||||
|
||||
if (!list.isNullOrEmpty()) {
|
||||
var mutableList = mutableListOf<RoomIcon>()
|
||||
mutableList.addAll(list)
|
||||
|
||||
loadSuccess(mutableList)
|
||||
updateDialogHeight(list.size)
|
||||
loadSuccess(list)
|
||||
return
|
||||
}
|
||||
val disposable = AvRoomModel.get().roomGamePlayList
|
||||
@@ -126,12 +126,21 @@ class RoomGameplayDialog : BottomSheetDialogFragment() {
|
||||
}
|
||||
.subscribe { it: List<RoomIcon> ->
|
||||
dataService?.putData(cacheKey, it)
|
||||
updateDialogHeight(it.size)
|
||||
loadSuccess(it)
|
||||
}
|
||||
getCompositeDisposable().add(disposable)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateDialogHeight(count: Int) {
|
||||
if (count > 10) {
|
||||
val layoutParams = recycleView.layoutParams
|
||||
layoutParams.height = 600
|
||||
recycleView.layoutParams = layoutParams
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadSuccess(list: List<RoomIcon>?) {
|
||||
var finalList = mutableListOf<RoomGameplayItem>()
|
||||
if (isOnlyPK) {
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 6.5 KiB |
Reference in New Issue
Block a user