package com.dollearn.student.ui.home
|
|
import androidx.fragment.app.Fragment
|
import com.dollearn.student.R
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.request
|
import com.dollearn.student.ui.TransparentStatusBarActivity
|
import com.dollearn.student.utils.Const
|
import com.dollearn.student.utils.event.IntEvent
|
import kotlinx.android.synthetic.main.activity_schedul.*
|
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.Subscribe
|
|
class ScheduleActivity :TransparentStatusBarActivity(){
|
override fun setContentView() = R.layout.activity_schedul
|
|
private val titles = arrayOf("Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "自主游戏", "听故事")
|
private val frags = arrayListOf<Fragment>()
|
|
val week by lazy { intent.getIntExtra("week",0) }
|
val season by lazy { intent.getIntExtra("season",0) }
|
|
var currentDay = 1
|
|
override fun initClick() {
|
}
|
|
override fun initView() {
|
title = ""
|
getSchedule()
|
EventBus.getDefault().register(this)
|
}
|
|
private fun getSchedule(){
|
HttpManager.studySchedule(week,1).request(this){_,data->
|
data?.apply {
|
currentDay = day
|
initTab(if (computeSchedule == 100) 7 else day)
|
}
|
}
|
}
|
|
private fun initTab(day:Int) {
|
titles.forEachIndexed { index, s ->
|
if (index<5){
|
frags.add(DailyFragment.newInstance(index+1))
|
}else
|
frags.add(WeekendFragment.newInstance(index+1))
|
}
|
tab_bar.setViewPager(view_pager, titles,this,frags)
|
tab_bar.currentTab = currentDay-1
|
view_pager.offscreenPageLimit = day
|
//设置不可点击的day
|
(day until 6).forEach {
|
tab_bar.getTitleView(it).isEnabled = false
|
}
|
if (tab_bar.currentTab == 0)
|
tab_bar.updateTabStyles()
|
}
|
|
fun unLockNext(day: Int){
|
currentDay = day
|
tab_bar.getTitleView(day - 1).isEnabled = true
|
tab_bar.currentTab = currentDay-1
|
}
|
|
@Subscribe
|
fun nextSubject(e: IntEvent){
|
if (e.code == Const.EventCode.NEXT_SUBJECT){
|
(frags[view_pager.currentItem] as DailyFragment).nextSubject(e.i)
|
}
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
EventBus.getDefault().unregister(this)
|
}
|
}
|