From c545fa8154a56bda0b09933dd91f3dd21520d50d Mon Sep 17 00:00:00 2001 From: kimyujin-com <80165026+kimyujin-com@users.noreply.github.com> Date: Thu, 15 Feb 2024 14:23:47 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EC=A1=B8=EC=97=85=EC=98=88=EC=A0=95?= =?UTF-8?q?=EC=9D=BC=20=EC=88=98=EC=A0=95=ED=95=98=EA=B8=B0=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=20=EB=B0=8F=20=EB=B2=84=ED=8A=BC=20=ED=99=9C?= =?UTF-8?q?=EC=84=B1=ED=99=94=20=EC=A1=B0=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ui/board/GradDateFragment.kt | 11 +++++--- .../ui/board/viewmodel/GradDateViewModel.kt | 26 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/umc/com/mobile/project/ui/board/GradDateFragment.kt b/app/src/main/java/umc/com/mobile/project/ui/board/GradDateFragment.kt index a64d122..3684339 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/board/GradDateFragment.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/board/GradDateFragment.kt @@ -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 @@ -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) @@ -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 { @@ -83,7 +85,7 @@ class GradDateFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - + //api 연결 viewModel.getDateInfo() //전에 저장했던 졸업일자랑 dday 불러오기 @@ -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" @@ -123,6 +127,7 @@ class GradDateFragment : Fragment() { binding.tvGradDateMemo.isEnabled = false } }) + //버튼 활성화 조건 viewModel.isButtonEnabled.observe(viewLifecycleOwner, Observer { isEnabled -> if (isEnabled) { diff --git a/app/src/main/java/umc/com/mobile/project/ui/board/viewmodel/GradDateViewModel.kt b/app/src/main/java/umc/com/mobile/project/ui/board/viewmodel/GradDateViewModel.kt index 42f68ff..59b14f0 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/board/viewmodel/GradDateViewModel.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/board/viewmodel/GradDateViewModel.kt @@ -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 @@ -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 @@ -85,17 +90,27 @@ class GradDateViewModel : ViewModel() { private var previousMessage: String? = null private var previousDDay: Int? = null + //버튼 활성화 조건 val isButtonEnabled = MediatorLiveData().apply { + var previousMessage: String? = null + var previousDDay: String? = null + //cheeringMessage 값이 변경될 때마다 실행 - addSource(cheeringMessage) { currentMessage -> - value = previousMessage != currentMessage + val cheeringMessageObserver = Observer { 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 { 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() { @@ -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 {