From 35f9049499e07609f7c8b8e061235184df3f1e29 Mon Sep 17 00:00:00 2001 From: dkyuuum Date: Sun, 18 Feb 2024 22:40:32 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=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=B4=9D=20=ED=8F=89?= =?UTF-8?q?=EA=B7=A0=20=EA=B3=84=EC=82=B0=20=EA=B5=AC=ED=98=84=20#21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ui/gradInfo/GradeFragment.kt | 26 ++++++++++++++----- .../ui/gradInfo/viewmodel/GradeViewModel.kt | 18 +++++-------- app/src/main/res/layout/fragment_grade.xml | 8 +++--- 3 files changed, 30 insertions(+), 22 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 e220534..d0b7abe 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 @@ -12,9 +12,8 @@ import androidx.fragment.app.viewModels import androidx.lifecycle.Observer import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager -import okhttp3.internal.notify import umc.com.mobile.project.R -import umc.com.mobile.project.data.model.gradInfo.GradesResponse +import umc.com.mobile.project.data.model.gradInfo.GradesTotalDto import umc.com.mobile.project.databinding.FragmentGradeBinding import umc.com.mobile.project.ui.gradInfo.adapter.AverageRVAdapter import umc.com.mobile.project.ui.gradInfo.adapter.GradeRVAdapter @@ -23,6 +22,7 @@ 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( @@ -43,9 +43,19 @@ class GradeFragment : Fragment() { }) viewModel.totalAverage.observe(viewLifecycleOwner, Observer { totalAverageGrade -> - binding.tvAverageTotal.text = totalAverageGrade.toString() + 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 @@ -61,12 +71,13 @@ class GradeFragment : Fragment() { binding.tvAverageGrade.text = selectedGradeInfo?.averageGrade binding.tvAverageTotal.text = selectedGradeInfo?.totalGrade binding.tvPercent.text = selectedGradeInfo?.percentile - } - viewModel.grades.observe(viewLifecycleOwner, Observer { gradesMap -> - (binding.recyclerView2.adapter as? AverageRVAdapter)?.setData(gradesMap.values.toList()) - }) + selectedSemesterPosition = selectedGrade + } + /** + * 이수 안 한 학기 체크 + */ viewModel.isNullCheckGrade.observe(viewLifecycleOwner) { if (it) { showDialog() @@ -79,6 +90,7 @@ class GradeFragment : Fragment() { override fun onDestroyView() { super.onDestroyView() _binding = null + selectedSemesterPosition = null } private fun initRecyclerView() { diff --git a/app/src/main/java/umc/com/mobile/project/ui/gradInfo/viewmodel/GradeViewModel.kt b/app/src/main/java/umc/com/mobile/project/ui/gradInfo/viewmodel/GradeViewModel.kt index a1c2ce8..629ba42 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/gradInfo/viewmodel/GradeViewModel.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/gradInfo/viewmodel/GradeViewModel.kt @@ -43,8 +43,8 @@ class GradeViewModel : ViewModel() { private val selectedSemesterGrade: LiveData get() = _selectedSemesterGrade - private val _totalAverage: MutableLiveData = MutableLiveData() - val totalAverage: LiveData + private val _totalAverage: MutableLiveData = MutableLiveData() + val totalAverage: LiveData get() = _totalAverage private val _isNullCheckGrade: MutableLiveData = MutableLiveData() @@ -67,6 +67,7 @@ class GradeViewModel : ViewModel() { val gradesTotalMap = mutableMapOf() val semestersDto = gradesResponse.result.semesters var count = 1 + var total = 0.0 semestersDto.let { for ((semester, semesterClasses) in it) { @@ -88,15 +89,14 @@ class GradeViewModel : ViewModel() { val newGradeKey = "$count 학기 성적" gradesTotalMap[newGradeKey] = gradeTotalDto - + total += gradeTotalDto.averageGrade.toDouble() count++ } - Log.d("Grade: gradeTotalList ", "$gradesTotalMap") - - count = 0 +// Log.d("Grade: gradeTotalList ", "$gradesTotalMap") } _semesters?.postValue(semestersMap) _grades.postValue(gradesTotalMap) + _totalAverage.postValue(String.format("%.2f", total / (count - 1))) } fun getGradeInfo() { @@ -110,7 +110,7 @@ class GradeViewModel : ViewModel() { if (userResponse != null) { _gradesInfo.postValue(userResponse) processRequiredBasicCourses(userResponse) - Log.d("gradInfo", "${response.body()}") +// Log.d("gradInfo", "${response.body()}") } else { _error.postValue("서버 응답이 올바르지 않습니다.") } @@ -141,10 +141,6 @@ class GradeViewModel : ViewModel() { _selectedSemesterGrade.postValue(grade) } - fun onSetTotalAverageGrade(totalAverageGrade: Double, totalNumber: Int) { - _totalAverage.postValue((totalAverageGrade/totalNumber)) - } - fun onSetNullCheckGrade(flag: Boolean) { _isNullCheckGrade.postValue(flag) } diff --git a/app/src/main/res/layout/fragment_grade.xml b/app/src/main/res/layout/fragment_grade.xml index bf42bb5..d3beced 100644 --- a/app/src/main/res/layout/fragment_grade.xml +++ b/app/src/main/res/layout/fragment_grade.xml @@ -349,20 +349,20 @@ app:layout_constraintTop_toBottomOf="@+id/tv_grade_average_title"> + app:layout_constraintTop_toBottomOf="@+id/tv_average_title" />