|
@@ -10,12 +10,16 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
10
|
10
|
import androidx.recyclerview.widget.RecyclerView
|
11
|
11
|
import fr.forum_thalie.tsumugi.R
|
12
|
12
|
import fr.forum_thalie.tsumugi.planning.Planning
|
|
13
|
+import fr.forum_thalie.tsumugi.planning.Programme
|
|
14
|
+import fr.forum_thalie.tsumugi.weekdays
|
|
15
|
+import kotlinx.android.synthetic.main.fragment_programme.*
|
13
|
16
|
|
14
|
|
-class ProgrammeDayFragment(day: String) : Fragment() {
|
|
17
|
+class ProgrammeDayFragment(private val day: String) : Fragment() {
|
15
|
18
|
|
16
|
19
|
private lateinit var recyclerView: RecyclerView
|
17
|
20
|
private lateinit var viewAdapter: RecyclerView.Adapter<*>
|
18
|
21
|
private lateinit var viewManager: RecyclerView.LayoutManager
|
|
22
|
+ private val programmeOfTheDay: ArrayList<Programme> = ArrayList()
|
19
|
23
|
|
20
|
24
|
override fun onCreateView(
|
21
|
25
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
@@ -23,9 +27,13 @@ class ProgrammeDayFragment(day: String) : Fragment() {
|
23
|
27
|
): View? {
|
24
|
28
|
// Inflate the layout for this fragment
|
25
|
29
|
val root = inflater.inflate(R.layout.fragment_programme_day, container, false)
|
|
30
|
+ Planning.instance.programmes.forEach {
|
|
31
|
+ if (it.isThisDay(day = weekdays.indexOf(day)))
|
|
32
|
+ programmeOfTheDay.add(it)
|
|
33
|
+ }
|
26
|
34
|
viewManager = LinearLayoutManager(context)
|
27
|
35
|
viewAdapter =
|
28
|
|
- ProgrammeAdapter(Planning.instance.programmes)
|
|
36
|
+ ProgrammeAdapter(programmeOfTheDay, day)
|
29
|
37
|
recyclerView = root.findViewById<RecyclerView>(R.id.programme_recycler).apply {
|
30
|
38
|
// use this setting to improve performance if you know that changes
|
31
|
39
|
// in content do not change the layout size of the RecyclerView
|
|
@@ -33,17 +41,22 @@ class ProgrammeDayFragment(day: String) : Fragment() {
|
33
|
41
|
layoutManager = viewManager
|
34
|
42
|
adapter = viewAdapter
|
35
|
43
|
}
|
36
|
|
- Planning.instance.isProgrammeUpdated.observeForever(isProgrammeUpdatedObserver)
|
|
44
|
+ Planning.instance.currentProgramme.observeForever(isProgrammeUpdatedObserver)
|
37
|
45
|
return root
|
38
|
46
|
}
|
39
|
47
|
|
40
|
|
- private val isProgrammeUpdatedObserver = Observer<Boolean> {
|
|
48
|
+ private val isProgrammeUpdatedObserver = Observer<String> {
|
|
49
|
+ programmeOfTheDay.clear()
|
|
50
|
+ Planning.instance.programmes.forEach {
|
|
51
|
+ if (it.isThisDay(day = weekdays.indexOf(day)))
|
|
52
|
+ programmeOfTheDay.add(it)
|
|
53
|
+ }
|
41
|
54
|
viewAdapter.notifyDataSetChanged()
|
42
|
55
|
}
|
43
|
56
|
|
44
|
57
|
override fun onDestroyView() {
|
45
|
58
|
super.onDestroyView()
|
46
|
|
- Planning.instance.isProgrammeUpdated.removeObserver(isProgrammeUpdatedObserver)
|
|
59
|
+ Planning.instance.currentProgramme.removeObserver(isProgrammeUpdatedObserver)
|
47
|
60
|
}
|
48
|
61
|
|
49
|
62
|
companion object {
|