Browse Source

refactored constructor to use factory pattern (should fix a crash)

yattoz 5 years ago
parent
commit
a6a0e0be90

+ 11 - 4
app/src/main/java/fr/forum_thalie/tsumugi/ui/programme/ProgrammeDayFragment.kt View File

12
 import fr.forum_thalie.tsumugi.planning.Planning
12
 import fr.forum_thalie.tsumugi.planning.Planning
13
 import fr.forum_thalie.tsumugi.planning.Programme
13
 import fr.forum_thalie.tsumugi.planning.Programme
14
 import fr.forum_thalie.tsumugi.weekdays
14
 import fr.forum_thalie.tsumugi.weekdays
15
-import kotlinx.android.synthetic.main.fragment_programme.*
16
 
15
 
17
-class ProgrammeDayFragment(private val day: String) : Fragment() {
16
+
17
+class ProgrammeDayFragment : Fragment() {
18
 
18
 
19
     private lateinit var recyclerView: RecyclerView
19
     private lateinit var recyclerView: RecyclerView
20
     private lateinit var viewAdapter: RecyclerView.Adapter<*>
20
     private lateinit var viewAdapter: RecyclerView.Adapter<*>
21
     private lateinit var viewManager: RecyclerView.LayoutManager
21
     private lateinit var viewManager: RecyclerView.LayoutManager
22
     private val programmeOfTheDay: ArrayList<Programme> = ArrayList()
22
     private val programmeOfTheDay: ArrayList<Programme> = ArrayList()
23
+    private val day = arguments?.getString("day") ?: weekdays.first()
23
 
24
 
24
     override fun onCreateView(
25
     override fun onCreateView(
25
         inflater: LayoutInflater, container: ViewGroup?,
26
         inflater: LayoutInflater, container: ViewGroup?,
56
         return root
57
         return root
57
     }
58
     }
58
 
59
 
60
+
59
     companion object {
61
     companion object {
60
         @JvmStatic
62
         @JvmStatic
61
-        fun newInstance(day: String) =
62
-            ProgrammeDayFragment(day)
63
+        fun newInstance(day: String): ProgrammeDayFragment {
64
+            val args = Bundle()
65
+            args.putString("day", day)
66
+            val f = ProgrammeDayFragment()
67
+            f.arguments = args
68
+            return f
69
+        }
63
     }
70
     }
64
 }
71
 }