lmw
1 天以前 9904e5f900ba751c1fe719cdf889f00e9f1418e8
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
package com.dollearn.student.ui.home
 
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.utils.showAllowingStateLoss
import com.dollearn.student.R
import com.dollearn.student.dialog.TipDialog
import com.dollearn.student.network.HttpManager
import com.dollearn.student.network.entity.Week
import com.dollearn.student.network.request
import com.dollearn.student.ui.TransparentStatusBarActivity
import com.dollearn.student.ui.home.adapter.WeekAdapter
import kotlinx.android.synthetic.main.activity_week_select.*
import org.jetbrains.anko.startActivity
 
class WeekSelectActivity:TransparentStatusBarActivity() {
    override fun setContentView() = R.layout.activity_week_select
 
    private val seasons = arrayListOf("第一季","第二季","第三季","第四季")
    private val seasonAdapter = SeasonAdapter(seasons)
 
    private val weeks = arrayListOf<Week>()
    private val weekAdapter = WeekAdapter(weeks)
 
    override fun initClick() {
        seasonAdapter.setOnItemClickListener { view, position ->
            seasonAdapter.checked = position
            seasonAdapter.notifyDataSetChanged()
            getWeeks()
        }
 
        weekAdapter.setOnItemClickListener { view, position ->
            if (weeks[position].canStudy)
                startActivity<ScheduleActivity>("week" to weeks[position].week,"season" to seasonAdapter.checked+1)
            else{
                val msg = if (seasonAdapter.checked == 0||weeks[0].canStudy) "请先完成上一周目学习后再试" else "请先完成上一季度学习后再试"
                val tipDialog = TipDialog()
                tipDialog.arguments = bundleOf("msg" to msg,"isAlert" to true)
                tipDialog.showAllowingStateLoss(supportFragmentManager,"noStart")
            }
        }
    }
 
    override fun initView() {
        rv_season.layoutManager = LinearLayoutManager(this)
        rv_season.adapter = seasonAdapter
        rv_week.layoutManager = GridLayoutManager(this,3)
        rv_week.adapter = weekAdapter
    }
 
    private fun getWeeks(){
        showDialog()
        HttpManager.weekList(seasonAdapter.checked+1).request(this){_,data->
            weeks.clear()
            weeks.addAll(data?: arrayListOf())
            weekAdapter.notifyDataSetChanged()
        }
    }
 
    override fun onResume() {
        super.onResume()
        getWeeks()
    }
}