From feb79fa5aac76fc15eb446d31207585d93b95141 Mon Sep 17 00:00:00 2001 From: dkyuuum Date: Sun, 18 Feb 2024 22:52:34 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EC=A1=B8=EC=97=85=EC=9A=94=EA=B1=B4/?= =?UTF-8?q?=EC=84=B1=EC=A0=81=20=EC=82=AC=ED=95=AD=20=EC=9D=B4=EC=88=98=20?= =?UTF-8?q?=EC=95=88=20=ED=95=9C=20=ED=95=99=EA=B8=B0=20=ED=81=B4=EB=A6=AD?= =?UTF-8?q?=20=EC=8B=9C=20=EC=84=B1=EC=A0=81=20=EC=95=88=20=EB=9C=A8?= =?UTF-8?q?=EA=B2=8C=20#21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ui/gradInfo/GradeFragment.kt | 22 ++++++++++++------- .../ui/gradInfo/adapter/GradeRVAdapter.kt | 5 +++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/umc/com/mobile/project/ui/gradInfo/GradeFragment.kt b/app/src/main/java/umc/com/mobile/project/ui/gradInfo/GradeFragment.kt index 6df925e..61e78cd 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/gradInfo/GradeFragment.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/gradInfo/GradeFragment.kt @@ -22,7 +22,6 @@ import umc.com.mobile.project.ui.gradInfo.viewmodel.GradeViewModel class GradeFragment : Fragment() { private var _binding: FragmentGradeBinding? = null private val viewModel: GradeViewModel by viewModels() - private var selectedSemesterPosition: String? = null private val binding get() = _binding!! override fun onCreateView( @@ -35,36 +34,43 @@ class GradeFragment : Fragment() { viewModel.getGradeInfo() // 사용자 성적 사항 조회 api initRecyclerView() // 성적 사항 recycleView 연결 + /** + * 선택한 학기 정보 넘기기 + */ viewModel.selectedSemester.observe(viewLifecycleOwner, Observer { selectedSemester -> (binding.recyclerView.adapter as? GradeRVAdapter)?.updateSelectedSemester( selectedSemester ) - binding.tvSemester.text = selectedSemester }) + /** + * 총 평균 관찰 + */ viewModel.totalAverage.observe(viewLifecycleOwner, Observer { totalAverageGrade -> binding.tvAverageContent.text = totalAverageGrade.toString() }) /** - * 총 학점 체크 후 데이터 넣기 + * 선택한 학기 총 학점 데이터 삽입 */ viewModel.grades.observe(viewLifecycleOwner, Observer { gradesMap -> (binding.recyclerView2.adapter as? AverageRVAdapter)?.setData(gradesMap.values.toList()) }) /** - * 총 학점 체크 후 화면 띄우기 + * 선택한 학기의 총 학점 관찰 */ viewModel.selectedSemesterGradeAndGrades.observe(viewLifecycleOwner) { pair -> val selectedGrade = pair.first val gradesMap = pair.second - Log.d("selectedGrade", "$selectedGrade") - Log.d("gradesMap", "$gradesMap") +// Log.d("selectedGrade", "$selectedGrade") +// Log.d("gradesMap", "$gradesMap") val selectedGradeInfo = gradesMap?.get("$selectedGrade") - Log.d("selectedGradeInfo", "$selectedGradeInfo") +// Log.d("selectedGradeInfo", "$selectedGradeInfo") + + binding.tvSemester.text = selectedGrade binding.tvAcquiredCredit.text = selectedGradeInfo?.acquiredCredits binding.tvAppliedCredit.text = selectedGradeInfo?.appliedCredits @@ -74,7 +80,7 @@ class GradeFragment : Fragment() { } /** - * 이수 안 한 학기 체크 + * 이수 안 한 학기 관찰 */ viewModel.isNullCheckGrade.observe(viewLifecycleOwner) { if (it) { diff --git a/app/src/main/java/umc/com/mobile/project/ui/gradInfo/adapter/GradeRVAdapter.kt b/app/src/main/java/umc/com/mobile/project/ui/gradInfo/adapter/GradeRVAdapter.kt index 7f923c1..769ee7d 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/gradInfo/adapter/GradeRVAdapter.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/gradInfo/adapter/GradeRVAdapter.kt @@ -48,10 +48,11 @@ class GradeRVAdapter(private val viewModel: GradeViewModel) : semestersInfo?.let { dataList.clear() - dataList.addAll(it ?: emptyList()) + dataList.addAll(it) notifyDataSetChanged() } ?: run { - Log.e("GradeRVAdapter", "null") + dataList.clear() + notifyDataSetChanged() } } }