package com.dollearn.student.ui.game
|
|
import androidx.core.os.bundleOf
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.fragment.BaseFragment
|
import cn.sinata.xldutils.utils.SPUtils
|
import com.dollearn.student.R
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.requestByF
|
import com.dollearn.student.utils.Const
|
import kotlinx.android.synthetic.main.layout_common_list.*
|
|
class GameDataFragment : BaseFragment() {
|
override fun contentViewId() = R.layout.layout_common_list
|
|
private val type by lazy { arguments?.getInt("type", TYPE_ALL)?: TYPE_ALL }
|
private var page = 1
|
private val userId by lazy { SPUtils.instance().getString(Const.User.USER_ID) }
|
|
|
override fun onFirstVisibleToUser() {
|
rv_list.layoutManager = LinearLayoutManager(requireContext())
|
refreshLayout.setOnRefreshListener {
|
page = 1
|
getData()
|
}
|
refreshLayout.setOnLoadMoreListener {
|
page++
|
getData()
|
}
|
refreshLayout.autoRefresh()
|
}
|
|
fun refresh(){
|
refreshLayout.autoRefresh()
|
}
|
|
private fun getData(){
|
HttpManager.gameRecord(userId,page).requestByF(this,success = { _, data->
|
|
}){_,_->
|
if (page == 1)
|
refreshLayout.finishRefresh(false)
|
else
|
refreshLayout.finishLoadMore(false)
|
page--
|
}
|
}
|
|
companion object{//0=全部 1=待上课 2=已完成
|
const val TYPE_ALL = 0
|
const val TYPE_OFFLINE = 1
|
const val TYPE_ONLINE = 2
|
fun newInstance(type:Int):GameDataFragment{
|
val fragment = GameDataFragment()
|
fragment.arguments = bundleOf("type" to type)
|
return fragment
|
}
|
}
|
}
|