diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 3072afaa..401569e5 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -7,11 +7,11 @@
-
+
-
+
\ No newline at end of file
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 04bae063..61e78cd1 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
@@ -2,6 +2,7 @@ package umc.com.mobile.project.ui.gradInfo
import android.app.AlertDialog
import android.os.Bundle
+import android.os.Handler
import android.util.Log
import android.view.LayoutInflater
import android.view.View
@@ -11,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
@@ -34,26 +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.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
- 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
@@ -62,12 +79,13 @@ class GradeFragment : Fragment() {
binding.tvPercent.text = selectedGradeInfo?.percentile
}
- viewModel.grades.observe(viewLifecycleOwner, Observer { gradesMap ->
- (binding.recyclerView2.adapter as? AverageRVAdapter)?.setData(gradesMap.values.toList())
- })
-
+ /**
+ * 이수 안 한 학기 관찰
+ */
viewModel.isNullCheckGrade.observe(viewLifecycleOwner) {
- if (it) { showDialog() }
+ if (it) {
+ showDialog()
+ }
}
return binding.root
@@ -97,5 +115,10 @@ class GradeFragment : Fragment() {
val alertDialog = dialogBuilder.create()
alertDialog.show()
+
+ Handler().postDelayed({
+ alertDialog.dismiss()
+ viewModel.onSetNullCheckGrade(false)
+ }, 1000)
}
}
diff --git a/app/src/main/java/umc/com/mobile/project/ui/gradInfo/adapter/AverageRVAdapter.kt b/app/src/main/java/umc/com/mobile/project/ui/gradInfo/adapter/AverageRVAdapter.kt
index dacd0a41..8ef3cf67 100644
--- a/app/src/main/java/umc/com/mobile/project/ui/gradInfo/adapter/AverageRVAdapter.kt
+++ b/app/src/main/java/umc/com/mobile/project/ui/gradInfo/adapter/AverageRVAdapter.kt
@@ -1,10 +1,12 @@
package umc.com.mobile.project.ui.gradInfo.adapter
import android.app.AlertDialog
+import android.graphics.Color
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContentProviderCompat.requireContext
+import umc.com.mobile.project.R
import umc.com.mobile.project.data.model.gradInfo.GradesTotalDto
import umc.com.mobile.project.databinding.ItemAverageGradeBinding
import umc.com.mobile.project.ui.gradInfo.GradeFragment
@@ -21,30 +23,41 @@ class AverageRVAdapter(private val viewModel: GradeViewModel) :
binding.root.setOnClickListener {
val position = adapterPosition
if (position != RecyclerView.NO_POSITION) {
- val semester = "${position + 1} 학기"
- val semesterGrade = "${position + 1} 학기 성적"
- viewModel.onSemesterItemClick(semester)
- viewModel.onSemesterGradeItemClick(semesterGrade)
-
- if (dataList[position].averageGrade == "0.0") {
- viewModel.onSetNullCheckGrade(true)
- }
+ handleItemClick(position)
}
}
}
+ private fun handleItemClick(position: Int) {
+ val semester = "${position + 1} 학기"
+ val semesterGrade = "${position + 1} 학기 성적"
+ viewModel.onSemesterItemClick(semester)
+ viewModel.onSemesterGradeItemClick(semesterGrade)
+
+ if (dataList[position].averageGrade == "0.0") {
+ viewModel.onSetNullCheckGrade(true)
+ }
+ }
+
fun bind(gradesTotalDto: GradesTotalDto, position: Int) {
val semester = if (position % 2 == 0) {
1
} else {
2
}
+
val grade = if (position % 2 == 0) position / 2 + 1 else (position + 1) / 2
-// totalAverageGrade += Integer.parseInt(gradesTotalDto.averageGrade)
binding.tvSemesterContent1.text = "$grade - $semester"
binding.tvAverageGradeContent1.text = gradesTotalDto.averageGrade
-// viewModel.onSetTotalAverageGrade(totalAverageGrade, position+1)
+
+ if (gradesTotalDto.averageGrade == "0.0") {
+ binding.tvAverageGradeContent1.setTextColor(Color.GRAY)
+ binding.tvSemesterContent1.setTextColor(Color.GRAY)
+ } else {
+ binding.tvAverageGradeContent1.setTextColor(Color.BLACK)
+ binding.tvSemesterContent1.setTextColor(Color.BLACK)
+ }
}
}
@@ -83,5 +96,4 @@ class AverageRVAdapter(private val viewModel: GradeViewModel) :
}
-
}
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 7f923c17..769ee7d7 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()
}
}
}
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 a1c2ce89..629ba420 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 bf42bb5b..d3beceda 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" />
diff --git a/app/src/main/res/layout/item_average_grade.xml b/app/src/main/res/layout/item_average_grade.xml
index 30145880..07d94c89 100644
--- a/app/src/main/res/layout/item_average_grade.xml
+++ b/app/src/main/res/layout/item_average_grade.xml
@@ -34,7 +34,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1-1"
- android:textColor="@{vm.isNullCheckGrade ? @color/gray : @color/black}"
+ android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@@ -46,7 +46,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:text="0.0"
- android:textColor="@{vm.isNullCheckGrade ? @color/gray : @color/black}"
+ android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"