|
|
package com.br_technology.securitytrain_master.ui.view.home.fragment
|
|
|
|
|
|
import com.br_technology.securitytrain_master.R
|
|
|
import android.content.Intent
|
|
|
import android.os.Bundle
|
|
|
import android.view.View
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import com.br_technology.securitytrain_master.base.common.ConstantParamKey
|
|
|
import com.br_technology.securitytrain_master.databinding.FragmentResultBinding
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.adapter.ResultAdapter
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendData
|
|
|
import com.br_technology.securitytrain_master.expand.addItemDecoration2
|
|
|
import com.br_technology.securitytrain_master.ui.bean.*
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.activity.DatabaseDetailActivity
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.activity.course.CourseDetailActivity
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.activity.course.TextDetailActivity
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.adapter.SearchAdapter
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendBean
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonBean
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.ResultViewModel
|
|
|
import com.br_technology.securitytrain_master.util.TranslateUnit
|
|
|
import com.br_technology.securitytrain_master.view.VerticalDecoration
|
|
|
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleFragment
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
|
|
|
|
/**
|
|
|
* createTime:2021/7/28 15:39
|
|
|
* auth:张继
|
|
|
* des:
|
|
|
*/
|
|
|
class ResultFragment : BaseLifeCycleFragment<ResultViewModel,FragmentResultBinding>(FragmentResultBinding::inflate) {
|
|
|
class ResultFragment(val type: Int) :
|
|
|
BaseLifeCycleFragment<ResultViewModel, FragmentResultBinding>(FragmentResultBinding::inflate),
|
|
|
SearchAdapter.ISearchClick {
|
|
|
|
|
|
override fun initData() {
|
|
|
super.initData()
|
|
|
var page = 1
|
|
|
var keywords = ""
|
|
|
|
|
|
override fun initView() {
|
|
|
super.initView()
|
|
|
var str = ""
|
|
|
when (type) {
|
|
|
ResultViewModel.ResultType.TYPE_ZERO -> {
|
|
|
str = "暂无在线课程"
|
|
|
}
|
|
|
ResultViewModel.ResultType.TYPE_ONE -> {
|
|
|
str = "暂无直播课程"
|
|
|
}
|
|
|
ResultViewModel.ResultType.TYPE_TWO -> {
|
|
|
str = "暂无文本课程"
|
|
|
}
|
|
|
ResultViewModel.ResultType.TYPE_THREE -> {
|
|
|
str = "暂无资料库"
|
|
|
}
|
|
|
}
|
|
|
binding.tvNoData.text = str
|
|
|
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, "思维导图高分作文法(高中)议论", "从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"),
|
|
|
when (type) {
|
|
|
0 -> {
|
|
|
result.addItemDecoration2(2, 15, 16)
|
|
|
result.layoutManager = GridLayoutManager(requireActivity(), 2)
|
|
|
}
|
|
|
else -> {
|
|
|
result.addItemDecoration(
|
|
|
VerticalDecoration(
|
|
|
TranslateUnit.dp2px(context, 16f),
|
|
|
0
|
|
|
)
|
|
|
)
|
|
|
val resultAdapter = ResultAdapter()
|
|
|
result.adapter = resultAdapter
|
|
|
// resultAdapter.addList(recommendList)
|
|
|
result.layoutManager = LinearLayoutManager(requireActivity())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var searchAdapter: SearchAdapter? = null
|
|
|
|
|
|
override fun initData() {
|
|
|
super.initData()
|
|
|
refresh()
|
|
|
}
|
|
|
|
|
|
override fun initDataObserver() {
|
|
|
mViewModel.videoData.observe(this, {
|
|
|
val data = it.data.list.data
|
|
|
setData(transData(data))
|
|
|
})
|
|
|
mViewModel.liveData.observe(this, {
|
|
|
val data = it.data.list.data
|
|
|
setData(transData(data))
|
|
|
})
|
|
|
mViewModel.txtData.observe(this, {
|
|
|
val data = it.data.list.data
|
|
|
setData(transData(data))
|
|
|
})
|
|
|
|
|
|
mViewModel.materialData.observe(this, {
|
|
|
val data = it.data.list.data
|
|
|
setData(transData(data))
|
|
|
})
|
|
|
}
|
|
|
|
|
|
private fun setData(data: List<SearchBean>) {
|
|
|
binding.smartRefresh.finishLoadMore()
|
|
|
binding.smartRefresh.finishRefresh()
|
|
|
binding.smartRefresh.setEnableLoadMore(data.size == 10)
|
|
|
if (page == 1) {
|
|
|
searchAdapter = SearchAdapter()
|
|
|
searchAdapter?.setList(data)
|
|
|
searchAdapter?.setIClickItem(this)
|
|
|
binding.result.adapter = searchAdapter
|
|
|
} else {
|
|
|
searchAdapter?.addData(data)
|
|
|
}
|
|
|
binding.smartRefresh.visibility = if (searchAdapter?.itemCount!! > 0) {
|
|
|
View.VISIBLE
|
|
|
} else {
|
|
|
View.GONE
|
|
|
}
|
|
|
binding.tvNoData.visibility = if (searchAdapter?.itemCount!! > 0) {
|
|
|
View.GONE
|
|
|
} else {
|
|
|
View.VISIBLE
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private fun transData(data: List<Any>): List<SearchBean> {
|
|
|
val list = mutableListOf<SearchBean>()
|
|
|
for (item in data) {
|
|
|
val putData = SearchBean(type)
|
|
|
if (item is LessonBean) {
|
|
|
putData.txtData = item
|
|
|
}
|
|
|
if (item is LessonLive) {
|
|
|
putData.liveData = item
|
|
|
}
|
|
|
if (item is VideoLessonBean.ListBean.DataBean) {
|
|
|
putData.videoData = item
|
|
|
}
|
|
|
if (item is RecommendBean.ListBean) {
|
|
|
putData.materialData = item
|
|
|
}
|
|
|
list.add(putData)
|
|
|
}
|
|
|
return list
|
|
|
}
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
EventBus.getDefault().register(this)
|
|
|
}
|
|
|
|
|
|
override fun onDestroyView() {
|
|
|
EventBus.getDefault().unregister(this)
|
|
|
super.onDestroyView()
|
|
|
}
|
|
|
|
|
|
fun refresh() {
|
|
|
page = 1
|
|
|
mViewModel.loadData(type, keywords, page)
|
|
|
}
|
|
|
|
|
|
fun loadData() {
|
|
|
page++
|
|
|
mViewModel.loadData(type, keywords, page)
|
|
|
}
|
|
|
|
|
|
@Subscribe
|
|
|
fun search(search: SearchEvent) {
|
|
|
keywords = search.search
|
|
|
refresh()
|
|
|
}
|
|
|
|
|
|
override fun clickItem(item: SearchBean) {
|
|
|
when (type) {
|
|
|
ResultViewModel.ResultType.TYPE_ZERO -> {
|
|
|
val course = CourseParam()
|
|
|
val data = item.videoData
|
|
|
course.mLessonId = "${data?.id}"
|
|
|
course.isTrainClass = false
|
|
|
course.type = data?.type?.toInt() ?: 0
|
|
|
this@ResultFragment.startActivity(
|
|
|
Intent(
|
|
|
requireActivity(),
|
|
|
CourseDetailActivity::class.java
|
|
|
).putExtra(ConstantParamKey.COURSE_BEAN, course)
|
|
|
)
|
|
|
}
|
|
|
ResultViewModel.ResultType.TYPE_ONE -> {
|
|
|
}
|
|
|
ResultViewModel.ResultType.TYPE_TWO -> {
|
|
|
val course = CourseParam()
|
|
|
val data = item.txtData
|
|
|
course.mLessonId = "${data?.id}"
|
|
|
course.isTrainClass = true
|
|
|
course.mTrainClassId = "${data?.train_class_id}"
|
|
|
this@ResultFragment.startActivity(
|
|
|
Intent(
|
|
|
requireActivity(),
|
|
|
TextDetailActivity::class.java
|
|
|
).putExtra(ConstantParamKey.COURSE_BEAN, course)
|
|
|
)
|
|
|
}
|
|
|
ResultViewModel.ResultType.TYPE_THREE -> {
|
|
|
val data = item.materialData
|
|
|
this@ResultFragment.startActivity(
|
|
|
Intent(requireActivity(), DatabaseDetailActivity::class.java)
|
|
|
.putExtra(ConstantParamKey.DOC_ID, data?.id)
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|