Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/FOR-GRAD/For-Grad-android i…
Browse files Browse the repository at this point in the history
…nto 21-졸업-요건-ui
  • Loading branch information
dkyuuum committed Feb 15, 2024
2 parents 6dcd83d + 509be44 commit 03a3626
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package umc.com.mobile.project.ui.board

import android.content.Context
import android.os.Bundle
import android.text.Editable
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
Expand Down Expand Up @@ -42,6 +41,10 @@ class GradDateFragment : Fragment() {
bottomSheetBinding =
FragmentGradDateBottomBinding.inflate(layoutInflater) // bottomSheetBinding 초기화

//fragment 들어왔을 때 수정하기 text만 보이게
viewModel.init()

//졸업예정일 누르면 bottom frag 뜨게
with(binding) {
tvGradDateDate.setOnClickListener {
val bottomSheet = GradDateBottomFragment(mContext)
Expand Down Expand Up @@ -70,7 +73,6 @@ class GradDateFragment : Fragment() {
navigate(R.id.action_fragment_date_to_fragment_home)
viewModel.onEditButtonClick()
} catch (e: ParseException) {
Log.e("GradDateFragment", "Error parsing date", e)
Toast.makeText(context, "날짜를 올바른 형식으로 입력해주세요.", Toast.LENGTH_LONG).show()
}
} else {
Expand All @@ -83,7 +85,7 @@ class GradDateFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

//api 연결
viewModel.getDateInfo()

//전에 저장했던 졸업일자랑 dday 불러오기
Expand All @@ -100,10 +102,12 @@ class GradDateFragment : Fragment() {
binding.tvGradDateDday.text = "D-" + response.result.dday.toString()
}
})

//다시 선택한 졸업 일자 띄우기
viewModel._selectedDate.observe(viewLifecycleOwner) { date ->
binding.tvGradDateDate.text = date
}

//다시 선택한 졸업 일자에 맞춰 dday 띄우기
viewModel._dday.observe(viewLifecycleOwner) { dday ->
binding.tvGradDateDday.text = "D-$dday"
Expand All @@ -123,6 +127,7 @@ class GradDateFragment : Fragment() {
binding.tvGradDateMemo.isEnabled = false
}
})

//버튼 활성화 조건
viewModel.isButtonEnabled.observe(viewLifecycleOwner, Observer { isEnabled ->
if (isEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import retrofit2.Call
import retrofit2.Callback
Expand Down Expand Up @@ -58,6 +59,10 @@ class GradDateViewModel : ViewModel() {
cheeringMessage.value = ""
}

fun init() {
_isEditMode.value = false
}

fun updateSelectedDate(year: String, month: String, day: String) {
val selectedDateString = "졸업 예정일 ${year}$month ${day}"
_selectedDate.value = selectedDateString
Expand Down Expand Up @@ -85,17 +90,27 @@ class GradDateViewModel : ViewModel() {
private var previousMessage: String? = null
private var previousDDay: Int? = null

//버튼 활성화 조건
val isButtonEnabled = MediatorLiveData<Boolean>().apply {
var previousMessage: String? = null
var previousDDay: String? = null

//cheeringMessage 값이 변경될 때마다 실행
addSource(cheeringMessage) { currentMessage ->
value = previousMessage != currentMessage
val cheeringMessageObserver = Observer<String> { currentMessage ->
val dDayValue = _dday.value
value =
previousMessage != currentMessage && currentMessage.isNotEmpty() && dDayValue != null && dDayValue != 0
previousMessage = currentMessage
}
//_dday 값이 변경될 때마다 실행
addSource(_dday) { currentDDay ->
value = previousDDay != currentDDay
previousDDay = currentDDay
val dDayObserver = Observer<Int> { currentDDay ->
val messageValue = cheeringMessage.value
value =
previousDDay != currentDDay.toString() && currentDDay != null && currentDDay != 0 && messageValue != null && messageValue.isNotEmpty()
previousDDay = currentDDay.toString()
}
addSource(cheeringMessage, cheeringMessageObserver)
addSource(_dday, dDayObserver)
}

fun getDateInfo() {
Expand All @@ -111,7 +126,6 @@ class GradDateViewModel : ViewModel() {
_dateResponse2.postValue(dateInfoResponse)
if (_dateResponse2.value != null && _dateResponse2.value!!.result != null) {
_selectedDate.value = _dateResponse2.value!!.result.gradDate
Log.d("getSelectedDate", selectedDate.value.toString())
}
Log.d("gradDate", "${response.body()}")
} else {
Expand Down

0 comments on commit 03a3626

Please sign in to comment.