Skip to content

Commit

Permalink
Merge pull request #97 from FOR-GRAD/21-졸업-요건-ui
Browse files Browse the repository at this point in the history
21 졸업 요건 UI
  • Loading branch information
dkyuuum authored Feb 18, 2024
2 parents b047dbc + 2d85431 commit ed36099
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -97,5 +115,10 @@ class GradeFragment : Fragment() {

val alertDialog = dialogBuilder.create()
alertDialog.show()

Handler().postDelayed({
alertDialog.dismiss()
viewModel.onSetNullCheckGrade(false)
}, 1000)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
}

Expand Down Expand Up @@ -83,5 +96,4 @@ class AverageRVAdapter(private val viewModel: GradeViewModel) :
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class GradeViewModel : ViewModel() {
private val selectedSemesterGrade: LiveData<String>
get() = _selectedSemesterGrade

private val _totalAverage: MutableLiveData<Double> = MutableLiveData()
val totalAverage: LiveData<Double>
private val _totalAverage: MutableLiveData<String> = MutableLiveData()
val totalAverage: LiveData<String>
get() = _totalAverage

private val _isNullCheckGrade: MutableLiveData<Boolean> = MutableLiveData()
Expand All @@ -67,6 +67,7 @@ class GradeViewModel : ViewModel() {
val gradesTotalMap = mutableMapOf<String, GradesTotalDto>()
val semestersDto = gradesResponse.result.semesters
var count = 1
var total = 0.0

semestersDto.let {
for ((semester, semesterClasses) in it) {
Expand All @@ -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() {
Expand All @@ -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("서버 응답이 올바르지 않습니다.")
}
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/fragment_grade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,20 @@
app:layout_constraintTop_toBottomOf="@+id/tv_grade_average_title">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_average_content"
android:id="@+id/tv_average_title"
style="@style/MediumFont.13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="13dp"
android:text="총 평균"
android:textColor="@color/black"
app:layout_constraintBottom_toTopOf="@+id/appCompatTextView9"
app:layout_constraintBottom_toTopOf="@+id/tv_average_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/appCompatTextView9"
android:id="@+id/tv_average_content"
style="@style/BoldFont.20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -371,7 +371,7 @@
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_average_content" />
app:layout_constraintTop_toBottomOf="@+id/tv_average_title" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/item_average_grade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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"
Expand Down

0 comments on commit ed36099

Please sign in to comment.