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 3684339..f7e6487 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 @@ -113,6 +113,11 @@ class GradDateFragment : Fragment() { binding.tvGradDateDday.text = "D-$dday" } + //api에서 메모 hint로 가져오기 + viewModel._dateResponse2.observe(viewLifecycleOwner) { response -> + binding.tvGradDateMemo.hint = response!!.result.message + } + //수정하기 및 버튼 visible 조건 viewModel.isEditMode.observe(viewLifecycleOwner, Observer { isEditMode -> if (isEditMode) { 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 59b14f0..cceeef1 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 @@ -14,9 +14,11 @@ import umc.com.mobile.project.data.model.home.UpdateGradDateRequest import umc.com.mobile.project.data.model.home.UpdateGradDateResponse import umc.com.mobile.project.data.network.ApiClient import umc.com.mobile.project.data.network.api.HomeApi +import java.text.SimpleDateFormat import java.time.LocalDate import java.time.format.DateTimeFormatter import java.time.temporal.ChronoUnit +import java.util.Locale class GradDateViewModel : ViewModel() { val _selectedDate: MutableLiveData = MutableLiveData() @@ -55,10 +57,6 @@ class GradDateViewModel : ViewModel() { val isEditMode: LiveData get() = _isEditMode - init { - cheeringMessage.value = "" - } - fun init() { _isEditMode.value = false } @@ -86,12 +84,9 @@ class GradDateViewModel : ViewModel() { _isEditMode.value = !_isEditMode.value!! } - //전의 메모랑 같으면 저장 안됨 - private var previousMessage: String? = null - private var previousDDay: Int? = null - //버튼 활성화 조건 val isButtonEnabled = MediatorLiveData().apply { + //이전 메모랑 내용 같으면 저장 안됨 var previousMessage: String? = null var previousDDay: String? = null @@ -99,14 +94,14 @@ class GradDateViewModel : ViewModel() { val cheeringMessageObserver = Observer { currentMessage -> val dDayValue = _dday.value value = - previousMessage != currentMessage && currentMessage.isNotEmpty() && dDayValue != null && dDayValue != 0 + previousMessage != currentMessage && currentMessage.isNotEmpty() previousMessage = currentMessage } //_dday 값이 변경될 때마다 실행 val dDayObserver = Observer { currentDDay -> val messageValue = cheeringMessage.value value = - previousDDay != currentDDay.toString() && currentDDay != null && currentDDay != 0 && messageValue != null && messageValue.isNotEmpty() + previousDDay != currentDDay.toString() && currentDDay != null && currentDDay != 0 previousDDay = currentDDay.toString() } addSource(cheeringMessage, cheeringMessageObserver) @@ -124,6 +119,13 @@ class GradDateViewModel : ViewModel() { if (dateInfoResponse != null) { dateResponse.postValue(dateInfoResponse)//home에 있어서 놔둠 _dateResponse2.postValue(dateInfoResponse) + val originalFormat = SimpleDateFormat("yyyy-MM-dd", Locale.KOREA) + val targetFormat = SimpleDateFormat("yyyy-M월-d", Locale.KOREA) + if (dateInfoResponse.result.dday != null) { + val date = originalFormat.parse(dateInfoResponse.result.gradDate) + val formattedDate = targetFormat.format(date) + _selectedDateRequest.value = formattedDate + } if (_dateResponse2.value != null && _dateResponse2.value!!.result != null) { _selectedDate.value = _dateResponse2.value!!.result.gradDate } diff --git a/app/src/main/res/layout/fragment_grad_date.xml b/app/src/main/res/layout/fragment_grad_date.xml index 517ab29..94ca895 100644 --- a/app/src/main/res/layout/fragment_grad_date.xml +++ b/app/src/main/res/layout/fragment_grad_date.xml @@ -11,169 +11,174 @@ - - - - - + android:layout_height="match_parent" + android:orientation="vertical"> + + + + - - + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/iv_grad_date_card1"> + + + + + + - - - - - - - + + - + android:layout_marginBottom="6dp" + android:background="@drawable/bg_solid_gray_radius_25" + android:backgroundTint="@color/gray" + android:minHeight="0dp" + android:paddingTop="17dp" + android:paddingBottom="17dp" + android:stateListAnimator="@null" + android:text="저장하기" + android:textColor="@color/skyBlue" + android:visibility="@{vm.isEditMode ? 0 : 8}" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="@+id/tv_grad_date_memo" + app:layout_constraintStart_toStartOf="@+id/tv_grad_date_memo" /> - - - - - - - + \ No newline at end of file