lmw
5 天以前 c42258b3bdc3527b74e05bbd917ceaa458cc205a
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package com.dollearn.student.ui.home
 
import android.widget.TextView
import androidx.core.os.bundleOf
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.utils.showAllowingStateLoss
import com.dollearn.student.R
import com.dollearn.student.dialog.GameTypeDialog
import com.dollearn.student.dialog.TipDialog
import com.dollearn.student.network.Apis
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.EmptyEvent
import com.dollearn.student.utils.event.IntEvent
import com.dollearn.student.utils.extention.clickDelay
import kotlinx.android.synthetic.main.activity_schedul_new.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.jetbrains.anko.backgroundResource
import org.jetbrains.anko.browse
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
 
class ScheduleActivityNew :TransparentStatusBarActivity(){
    override fun setContentView() = R.layout.activity_schedul_new
 
    val week by lazy { intent.getIntExtra("week",0) }
    val season by lazy { intent.getIntExtra("season",0) }
 
    val dailyViews by lazy { arrayListOf(cl_1,cl_2,cl_3,cl_4,cl_5,cl_6,cl_7) }
 
    override fun initClick() {
        cl_1.clickDelay {
            showDialog("加载题目...")
            HttpManager.listenSelectPicture(season, week, 1).request(this,false, {_,data->
                startActivityForResult<ListenActivity>(1,"data" to data,"day" to 1,"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, 2).request(this,false, {_,data->
                startActivityForResult<ChooseVoiceActivity>(1,"data" to data,"day" to 2,"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, 3).request(this,false, {_,data->
                startActivityForResult<IncludeActivity>(1,"data" to data,"day" to 3,"week" to week,"season" to season)
                EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER))
 
            }){_,msg->
                handleError(msg)
            }
        }
        cl_4.clickDelay {
            showDialog("加载题目...")
            HttpManager.questionsAndAnswers(season, week, 4).request(this,false, {_,data->
                startActivityForResult<QAActivity>(1,"data" to data,"day" to 4,"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, 5).request(this,false,{_,data->
                startActivityForResult<MatchActivity>(1,"data" to data,"day" to 5,"week" to week,"season" to season)
                EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER))
 
            }){_,msg->
                handleError(msg)
            }
        }
        cl_6.clickDelay {
            val gameTypeDialog = GameTypeDialog()
            gameTypeDialog.setCallback(object :GameTypeDialog.OnClickCallback{
                override fun onOk(d: Int) {
                    if (d == 1){
                        HttpManager.userGameDifficulty(week).request(this@ScheduleActivityNew){_,data->
                            startActivity<SuperListenActivity>("week" to week,"season" to season,"level" to (data?:0))
                            EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER))
                        }
                    }else{
                        showDialog("加载题目...")
                        HttpManager.gameMemory(season, week).request(this@ScheduleActivityNew){_,data->
                            startActivity<MemoryActivity>("data" to data,"week" to week,"season" to season)
                            EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER))
 
                        }
                    }
                }
            })
            gameTypeDialog.show(supportFragmentManager,"game")
        }
        cl_7.clickDelay {
            val gameTypeDialog = GameTypeDialog()
            gameTypeDialog.arguments = bundleOf("isStory" to true)
            gameTypeDialog.setCallback(object :GameTypeDialog.OnClickCallback{
                override fun onOk(d: Int) {
                    if (d == 1){
                        showDialog("加载题目...")
                        HttpManager.lookPictureDbu(season, week).request(this@ScheduleActivityNew){_,data->
                            startActivity<LookImgActivity>("data" to data,"week" to week,"season" to season)
                            EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER))
                        }
                    }else{
                        showDialog("加载题目...")
                        HttpManager.frameworkMemory(season, week).request(this@ScheduleActivityNew){_,data->
                            startActivity<ListenStoryActivity>("data" to data,"week" to week,"season" to season)
                            EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_TIMER))
 
                        }
                    }
                }
            })
            gameTypeDialog.show(supportFragmentManager,"game")
        }
    }
 
    override fun initView() {
        title = ""
        EventBus.getDefault().register(this)
    }
 
    override fun onResume() {
        super.onResume()
        getSchedule()
    }
 
    private fun getSchedule(){
        HttpManager.studySchedule(week,1).request(this){_,data->
            data?.apply {
                initTab(if (computeSchedule == 100) 7 else day)
                tv_current.text = "当前周目:第 ${week} 周"
                tv_progress.text = "${computeSchedule}%"
                tv_total.text = "${totalStudy}小时"
                tv_today.text = "${todayStudy}小时"
                progress_bar.progress = computeSchedule
                formatProgress(listen,tv_state)
                formatProgress(look,tv_state_2)
                formatProgress(induction,tv_state_3)
                formatProgress(answer,tv_state_4)
                formatProgress(pair,tv_state_5)
            }
        }
    }
 
    private fun initTab(day:Int) {
        //设置是否可点击
        dailyViews.forEachIndexed { index, constraintLayout ->
            if (index in day until 6){
                dailyViews[index].isEnabled = false
                dailyViews[index].alpha = 0.5f
            }else{
                dailyViews[index].isEnabled = true
                dailyViews[index].alpha = 1f
            }
        }
    }
 
    private fun formatProgress(progress:Int,tv: TextView){
        tv.text =  when(progress){
            -1, 0->{
                tv.backgroundResource = R.drawable.bg_red_9dp
                "未完成"
            }
            100->{
                tv.backgroundResource = R.drawable.bg_blue_9dp
                "已完成"
            }
            else->{
                tv.backgroundResource = R.drawable.bg_pink_9dp
                "剩余:${progress}%"
            }
        }
    }
 
    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(supportFragmentManager,"vip")
        }else{
            myToast(msg)
        }
    }
 
    @Subscribe
    fun nextSubject(e: IntEvent){
        if (e.code == Const.EventCode.NEXT_SUBJECT){
            when(e.i){
                2->{
                    cl_2.callOnClick()
                }
                3->{
                    cl_3.callOnClick()
                }
                4->{
                    cl_4.callOnClick()
                }
                5->{
                    cl_5.callOnClick()
                }
            }
        }
    }
 
    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }
}