@@ -65,6 +65,11 @@ class ExamTakingFragment : BaseExamFragment(), View.OnClickListener, CompoundBut
6565
6666 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
6767 super .onViewCreated(view, savedInstanceState)
68+ initializeExamData()
69+ setupListeners()
70+ }
71+
72+ private fun initializeExamData () {
6873 viewLifecycleOwner.lifecycleScope.launch {
6974 user = userSessionManager.getUserModel()
7075 initExam()
@@ -94,7 +99,7 @@ class ExamTakingFragment : BaseExamFragment(), View.OnClickListener, CompoundBut
9499 val examCourseIdValue = exam?.courseId
95100 val userIdValue = user?.id
96101
97- viewLifecycleOwner.lifecycleScope.launch(Dispatchers . IO ) {
102+ viewLifecycleOwner.lifecycleScope.launch(dispatcherProvider.io ) {
98103 try {
99104 submissionsRepository.deleteExamSubmissions(
100105 examIdValue ? : id ? : " " , examCourseIdValue, userIdValue
@@ -103,7 +108,7 @@ class ExamTakingFragment : BaseExamFragment(), View.OnClickListener, CompoundBut
103108 e.printStackTrace()
104109 }
105110
106- withContext(Dispatchers . Main ) {
111+ withContext(dispatcherProvider.main ) {
107112 answerCache.clear()
108113 clearAnswer()
109114 ans = " "
@@ -116,7 +121,7 @@ class ExamTakingFragment : BaseExamFragment(), View.OnClickListener, CompoundBut
116121 val newSub = submissionsRepository.createExamSubmission(
117122 user?.id, user?.dob, user?.gender, currentExam, type, if (isTeam) teamId else null
118123 )
119- withContext(Dispatchers . Main ) {
124+ withContext(dispatcherProvider.main ) {
120125 sub = newSub
121126 startExam(questions?.get(currentIndex))
122127 updateNavButtons()
@@ -142,7 +147,9 @@ class ExamTakingFragment : BaseExamFragment(), View.OnClickListener, CompoundBut
142147 Snackbar .make(binding.tvQuestionCount, R .string.no_questions_available, Snackbar .LENGTH_LONG ).show()
143148 }
144149 }
150+ }
145151
152+ private fun setupListeners () {
146153 binding.btnBack.setOnClickListener {
147154 saveCurrentAnswer()
148155 lifecycleScope.launch {
0 commit comments