package com.dollearn.student.ui.home
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.gone
|
import com.dollearn.student.R
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.entity.Banner
|
import com.dollearn.student.network.entity.VideoTypeBean
|
import com.dollearn.student.network.request
|
import com.dollearn.student.ui.TransparentStatusBarActivity
|
import com.dollearn.student.ui.home.adapter.HomeBannerAdapter
|
import com.dollearn.student.ui.home.adapter.VideoTypeAdapter
|
import com.dollearn.student.utils.extention.clickDelay
|
import com.youth.banner.indicator.CircleIndicator
|
import kotlinx.android.synthetic.main.activity_video_home.*
|
import org.jetbrains.anko.startActivity
|
|
class VideoHomeActivity : TransparentStatusBarActivity() {
|
override fun setContentView() = R.layout.activity_video_home
|
|
private val type by lazy { intent.getIntExtra("type", TYPE_COURSE) }
|
private var search:String? = null
|
|
private val bannerImg = arrayListOf<Banner>()
|
private val bannerAdapter by lazy {
|
HomeBannerAdapter(bannerImg, this)
|
}
|
|
private val list = arrayListOf<VideoTypeBean>()
|
private val adapter = VideoTypeAdapter(list,object :VideoTypeAdapter.Callback{
|
override fun onMore(position: Int) {
|
startActivity<VideoListActivity>("id" to list[position].id,"type" to type)
|
}
|
|
override fun onVideoDetail(id: String) {
|
startActivity<VideoDetailActivity>("id" to id,"type" to type)
|
}
|
})
|
|
override fun initClick() {
|
banner.setOnBannerListener { data, position ->
|
val banner = data as Banner
|
banner.name = banner.model
|
banner.jumpPage(this)
|
}
|
|
tv_search.clickDelay {
|
val s = et_search.text.toString()
|
search = if (s.isNullOrEmpty()) null else s
|
refreshLayout.autoRefresh()
|
}
|
}
|
|
override fun initView() {
|
title = if (type == TYPE_COURSE) "线上课得积分" else "看视频得奖励"
|
banner.adapter = bannerAdapter
|
banner.indicator = CircleIndicator(this)
|
getBanner()
|
rv_video.layoutManager = LinearLayoutManager(this)
|
rv_video.adapter = adapter
|
refreshLayout.setOnRefreshListener {
|
getData()
|
}
|
getData()
|
}
|
|
private fun getBanner() {
|
HttpManager.queryBanner(type+1).request(this){_,data->
|
bannerImg.addAll(data?: arrayListOf())
|
if (bannerImg.isEmpty())
|
banner.gone()
|
else
|
bannerAdapter.notifyDataSetChanged()
|
banner.setCurrentItem(1)
|
}
|
}
|
|
private fun getData(){
|
HttpManager.queryClassificationBenefitsVideosList(type,search).request(this,success = {_,data->
|
refreshLayout.finishRefresh()
|
list.clear()
|
list.addAll(data?: arrayListOf())
|
adapter.notifyDataSetChanged()
|
}){_,_->
|
refreshLayout.finishRefresh(false)
|
}
|
}
|
|
companion object{
|
const val TYPE_COURSE = 1 //线上课得积分
|
const val TYPE_VIDEO = 2 //看视频得奖励
|
const val TYPE_PRACTICE = 3 //课后练习
|
}
|
}
|