| | |
| | | import android.widget.TextView |
| | | import androidx.core.os.bundleOf |
| | | import cn.sinata.xldutils.fragment.BaseFragment |
| | | import cn.sinata.xldutils.utils.myToast |
| | | import cn.sinata.xldutils.utils.showAllowingStateLoss |
| | | import com.dollearn.student.R |
| | | import com.dollearn.student.dialog.TipDialog |
| | | import com.dollearn.student.network.Apis |
| | | import com.dollearn.student.network.HttpManager |
| | | import com.dollearn.student.network.requestByF |
| | | import com.dollearn.student.utils.Const |
| | | import com.dollearn.student.utils.event.EmptyEvent |
| | | import com.dollearn.student.utils.extention.clickDelay |
| | | import com.dollearn.student.utils.extention.formatToChinese |
| | | import kotlinx.android.synthetic.main.fragment_daily.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.jetbrains.anko.backgroundResource |
| | | import org.jetbrains.anko.support.v4.browse |
| | | import org.jetbrains.anko.support.v4.startActivityForResult |
| | | import org.jetbrains.anko.support.v4.toast |
| | | |
| | |
| | | private val week by lazy { |
| | | (requireActivity() as ScheduleActivity).week |
| | | } |
| | | private val current by lazy { |
| | | (requireActivity() as ScheduleActivity).currentDay |
| | | } |
| | | |
| | | |
| | | override fun onFirstVisibleToUser() { |
| | | getProgress() |
| | | cl_1.clickDelay { |
| | | showDialog("加载题目...") |
| | | HttpManager.listenSelectPicture(season, week, day).requestByF(this){_,data-> |
| | | HttpManager.listenSelectPicture(season, week, day).requestByF(this,false, {_,data-> |
| | | startActivityForResult<ListenActivity>(1,"data" to data,"day" to day,"week" to week,"season" to season) |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER)) |
| | | }){_,msg-> |
| | | handleError(msg) |
| | | } |
| | | } |
| | | cl_2.clickDelay { |
| | | showDialog("加载题目...") |
| | | HttpManager.pictureSelectVoice(season, week, day).requestByF(this){_,data-> |
| | | HttpManager.pictureSelectVoice(season, week, day).requestByF(this,false, {_,data-> |
| | | startActivityForResult<ChooseVoiceActivity>(1,"data" to data,"day" to day,"week" to week,"season" to season) |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER)) |
| | | |
| | | }){_,msg-> |
| | | handleError(msg) |
| | | } |
| | | } |
| | | cl_3.clickDelay { |
| | | showDialog("加载题目...") |
| | | HttpManager.induceExclude(season, week, day).requestByF(this){_,data-> |
| | | HttpManager.induceExclude(season, week, day).requestByF(this,false, {_,data-> |
| | | startActivityForResult<IncludeActivity>(1,"data" to data,"day" to day,"week" to week,"season" to season) |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER)) |
| | | |
| | | }){_,msg-> |
| | | handleError(msg) |
| | | } |
| | | } |
| | | cl_4.clickDelay { |
| | | showDialog("加载题目...") |
| | | HttpManager.induceExclude(season, week, day).requestByF(this){_,data-> |
| | | // startActivityForResult<IncludeActivity>(1,"data" to data,"day" to day,"week" to week,"season" to season) |
| | | HttpManager.questionsAndAnswers(season, week, day).requestByF(this,false, {_,data-> |
| | | startActivityForResult<QAActivity>(1,"data" to data,"day" to day,"week" to week,"season" to season) |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER)) |
| | | |
| | | }){_,msg-> |
| | | handleError(msg) |
| | | } |
| | | } |
| | | cl_5.clickDelay { |
| | | showDialog("加载题目...") |
| | | HttpManager.pictureMateVoice(season, week, day).requestByF(this){_,data-> |
| | | // startActivityForResult<IncludeActivity>(1,"data" to data,"day" to day,"week" to week,"season" to season) |
| | | HttpManager.pictureMateVoice(season, week, day).requestByF(this,false,{_,data-> |
| | | startActivityForResult<MatchActivity>(1,"data" to data,"day" to day,"week" to week,"season" to season) |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER)) |
| | | |
| | | }){_,msg-> |
| | | handleError(msg) |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun handleError(msg:String){ |
| | | if (msg.contains("会员")){ |
| | | val tipDialog = TipDialog() |
| | | tipDialog.arguments = bundleOf("msg" to msg,"ok" to "成为会员") |
| | | tipDialog.setCallback(object :TipDialog.OnClickCallback{ |
| | | override fun onOk() { |
| | | browse(Apis.SHARE_URL,true) |
| | | } |
| | | |
| | | override fun onCancel() { |
| | | } |
| | | }) |
| | | tipDialog.showAllowingStateLoss(childFragmentManager,"vip") |
| | | }else{ |
| | | myToast(msg) |
| | | } |
| | | } |
| | | |
| | | private fun getProgress(){ |
| | | HttpManager.studySchedule(week,day).requestByF(this){ _, data-> |
| | | data?.apply { |
| | | tv_current.text = "当前周目:${week}周目" |
| | | val scheduleActivity = activity as ScheduleActivity |
| | | if (day != scheduleActivity.currentDay){ //解锁了后一天 |
| | | scheduleActivity.unLockNext(day) |
| | | } |
| | | tv_current.text = "当前周目:${week.formatToChinese()}周目" |
| | | tv_progress.text = "${computeSchedule}%" |
| | | tv_total.text = "${totalStudy}小时" |
| | | tv_today.text = "${todayStudy}小时" |
| | | progress_bar.progress = computeSchedule |
| | | |
| | | if (this@DailyFragment.day == current){ |
| | | if (this@DailyFragment.day == scheduleActivity.currentDay){ |
| | | formatProgress(listen,tv_state) |
| | | formatProgress(look,tv_state_2) |
| | | formatProgress(induction,tv_state_3) |
| | |
| | | |
| | | private fun formatProgress(progress:Int,tv:TextView){ |
| | | tv.text = when(progress){ |
| | | -1->{ |
| | | tv.backgroundResource = R.drawable.bg_grey_9dp |
| | | "未开始" |
| | | } |
| | | 0->{ |
| | | -1, 0->{ |
| | | tv.backgroundResource = R.drawable.bg_red_9dp |
| | | "未完成" |
| | | } |
| | |
| | | "已完成" |
| | | } |
| | | else->{ |
| | | "剩余:${100-progress}%" |
| | | tv.backgroundResource = R.drawable.bg_pink_9dp |
| | | "剩余:${progress}%" |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
| | | super.onActivityResult(requestCode, resultCode, data) |
| | | if (resultCode == Activity.RESULT_OK) |
| | | getProgress() |
| | | getProgress() |
| | | } |
| | | } |