Skip to content

Commit

Permalink
Merge pull request #91 from FOR-GRAD/21-졸업-요건-ui
Browse files Browse the repository at this point in the history
21 졸업 요건 UI
  • Loading branch information
dkyuuum authored Feb 16, 2024
2 parents 24b9c03 + 70e72a5 commit c3959f0
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ data class Result(
)

data class FutureTimeTableDto(
val semester: SemesterInfo
)

data class SemesterInfo(
val sumCredits: Int,
val timeTableDtoList: List<TimeTableDto>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AverageRVAdapter(private val viewModel: GradeViewModel) :
val grade = if (position % 2 == 0) position / 2 + 1 else (position + 1) / 2
// totalAverageGrade += Integer.parseInt(gradesTotalDto.averageGrade)

binding.tvSemesterContent1.text = "$grade - $semester"
binding.tvSemesterContent1.text = "$grade - $semester"
binding.tvAverageGradeContent1.text = gradesTotalDto.averageGrade
// viewModel.onSetTotalAverageGrade(totalAverageGrade, position+1)
}
Expand All @@ -72,6 +72,7 @@ class AverageRVAdapter(private val viewModel: GradeViewModel) :
fun setData(data: List<GradesTotalDto>) {
dataList.clear()
dataList.addAll(data)
// viewModel.onSetNullCheckGrade(true)
repeat(8 - dataList.size) {
dataList.add(
GradesTotalDto(
Expand All @@ -82,8 +83,8 @@ class AverageRVAdapter(private val viewModel: GradeViewModel) :
"0"
)
)
viewModel.onSetNullCheckGrade(false)
}

notifyDataSetChanged()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class GradeViewModel : ViewModel() {
val totalAverage: LiveData<Double>
get() = _totalAverage

private val _isNullCheckGrade: MutableLiveData<Boolean> = MutableLiveData()
val isNullCheckGrade: LiveData<Boolean>
get() = _isNullCheckGrade

val selectedSemesterGradeAndGrades: MediatorLiveData<Pair<String?, Map<String, GradesTotalDto>?>> = MediatorLiveData()

init {
Expand Down Expand Up @@ -138,4 +142,8 @@ class GradeViewModel : ViewModel() {
fun onSetTotalAverageGrade(totalAverageGrade: Double, totalNumber: Int) {
_totalAverage.postValue((totalAverageGrade/totalNumber))
}

fun onSetNullCheckGrade(flag: Boolean) {
_isNullCheckGrade.postValue(flag)
}
}
20 changes: 3 additions & 17 deletions app/src/main/java/umc/com/mobile/project/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import umc.com.mobile.project.ui.home.viewmodel.HomeViewModel
class HomeFragment : Fragment() {
private var _binding: FragmentHomeBinding? = null
private val viewModel: HomeViewModel by viewModels()
// private val gradDateViewModel: GradDateViewModel by activityViewModels()
private val binding get() = _binding!!

override fun onCreateView(
Expand All @@ -39,7 +38,6 @@ class HomeFragment : Fragment() {
viewModel.getUserInfo() // 홈 화면 정보 조회 api

navigateFragment()
// saveCheeringMemo() // 응원의 한마디 연결
setupRecyclerView() // recyclerView 연결
setupHomeInfoRetrofit() // 홈 화면 ui 연결

Expand All @@ -48,7 +46,6 @@ class HomeFragment : Fragment() {

override fun onPause() {
super.onPause()
// saveCheeringMemo()
}

override fun onDestroyView() {
Expand All @@ -66,28 +63,17 @@ class HomeFragment : Fragment() {
}
}

/*
private fun saveCheeringMemo() {
gradDateViewModel.dateResponse.observe(viewLifecycleOwner, Observer {
})
}
*/

private fun setupRecyclerView() {
val adapter = NextPlanRVAdapter()

viewModel.userInfoResponse.observe(viewLifecycleOwner, Observer { userInfoResponse ->
val futureTimeTableDto = userInfoResponse?.result?.futureTimeTableDto
if (futureTimeTableDto != null) {
val futureSemesterInfo = futureTimeTableDto.values.firstOrNull()
if (futureSemesterInfo?.semester != null) {
val timeTableDtoList = futureSemesterInfo.semester.timeTableDtoList
val timeTableDtoList = futureSemesterInfo?.timeTableDtoList
if (timeTableDtoList != null) {
adapter.setData(timeTableDtoList)
} else {
Log.e("HomeFragment", "정보 없음")
}
} else {
Log.e("HomeFragment", "정보 없음")
}
})

Expand Down Expand Up @@ -120,7 +106,7 @@ class HomeFragment : Fragment() {
binding.tvGradeSemester.text = planKey

binding.tvTotalCredit.text =
(it?.result?.futureTimeTableDto?.get(planKey)?.semester?.sumCredits ?: "총 학점 0").toString()
"총 학점 ${it?.result?.futureTimeTableDto?.get(planKey)?.sumCredits}" ?: "총 학점 0"

val dDay = it?.result?.dday ?: 0
binding.progressbarToGrad.progress = 1460 - dDay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package umc.com.mobile.project.ui.home.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.data.model.home.TimeTableDto
import umc.com.mobile.project.databinding.ItemHomeNextPlanBinding

class NextPlanRVAdapter : RecyclerView.Adapter<NextPlanRVAdapter.MyViewHolder>() {

private var dataList = listOf<TimeTableDto>()
private var dataList = mutableListOf<TimeTableDto>()

inner class MyViewHolder(private val binding: ItemHomeNextPlanBinding) :
RecyclerView.ViewHolder(binding.root) {
Expand Down Expand Up @@ -36,8 +36,9 @@ class NextPlanRVAdapter : RecyclerView.Adapter<NextPlanRVAdapter.MyViewHolder>()
return dataList.size
}

fun setData(dataList: List<TimeTableDto>) {
this.dataList = dataList
fun setData(data: List<TimeTableDto>) {
dataList.clear()
dataList.addAll(data)
notifyDataSetChanged()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ class HomeViewModel : ViewModel() {

if (userResponse.result.futureTimeTableDto.isEmpty()) {
_planStatus.postValue(false)
} else {
_planStatus.postValue(true)
}
// Log.d("home", "${response.body()}")
Log.d("home", "${userResponse.result.futureTimeTableDto}")
} else {
_error.postValue("서버 응답이 올바르지 않습니다.")
}
} else {
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/umc/com/mobile/project/ui/login/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package umc.com.mobile.project.ui.login

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.view.KeyEvent
import android.view.WindowManager
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import umc.com.mobile.project.MainActivity
import umc.com.mobile.project.R
import umc.com.mobile.project.databinding.ActivityLoginBinding
import umc.com.mobile.project.ui.login.viewmodel.LoginViewModel
import kotlin.coroutines.coroutineContext
Expand Down Expand Up @@ -56,6 +60,28 @@ class LoginActivity : AppCompatActivity() {
}
false
}

// 이전 화면에서 로그아웃을 통해 돌아온 경우 다이얼로그 표시
val isLoggedOut = intent.getBooleanExtra("logged_out", false)
if (isLoggedOut) {
showLogoutDialog()
}
}

private fun showLogoutDialog() {
var dialogBuilder =
AlertDialog.Builder(this, R.style.CustomAlertDialogTheme)

val customView = layoutInflater.inflate(R.layout.custom_dialog_logout_home, null)
dialogBuilder.setView(customView)

val dialog = dialogBuilder.create()

dialog.show()

Handler().postDelayed({
dialog.dismiss()
}, 2000)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -35,7 +36,8 @@ class SettingFragment : Fragment() {

viewModel.userInfoResponse.observe(viewLifecycleOwner, Observer {
binding.tvAccountIdContent.text = it?.result?.id.toString()
binding.tvAccountMajorContent.text = "1트랙: ${it?.result?.track1} / 트랙: ${it?.result?.track2}"
binding.tvAccountMajorContent.text =
"1트랙: ${it?.result?.track1} / 트랙: ${it?.result?.track2}"
})

return binding.root
Expand All @@ -52,25 +54,29 @@ class SettingFragment : Fragment() {
}

binding.tvEtcLogout.setOnClickListener {
var dialog = AlertDialog.Builder(requireContext())
dialog.setTitle("로그아웃을 하시겠습니까?")
dialog.setMessage("서비스를 이용해주셔서 감사합니다.")
var dialogBuilder =
AlertDialog.Builder(requireContext(), R.style.CustomAlertDialogTheme)

fun toast() {
Toast.makeText(requireContext(), "로그아웃 되었습니다.", Toast.LENGTH_SHORT).show()
val customView = layoutInflater.inflate(R.layout.custom_dialog_logout, null)
dialogBuilder.setView(customView)
val alertDialog = dialogBuilder.create()

alertDialog.show()

customView.findViewById<Button>(R.id.button_positive).setOnClickListener {
// Toast.makeText(requireContext(), "로그아웃 되었습니다.", Toast.LENGTH_SHORT).show()
val intent = Intent(requireContext(), LoginActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
intent.putExtra("logged_out", true)
startActivity(intent)
requireActivity().finish()
}
var dialogLister = DialogInterface.OnClickListener { p0, p1 ->
when (p1) {
DialogInterface.BUTTON_POSITIVE -> toast()
}

customView.findViewById<Button>(R.id.button_negative).setOnClickListener {
alertDialog.dismiss()
}
dialog.setPositiveButton("YES", dialogLister)
dialog.setNegativeButton("NO", null)
dialog.show()

}

}
}
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/bg_dialog_black_47.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#78000000" />
</shape>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/custom_dialog_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#FFFFFF" />
</shape>
61 changes: 61 additions & 0 deletions app/src/main/res/layout/custom_dialog_logout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="38dp"
android:layout_marginEnd="38dp"
android:background="@drawable/bg_solid_white_radius_20"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textView_message"
style="@style/SemiBoldFont.16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="21dp"
android:text="포어그래드에서\n로그아웃 하시겠습니까?"
android:textColor="@android:color/black" />

<!-- 버튼들 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button_positive"
style="@style/SemiBoldFont.16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="9dp"
android:background="@drawable/bg_solid_white_radius_20"
android:padding="15dp"
android:stateListAnimator="@null"
android:text="로그아웃"
android:textColor="@color/skyBlue" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button_negative"
style="@style/SemiBoldFont.16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_solid_white_radius_20"
android:padding="15dp"
android:stateListAnimator="@null"
android:text="닫기"
android:textColor="@color/black" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
30 changes: 30 additions & 0 deletions app/src/main/res/layout/custom_dialog_logout_home.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@null">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_dialog_black_47"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textView_message"
style="@style/SemiBoldFont.16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="21dp"
android:text="로그아웃 되었습니다."
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit c3959f0

Please sign in to comment.