罗明文
2024-06-18 c9f6a2283ee7e5595c91c6d721726a89a3ab9ecd
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
import org.jetbrains.anko.support.v4.toast
 
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,"season" to season)
            }
        }
        cl_2.clickDelay {
            showDialog("加载题目...")
            HttpManager.pictureSelectVoice(season, week, day).requestByF(this){_,data->
                startActivityForResult<ChooseVoiceActivity>(1,"data" to data,"day" to day,"week" to week,"season" to season)
            }
        }
        cl_3.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)
            }
        }
        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)
            }
        }
        cl_5.clickDelay {
            showDialog("加载题目...")
            HttpManager.pictureMateVoice(season, week, day).requestByF(this){_,data->
                startActivityForResult<MatchActivity>(1,"data" to data,"day" to day,"week" to week,"season" to season)
            }
        }
    }
 
    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}%"
            }
        }
    }
 
    fun nextSubject(type:Int){
        when(type){
            2->{
                cl_2.callOnClick()
            }
            3->{
                cl_3.callOnClick()
            }
            4->{
                cl_4.callOnClick()
            }
            5->{
                cl_5.callOnClick()
            }
        }
    }
 
    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()
    }
}