罗明文
18 小时以前 442124baa483f8d1c4aaca7ff81e15dd3f122363
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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)
    }
}