|
|
package com.br_technology.securitytrain_master.ui.view.mine.fragment
|
|
|
|
|
|
import com.br_technology.securitytrain_master.R
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.ViewGroup
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import com.br_technology.securitytrain_master.base.common.ConstantParamKey
|
|
|
import com.br_technology.securitytrain_master.base.view.BaseAdapter
|
|
|
import com.br_technology.securitytrain_master.databinding.AdapterSideslipBinding
|
|
|
import com.br_technology.securitytrain_master.databinding.FragmentCourseBinding
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendData
|
|
|
import com.br_technology.securitytrain_master.expand.glideRound
|
|
|
import com.br_technology.securitytrain_master.ui.bean.CourseParam
|
|
|
import com.br_technology.securitytrain_master.ui.bean.FavoriteData
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.activity.course.TextDetailActivity
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.DatabaseFViewModel
|
|
|
import com.br_technology.securitytrain_master.ui.view.mine.adapter.SideslipAdapter
|
|
|
import com.br_technology.securitytrain_master.view.listener.OnItemClickListener
|
|
|
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleFragment
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -12,73 +22,79 @@ import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleFragment |
|
|
* auth:张继
|
|
|
* des:资料
|
|
|
*/
|
|
|
class CourseFragment :BaseLifeCycleFragment<DatabaseFViewModel,FragmentCourseBinding>(FragmentCourseBinding::inflate){
|
|
|
class CourseFragment :
|
|
|
BaseLifeCycleFragment<DatabaseFViewModel, FragmentCourseBinding>(FragmentCourseBinding::inflate) {
|
|
|
var page = 1
|
|
|
var docAdapter = TxtAdapter()
|
|
|
override fun initData() {
|
|
|
super.initData()
|
|
|
binding.apply {
|
|
|
val recommendList = mutableListOf(
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
RecommendData(
|
|
|
R.mipmap.banner,
|
|
|
"思维导图高分作文法(高中)议论",
|
|
|
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
|
|
|
),
|
|
|
)
|
|
|
val resultAdapter = SideslipAdapter()
|
|
|
result.adapter = resultAdapter
|
|
|
resultAdapter.addList(recommendList)
|
|
|
refresh()
|
|
|
}
|
|
|
|
|
|
override fun initView() {
|
|
|
super.initView()
|
|
|
binding.smartRefresh.setOnRefreshListener {
|
|
|
refresh()
|
|
|
}
|
|
|
binding.smartRefresh.setOnLoadMoreListener {
|
|
|
loadMore()
|
|
|
}
|
|
|
binding.result.layoutManager = LinearLayoutManager(requireContext())
|
|
|
}
|
|
|
|
|
|
override fun initDataObserver() {
|
|
|
mViewModel.lessonList.observe(this, {
|
|
|
if (page == 1) {
|
|
|
docAdapter = TxtAdapter()
|
|
|
binding.result.adapter = docAdapter
|
|
|
docAdapter.addList(it.data.list.data)
|
|
|
docAdapter.apply {
|
|
|
addListener(object : OnItemClickListener<FavoriteData> {
|
|
|
override fun onClick(position: Int, data: FavoriteData) {
|
|
|
val course = CourseParam()
|
|
|
course.mLessonId = data.object_id
|
|
|
course.isTrainClass = true
|
|
|
course.title = data.title
|
|
|
this@CourseFragment.startActivity(
|
|
|
Intent(requireActivity(), TextDetailActivity::class.java)
|
|
|
.putExtra(ConstantParamKey.COURSE_BEAN, course)
|
|
|
)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
} else {
|
|
|
docAdapter.addList(it.data.list.data)
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
|
|
|
private fun refresh() {
|
|
|
page = 1
|
|
|
mViewModel.getCollectLessonList(page)
|
|
|
binding.smartRefresh.setEnableLoadMore(false)
|
|
|
}
|
|
|
|
|
|
private fun loadMore() {
|
|
|
page++
|
|
|
mViewModel.getCollectDocList(page)
|
|
|
binding.smartRefresh.setEnableRefresh(false)
|
|
|
}
|
|
|
|
|
|
class TxtAdapter : BaseAdapter<FavoriteData, AdapterSideslipBinding>() {
|
|
|
override fun getViewBinding(
|
|
|
context: Context,
|
|
|
parent: ViewGroup,
|
|
|
viewType: Int,
|
|
|
from: LayoutInflater
|
|
|
): AdapterSideslipBinding {
|
|
|
return AdapterSideslipBinding.inflate(from, parent, false)
|
|
|
}
|
|
|
|
|
|
override fun onBind(holder: AdapterSideslipBinding, position: Int, data: FavoriteData) {
|
|
|
holder.pic.glideRound(data.image, 16)
|
|
|
holder.name.text = data.title
|
|
|
holder.info.text = data.des
|
|
|
}
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|