lmw
2024-06-18 1f45a54dc8e149548d3a61d1228741627aa4f23e
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
package com.dollearn.student.ui.course
 
import android.util.Log
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.GridLayoutManager
import cn.sinata.xldutils.fragment.BaseFragment
import cn.sinata.xldutils.utils.parserTime
import cn.sinata.xldutils.utils.toTime
import com.dollearn.student.R
import com.dollearn.student.ui.course.adapter.WeekAdapter
import com.dollearn.student.utils.Const
import kotlinx.android.synthetic.main.fragment_week.*
 
class WeekFragment:BaseFragment() {
    override fun contentViewId() = R.layout.fragment_week
 
    val startTime by lazy { arguments?.getLong("startTime",0L)?:0L } //第一天的时间戳
    val list = arrayListOf<Long>()
    private val adapter = WeekAdapter(list)
 
    override fun onFirstVisibleToUser() {
        Log.e(Const.Tag,"本周第一天${startTime.toTime("yyyy-MM-dd")}")
        rv_week.layoutManager = GridLayoutManager(requireContext(),7)
        rv_week.adapter = adapter
        list.addAll((0 until 7).map {
            startTime+(1000L*it*24*60*60)
        })
        adapter.notifyDataSetChanged()
        adapter.setOnItemClickListener { view, position ->
            if (list[position].toTime("yyyy-MM-dd 00:00:00").parserTime() >= System.currentTimeMillis().toTime("yyyy-MM-dd 00:00:00").parserTime())
                (parentFragment as CourseFragment).notifyWeekCheckChanged(list[position])
        }
    }
 
    fun refreshAdapter(){
        adapter.notifyDataSetChanged()
    }
 
    companion object{
        fun newInstance(startTime:Long):WeekFragment{
            val weekFragment = WeekFragment()
            weekFragment.arguments = bundleOf("startTime" to startTime)
            return weekFragment
        }
    }
}