Created
November 1, 2022 15:33
-
-
Save erdalkaymak/c8de6730b5401e04126994485153d4e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ExperimentalCoroutinesApi | |
| @AndroidEntryPoint | |
| class ChapterQuestionFragment(private val question: Question) : | |
| BaseFragment<FragmentChapterQuestionBinding, ChapterQuestionViewModel>(R.layout.fragment_chapter_question) { | |
| //var region | |
| override val viewModel: ChapterQuestionViewModel by viewModels() | |
| private lateinit var mCallback: OnRequestAction | |
| //end region | |
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
| super.onViewCreated(view, savedInstanceState) | |
| binding.questionContent = question | |
| binding.txtQuestion.text= Html.fromHtml(question.question) | |
| checkAnswerAndShowHint() | |
| } | |
| override fun onAttach(context: Context) { | |
| super.onAttach(context) | |
| try { | |
| mCallback = (parentFragment as OnRequestAction?)!! | |
| } catch (e: ClassCastException) { | |
| throw ClassCastException( | |
| context.toString() | |
| .toString() + " must implement OnRequestAction" | |
| ) | |
| } | |
| } | |
| private fun checkAnswerAndShowHint() { | |
| binding.btnCheck.setOnClickListener { | |
| when (question.correct_answer) { | |
| binding.rbOption1.text -> { | |
| if (binding.rbOption1.isChecked) { | |
| mCallback.nextPage() | |
| } else { | |
| showSnackBar( | |
| binding.root, | |
| "Your Answer is Wrong or you did not answer the question !!" | |
| ) | |
| } | |
| } | |
| binding.rbOption2.text -> { | |
| if (binding.rbOption2.isChecked) { | |
| showSnackBar(binding.root, "Correct Answer") | |
| mCallback.nextPage() | |
| } else { | |
| showSnackBar( | |
| binding.root, | |
| "Your Answer is Wrong or you did not answer the question !!" | |
| ) | |
| } | |
| } | |
| binding.rbOption3.text -> { | |
| if (binding.rbOption3.isChecked) { | |
| showSnackBar(binding.root, "Correct Answer") | |
| mCallback.nextPage() | |
| } else { | |
| showSnackBar( | |
| binding.root, | |
| "Your Answer is Wrong or you did not answer the question !!" | |
| ) | |
| } | |
| } | |
| binding.rbOption4.text -> { | |
| if (binding.rbOption4.isChecked) { | |
| showSnackBar(binding.root, "Correct Answer") | |
| mCallback.nextPage() | |
| } else { | |
| showSnackBar( | |
| binding.root, | |
| "Your Answer is Wrong or you did not answer the question !!" | |
| ) | |
| } | |
| } | |
| else -> { | |
| showSnackBar( | |
| binding.root, | |
| "Your Answer is Wrong or you did not answer the question !!" | |
| ) | |
| } | |
| } | |
| } | |
| binding.btnHint.setOnClickListener { | |
| buildDialog("HINT", question.hint!!) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment