LearnCompletedDialog.kt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.dlc.exam.ui.learn
  2. import android.annotation.SuppressLint
  3. import android.app.Dialog
  4. import android.content.Context
  5. import android.os.Bundle
  6. import android.view.LayoutInflater
  7. import android.view.View
  8. import com.dlc.exam.R
  9. import com.dlc.exam.databinding.DialogLearnCompletedBinding
  10. import com.rc.httpcore.vo.response.LearnBonusBean
  11. /**
  12. * 学习完成Dialog
  13. *
  14. * @author ReiChin_
  15. */
  16. class LearnCompletedDialog(
  17. context: Context,
  18. private val data: LearnBonusBean,
  19. private val endChapter: Boolean,
  20. private val assessStatus: Boolean,
  21. val listener: () -> Unit
  22. ) :
  23. Dialog(context, R.style.AlertDialogStyle) {
  24. private val viewBinding: DialogLearnCompletedBinding by lazy {
  25. DialogLearnCompletedBinding.inflate(LayoutInflater.from(context))
  26. }
  27. @SuppressLint("SetTextI18n")
  28. override fun onCreate(savedInstanceState: Bundle?) {
  29. super.onCreate(savedInstanceState)
  30. setContentView(viewBinding.root)
  31. viewBinding.close.setOnClickListener { dismiss() }
  32. viewBinding.learnBonusScore.text =
  33. "已学习时长${data.durationStr ?: "0"},共获得${data.points ?: "0"}奖励分"
  34. if (endChapter) {
  35. viewBinding.title.text = "您已学习完最后一章节"
  36. } else {
  37. viewBinding.title.text = "您已学习完该章节"
  38. }
  39. if (assessStatus) {
  40. // 需要课后考核
  41. viewBinding.nextChapter.text = "课后考核"
  42. viewBinding.nextChapter.visibility = View.VISIBLE
  43. } else {
  44. viewBinding.nextChapter.text = "学习下一章节"
  45. viewBinding.nextChapter.visibility = if (endChapter) View.GONE else View.VISIBLE
  46. }
  47. viewBinding.nextChapter.setOnClickListener {
  48. // 学习下一章节/课后考核
  49. dismiss()
  50. listener.invoke()
  51. }
  52. }
  53. }