package com.dollearn.student.ui.home
|
|
import android.app.Activity
|
import android.content.Intent
|
import android.widget.TextView
|
import androidx.core.os.bundleOf
|
import cn.sinata.xldutils.fragment.BaseFragment
|
import com.dollearn.student.R
|
import com.dollearn.student.network.HttpManager
|
import com.dollearn.student.network.requestByF
|
import com.dollearn.student.utils.extention.clickDelay
|
import kotlinx.android.synthetic.main.fragment_daily.*
|
import org.jetbrains.anko.backgroundResource
|
import org.jetbrains.anko.support.v4.startActivityForResult
|
|
class DailyFragment : BaseFragment() {
|
override fun contentViewId() = R.layout.fragment_daily
|
|
private val day by lazy {
|
arguments?.getInt("day")?:0
|
}
|
private val season by lazy {
|
(requireActivity() as ScheduleActivity).season
|
}
|
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->
|
startActivityForResult<ListenActivity>(1,"data" to data,"day" to day,"week" to week)
|
}
|
}
|
}
|
|
private fun getProgress(){
|
HttpManager.studySchedule(week,day).requestByF(this){ _, data->
|
data?.apply {
|
tv_current.text = "当前周目:${week}周目"
|
tv_progress.text = "${computeSchedule}%"
|
tv_total.text = "${totalStudy}小时"
|
tv_today.text = "${todayStudy}小时"
|
progress_bar.progress = computeSchedule
|
|
if (this@DailyFragment.day == current){
|
formatProgress(listen,tv_state)
|
formatProgress(look,tv_state_2)
|
formatProgress(induction,tv_state_3)
|
formatProgress(answer,tv_state_4)
|
formatProgress(pair,tv_state_5)
|
}else{
|
formatProgress(100,tv_state)
|
formatProgress(100,tv_state_2)
|
formatProgress(100,tv_state_3)
|
formatProgress(100,tv_state_4)
|
formatProgress(100,tv_state_5)
|
}
|
}
|
}
|
}
|
|
private fun formatProgress(progress:Int,tv:TextView){
|
tv.text = when(progress){
|
-1->{
|
tv.backgroundResource = R.drawable.bg_grey_9dp
|
"未开始"
|
}
|
0->{
|
tv.backgroundResource = R.drawable.bg_red_9dp
|
"未完成"
|
}
|
100->{
|
tv.backgroundResource = R.drawable.bg_blue_9dp
|
"已完成"
|
}
|
else->{
|
"剩余:${100-progress}%"
|
}
|
}
|
}
|
|
companion object{
|
fun newInstance(day:Int):DailyFragment{
|
val dailyFragment = DailyFragment()
|
dailyFragment.arguments = bundleOf("day" to day)
|
return dailyFragment
|
}
|
}
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
super.onActivityResult(requestCode, resultCode, data)
|
if (resultCode == Activity.RESULT_OK)
|
getProgress()
|
}
|
}
|