Skip to content

Commit

Permalink
Merge branch 'main' into 14-커리어
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyujin-com authored Feb 14, 2024
2 parents c6a06e7 + 360146c commit f2ce990
Show file tree
Hide file tree
Showing 19 changed files with 460 additions and 469 deletions.
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
import com.google.gson.annotations.SerializedName

data class CompletionResponse(
@SerializedName("isSuccess")
val isSuccess: Boolean,
@SerializedName("code")
val code: String,
@SerializedName("message")
val message: String,
@SerializedName("result")
val result: Result
)

data class Result(
@SerializedName("titleList")
val titleList: TitleList,
val titleList: List<String>,
@SerializedName("completionDtoMap")
val completionDtoMap: List<Map<String, List<String>>>,
@SerializedName("majorRequirements")
val majorRequirements: MajorRequirements
val completionDtoMap: List<Map<String, List<String>>>
)

data class TitleList(
@SerializedName("titleList")
val titles: List<String>
)

data class CompletionDto(
data class CompletionDtoMap(
@SerializedName("필수교양(기초)")
val requiredBasic: List<String>,
val requiredBasicCourses: List<String>,
@SerializedName("필수교양(소양)")
val requiredCultural: List<String>,
val requiredGeneralCourses: List<String>,
@SerializedName("선택필수교양")
val optionalRequired: List<String>,
val electiveRequiredCourses: List<String>,
@SerializedName("소 계")
val optionalRequiredSubtotal: List<String>
)

data class MajorRequirements(
val subtotal: List<String>,
@SerializedName("제1트랙")
val track1: List<String>,
@SerializedName("제2트랙")
val track2: List<String>,
@SerializedName("부전공 부전공 - micro college")
val minorMicroCollege: List<String>
val minor: List<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ data class GradesDto(
val subjectName: String,
val credits: String,
val grade: String,
val track: String
)

data class GradesTotalDto(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package umc.com.mobile.project.ui.gradInfo

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -24,50 +25,55 @@ class CompletionStateFragment : Fragment() {
viewModel.getCompletionInfo() // 사용자 개인별 이수 현황 조회 api

viewModel.completionInfo.observe(viewLifecycleOwner, Observer {
// general
// binding.tvTotalScore.text = it?.result?.completionDtoMap?.generalMap?.subtotal?.get("소 계") ?: "누적 / (총계)"
val completionDtoMap: List<Map<String, List<String>>>? = it?.result?.completionDtoMap

// major
// binding.tvTotalScore2.text = it?.result?.majorCompletionDto?.majorMap?.total?.get(0).toString()
binding.tvTrack11Content.text = it?.result?.majorRequirements?.track1?.get(0).toString()
binding.tvTrack12Content.text = it?.result?.majorRequirements?.track1?.get(1).toString()
binding.tvTrack13Content.text = it?.result?.majorRequirements?.track1?.get(2).toString()
binding.tvTrack21Content.text = it?.result?.majorRequirements?.track2?.get(0).toString()
binding.tvTrack22Content.text = it?.result?.majorRequirements?.track2?.get(1).toString()
binding.tvTrack23Content.text = it?.result?.majorRequirements?.track2?.get(2).toString()
/**
* 필수 교양 (기초)
*/
completionDtoMap?.firstOrNull { it.containsKey("필수교양(기초)") }?.get("필수교양(기초)")?.let { requiredBasicCourses1 ->
binding.tvBasic1.text = requiredBasicCourses1[0]
binding.tvBasic1Content.text = requiredBasicCourses1[1]
binding.tvBasic2.text = requiredBasicCourses1[2]
binding.tvBasic2Content.text = requiredBasicCourses1[3]
binding.tvBasic3.text = requiredBasicCourses1[4]
binding.tvBasic3Content.text = requiredBasicCourses1[5]

})
// binding.tvBasic4.text = requiredBasicCourses1[6]
// binding.tvBasic4Content.text = requiredBasicCourses1[7]
// binding.tvBasic5.text = requiredBasicCourses1[8]
// binding.tvBasic5Content.text = requiredBasicCourses1[9]
// binding.tvBasic6.text = requiredBasicCourses1[10]
// binding.tvBasic6Content.text = requiredBasicCourses1[11]
}

viewModel.foundationElectiveCourses.observe(viewLifecycleOwner, Observer { courses ->
courses?.let {
if (it.isNotEmpty()) {
val coursesList = it.map { entry -> entry.key to entry.value }
if (coursesList.size > 1) {
binding.tvSoyang1.text = coursesList[0].first
binding.tvSoyang1Content.text = coursesList[0].second
binding.tvSoyang2.text = coursesList[1].first
binding.tvSoyang2Content.text = coursesList[1].second
}
}
/**
* 필수 교양 (소양)
*/
completionDtoMap?.firstOrNull { it.containsKey("필수교양(소양)") }?.get("필수교양(소양)")?.let { requiredBasicCourses2 ->
binding.tvSoyang1.text = requiredBasicCourses2[0]
binding.tvSoyang1Content.text = requiredBasicCourses2[1]
binding.tvSoyang2.text = requiredBasicCourses2[2]
binding.tvSoyang2Content.text = requiredBasicCourses2[3]
binding.tvTotalScore.text = requiredBasicCourses2[5]
}
})

viewModel.requiredBasicCourses.observe(viewLifecycleOwner, Observer { courses ->
courses?.let {
if (it.isNotEmpty()) {
val coursesList = it.map { entry -> entry.key to entry.value }
if (coursesList.size > 2) {
binding.tvBasic1.text = coursesList[0].first
binding.tvBasic1Content.text = coursesList[0].second
binding.tvBasic2.text = coursesList[1].first
binding.tvBasic2Content.text = coursesList[1].second
binding.tvBasic3.text = coursesList[2].first
binding.tvBasic3Content.text = coursesList[2].second
}
}
/**
* 트랙 1, 트랙 2
*/
completionDtoMap?.firstOrNull { it.containsKey("제1트랙") }?.get("제1트랙")?.let { track1Values ->
binding.tvTrack11Content.text = track1Values[0]
binding.tvTrack12Content.text = track1Values[1]
binding.tvTrack13Content.text = track1Values[2]
binding.tvTotalScore2.text = track1Values[3]
}
})

completionDtoMap?.firstOrNull { it.containsKey("제2트랙") }?.get("제2트랙")?.let { track1Values ->
binding.tvTrack21Content.text = track1Values[0]
binding.tvTrack22Content.text = track1Values[1]
binding.tvTrack23Content.text = track1Values[2]
}

})

return binding.root
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
import okhttp3.internal.notify
import umc.com.mobile.project.data.model.gradInfo.GradesResponse
import umc.com.mobile.project.data.model.home.TimeTableDto
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
import umc.com.mobile.project.ui.gradInfo.viewmodel.GradInfoViewModel
import umc.com.mobile.project.ui.gradInfo.viewmodel.GradeViewModel

class GradeFragment : Fragment() {
Expand All @@ -33,10 +32,32 @@ class GradeFragment : Fragment() {
viewModel.getGradeInfo() // 사용자 성적 사항 조회 api
initRecyclerView() // 성적 사항 recycleView 연결

viewModel.semesters?.observe(viewLifecycleOwner, Observer { semesters ->
// semesters를 사용하여 RecyclerView 어댑터 업데이트
// (binding.recyclerView.adapter as GradeRVAdapter).submitList(semesters.values.toList())
// binding.tvSemester.text = (semesters.keys ?: "null").toString()
viewModel.selectedSemester.observe(viewLifecycleOwner, Observer { selectedSemester ->
(binding.recyclerView.adapter as? GradeRVAdapter)?.updateSelectedSemester(
selectedSemester
)
binding.tvSemester.text = selectedSemester
})

viewModel.selectedSemesterGradeAndGrades.observe(viewLifecycleOwner) { pair ->
val selectedGrade = pair.first
val gradesMap = pair.second

Log.d("selectedGrade", "$selectedGrade")
Log.d("gradesMap", "$gradesMap")

val selectedGradeInfo = gradesMap?.get("$selectedGrade")
Log.d("selectedGradeInfo", "$selectedGradeInfo")

binding.tvAcquiredCredit.text = selectedGradeInfo?.acquiredCredits
binding.tvAppliedCredit.text = selectedGradeInfo?.appliedCredits
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())
})

return binding.root
Expand All @@ -48,11 +69,13 @@ class GradeFragment : Fragment() {
}

private fun initRecyclerView() {
val adapter = GradeRVAdapter()
val adapter = GradeRVAdapter(viewModel)
val adapter2 = AverageRVAdapter(viewModel)

binding.recyclerView.adapter = adapter
binding.recyclerView.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
}
binding.recyclerView.layoutManager = LinearLayoutManager(context)

}
binding.recyclerView2.adapter = adapter2
binding.recyclerView2.layoutManager = GridLayoutManager(context, 2)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package umc.com.mobile.project.ui.gradInfo.adapter

import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import umc.com.mobile.project.data.model.gradInfo.GradesTotalDto
import umc.com.mobile.project.databinding.ItemAverageGradeBinding
import umc.com.mobile.project.ui.gradInfo.viewmodel.GradeViewModel

class AverageRVAdapter(private val viewModel: GradeViewModel) :
RecyclerView.Adapter<AverageRVAdapter.MyViewHolder>() {
private var dataList = mutableListOf<GradesTotalDto>()

inner class MyViewHolder(private val binding: ItemAverageGradeBinding) :
RecyclerView.ViewHolder(binding.root) {
init {
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)
}
}
}

fun bind(gradesTotalDto: GradesTotalDto, position: Int) {
val count = if (position % 2 == 0) {
1
} else {
2
}
val semester = if (position % 2 == 0) position / 2 + 1 else (position + 1) / 2

binding.tvSemesterContent1.text = "$semester - $count"
binding.tvAverageGradeContent1.text = gradesTotalDto.averageGrade
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val binding = ItemAverageGradeBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return MyViewHolder(binding)
}

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.bind(dataList[position], position)
}

override fun getItemCount(): Int {
return dataList.size
}

fun setData(data: List<GradesTotalDto>) {
dataList.clear()
dataList.addAll(data)
repeat(8 - dataList.size) {
dataList.add(
GradesTotalDto(
"0",
"0",
"0.0",
"0.0",
"0"
)
)
}
notifyDataSetChanged()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import android.util.Log
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import umc.com.mobile.project.data.model.gradInfo.GradesResponse
import umc.com.mobile.project.data.model.gradInfo.GradesDto
import umc.com.mobile.project.databinding.ItemClassAndGradeBinding
class GradeRVAdapter : RecyclerView.Adapter<GradeRVAdapter.MyViewHolder>() {
private var dataList = mutableListOf<GradesResponse>()
import umc.com.mobile.project.ui.gradInfo.viewmodel.GradeViewModel

class GradeRVAdapter(private val viewModel: GradeViewModel) :
RecyclerView.Adapter<GradeRVAdapter.MyViewHolder>() {
private var dataList = mutableListOf<GradesDto>()
private var selectedSemester = ""

inner class MyViewHolder(private val binding: ItemClassAndGradeBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(gradesResponse: GradesResponse) {
binding.tvKindTitle.text = gradesResponse.result.semesters["1학기"]?.gradesDtoList?.get(0)?.classification
binding.tvClassTitle.text = gradesResponse.result.semesters["학기"]?.gradesDtoList?.get(1)?.subjectName
binding.tvCreditTitle.text = gradesResponse.result.semesters["학기"]?.gradesDtoList?.get(2)?.credits
binding.tvGradeTitle.text = gradesResponse.result.semesters["학기"]?.gradesDtoList?.get(3)?.grade
binding.tvCurrentTrackTitle.text = gradesResponse.result.semesters["학기"]?.gradesDtoList?.get(4)?.track

fun bind(gradesDto: GradesDto) {
binding.tvKindTitle.text = gradesDto.subjectName
binding.tvClassTitle.text = gradesDto.classification
binding.tvCreditTitle.text = gradesDto.credits
binding.tvGradeTitle.text = gradesDto.grade
}
}

Expand All @@ -37,4 +41,17 @@ class GradeRVAdapter : RecyclerView.Adapter<GradeRVAdapter.MyViewHolder>() {
return dataList.size
}

fun updateSelectedSemester(selectedSemester: String) {
this.selectedSemester = selectedSemester

val semestersInfo = viewModel.semesters?.value?.get(selectedSemester)

semestersInfo?.let {
dataList.clear()
dataList.addAll(it ?: emptyList())
notifyDataSetChanged()
} ?: run {
Log.e("GradeRVAdapter", "null")
}
}
}
Loading

0 comments on commit f2ce990

Please sign in to comment.