From 9c9bbd21588236e3beae8921e6daac50cd121e21 Mon Sep 17 00:00:00 2001 From: JingBh Date: Sat, 12 Feb 2022 11:30:26 +0800 Subject: [PATCH] fix: paper analysis topic number and text answer layout --- .../ui/exam/PaperAnalysisActivity.kt | 34 ++++++++----------- .../ui/exam/PaperAnalysisTopicViewHolder.kt | 2 +- .../res/layout/layout_topic_text_answer.xml | 5 +-- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/top/jingbh/zhixuehelper/ui/exam/PaperAnalysisActivity.kt b/app/src/main/java/top/jingbh/zhixuehelper/ui/exam/PaperAnalysisActivity.kt index f8e6b68..87c8c13 100644 --- a/app/src/main/java/top/jingbh/zhixuehelper/ui/exam/PaperAnalysisActivity.kt +++ b/app/src/main/java/top/jingbh/zhixuehelper/ui/exam/PaperAnalysisActivity.kt @@ -125,19 +125,6 @@ class PaperAnalysisActivity : AppCompatActivity() { } } - /*lifecycleScope.launch { - repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.uiState - .map { it.selectedIndex } - .filter { it >= 0 } - .distinctUntilChanged() - .collectLatest { - indexAdapter.notifyItemChanged(it) - binding.list.smoothScrollToPosition(it) - } - } - }*/ - lifecycleScope.launch { viewModel.analysis .collectLatest { analysis -> @@ -214,14 +201,21 @@ class PaperAnalysisActivity : AppCompatActivity() { private val binding: ItemPaperAnalysisIndexBinding ) : RecyclerView.ViewHolder(binding.root) { fun bind(topic: ExamPaperTopic, selected: Boolean = false) { - binding.text.text = topic.id.toString() - binding.text.setTextColor( - when (topic.getCorrectness()) { - ExamPaperTopic.Correctness.CORRECT -> colorCorrectRoles.accent - ExamPaperTopic.Correctness.HALF_CORRECT -> colorHalfCorrectRoles.accent - ExamPaperTopic.Correctness.WRONG -> colorWrongRoles.accent + binding.text.apply { + text = topic.title.let { title -> + if (title.length > 2) { + title.substring(0, 2) + } else title } - ) + + setTextColor( + when (topic.getCorrectness()) { + ExamPaperTopic.Correctness.CORRECT -> colorCorrectRoles.accent + ExamPaperTopic.Correctness.HALF_CORRECT -> colorHalfCorrectRoles.accent + ExamPaperTopic.Correctness.WRONG -> colorWrongRoles.accent + } + ) + } binding.root.isSelected = selected if (!selected) binding.root.setOnClickListener { diff --git a/app/src/main/java/top/jingbh/zhixuehelper/ui/exam/PaperAnalysisTopicViewHolder.kt b/app/src/main/java/top/jingbh/zhixuehelper/ui/exam/PaperAnalysisTopicViewHolder.kt index 5fe05d7..d1012d4 100644 --- a/app/src/main/java/top/jingbh/zhixuehelper/ui/exam/PaperAnalysisTopicViewHolder.kt +++ b/app/src/main/java/top/jingbh/zhixuehelper/ui/exam/PaperAnalysisTopicViewHolder.kt @@ -28,7 +28,7 @@ class PaperAnalysisTopicViewHolder private constructor( private val context = binding.root.context fun bind(topic: ExamPaperTopic) { - binding.title.text = context.getString(R.string.paper_topic_title, topic.id) + binding.title.text = context.getString(R.string.paper_topic_title, topic.title) binding.userAnswerCard.apply { val answerLayout = when (topic.type) { diff --git a/app/src/main/res/layout/layout_topic_text_answer.xml b/app/src/main/res/layout/layout_topic_text_answer.xml index 66642f4..b01d0a8 100644 --- a/app/src/main/res/layout/layout_topic_text_answer.xml +++ b/app/src/main/res/layout/layout_topic_text_answer.xml @@ -18,13 +18,14 @@