| | |
| | | package com.dollearn.student.ui.home |
| | | |
| | | import androidx.constraintlayout.widget.ConstraintLayout |
| | | 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 |
| | |
| | | override fun initView() { |
| | | title = "" |
| | | getSchedule() |
| | | EventBus.getDefault().register(this) |
| | | } |
| | | |
| | | private fun getSchedule(){ |
| | | initTab(7) //todo test |
| | | |
| | | // HttpManager.studySchedule(week,1).request(this){_,data-> |
| | | // data?.apply { |
| | | // initTab(if (computeSchedule == 100) 7 else day) |
| | | // currentDay = day |
| | | // } |
| | | // } |
| | | HttpManager.studySchedule(week,1).request(this){_,data-> |
| | | data?.apply { |
| | | currentDay = day |
| | | initTab(if (computeSchedule == 100) 7 else day) |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun initTab(day:Int) { |
| | | val title = titles.take(day) |
| | | title.forEachIndexed { index, s -> |
| | | titles.forEachIndexed { index, s -> |
| | | if (index<5){ |
| | | frags.add(DailyFragment.newInstance(index+1)) |
| | | }else |
| | | frags.add(WeekendFragment.newInstance(index+1)) |
| | | } |
| | | val layoutParams = tab_bar.layoutParams as ConstraintLayout.LayoutParams |
| | | val anchors = listOf(R.id.tv_1,R.id.tv_2,R.id.tv_3,R.id.tv_4,R.id.tv_5,R.id.tv_6,R.id.tv_7,R.id.tv_8) |
| | | layoutParams.endToStart = anchors[day] |
| | | tab_bar.layoutParams = layoutParams |
| | | tab_bar.setViewPager(view_pager, title.toTypedArray(),this,frags) |
| | | 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) |
| | | } |
| | | } |