浏览代码

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

yattoz 5 年前
父节点
当前提交
a6a0e0be90
共有 1 个文件被更改,包括 11 次插入4 次删除
  1. 11 4
      app/src/main/java/fr/forum_thalie/tsumugi/ui/programme/ProgrammeDayFragment.kt

+ 11 - 4
app/src/main/java/fr/forum_thalie/tsumugi/ui/programme/ProgrammeDayFragment.kt 查看文件

@@ -12,14 +12,15 @@ import fr.forum_thalie.tsumugi.R
12 12
 import fr.forum_thalie.tsumugi.planning.Planning
13 13
 import fr.forum_thalie.tsumugi.planning.Programme
14 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 19
     private lateinit var recyclerView: RecyclerView
20 20
     private lateinit var viewAdapter: RecyclerView.Adapter<*>
21 21
     private lateinit var viewManager: RecyclerView.LayoutManager
22 22
     private val programmeOfTheDay: ArrayList<Programme> = ArrayList()
23
+    private val day = arguments?.getString("day") ?: weekdays.first()
23 24
 
24 25
     override fun onCreateView(
25 26
         inflater: LayoutInflater, container: ViewGroup?,
@@ -56,9 +57,15 @@ class ProgrammeDayFragment(private val day: String) : Fragment() {
56 57
         return root
57 58
     }
58 59
 
60
+
59 61
     companion object {
60 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
 }