Skip to content

Commit

Permalink
Merge pull request #86 from FOR-GRAD/14-커리어
Browse files Browse the repository at this point in the history
14 커리어
  • Loading branch information
kimyujin-com authored Feb 13, 2024
2 parents 00059be + 4680783 commit 360146c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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
import android.view.View
Expand All @@ -16,6 +17,7 @@ import umc.com.mobile.project.databinding.FragmentGradDateBinding
import umc.com.mobile.project.databinding.FragmentGradDateBottomBinding
import umc.com.mobile.project.ui.board.viewmodel.GradDateViewModel
import umc.com.mobile.project.ui.common.NavigationUtil.navigate
import java.text.ParseException
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand All @@ -34,6 +36,7 @@ class GradDateFragment : Fragment() {
savedInstanceState: Bundle?
): View {
_binding = FragmentGradDateBinding.inflate(inflater, container, false)
binding.vm = viewModel
mContext = requireContext()
bottomSheetBinding =
FragmentGradDateBottomBinding.inflate(layoutInflater) // bottomSheetBinding 초기화
Expand Down Expand Up @@ -62,12 +65,23 @@ class GradDateFragment : Fragment() {
val originalFormat = SimpleDateFormat("yyyy-M월-d", Locale.KOREA)
val targetFormat = SimpleDateFormat("yyyy-MM-dd", Locale.KOREA)

val date = originalFormat.parse(viewModel.selectedDateRequest.value)
val formattedDate = targetFormat.format(date)
viewModel.updateCheeringMessage(binding.tvGradDateMemo.text.toString())
viewModel.updateDateInfo(formattedDate)
Toast.makeText(context, "저장되었습니다.", Toast.LENGTH_LONG).show()
navigate(R.id.action_fragment_date_to_fragment_home)
val dateString = viewModel.selectedDateRequest.value
if (dateString != null) {
try {
val date = originalFormat.parse(dateString)
val formattedDate = targetFormat.format(date)
viewModel.updateCheeringMessage(binding.tvGradDateMemo.text.toString())
viewModel.updateDateInfo(formattedDate)
Toast.makeText(context, "저장되었습니다.", Toast.LENGTH_LONG).show()
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 {
Toast.makeText(context, "졸업예정일을 선택해주세요.", Toast.LENGTH_LONG).show()
}
}

return binding.root
Expand Down Expand Up @@ -104,6 +118,16 @@ class GradDateFragment : Fragment() {
viewModel.cheeringMessage.observe(viewLifecycleOwner) { message ->
binding.tvGradDateMemo.text = Editable.Factory.getInstance().newEditable(message)
}

viewModel.isEditMode.observe(viewLifecycleOwner, Observer { isEditMode ->
if (isEditMode) {
binding.tvGradDateEdit.visibility = View.GONE
binding.btnSave.visibility = View.VISIBLE
} else {
binding.tvGradDateEdit.visibility = View.VISIBLE
binding.btnSave.visibility = View.GONE
}
})
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package umc.com.mobile.project.ui.board.viewmodel
import android.util.Log
import androidx.databinding.ObservableBoolean
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
Expand All @@ -16,6 +17,7 @@ import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit


class GradDateViewModel : ViewModel() {
val _selectedDate: MutableLiveData<String> = MutableLiveData()
val selectedDate: LiveData<String>
Expand All @@ -30,30 +32,39 @@ class GradDateViewModel : ViewModel() {
private val _dateResponse: MutableLiveData<GradDateResponse?> = MutableLiveData()
val dateResponse: MutableLiveData<GradDateResponse?>
get() = _dateResponse

private val _updateDateResponse: MutableLiveData<UpdateGradDateResponse?> = MutableLiveData()
val updateDateResponse: MutableLiveData<UpdateGradDateResponse?>
get() = _updateDateResponse

private val _error: MutableLiveData<String> = MutableLiveData()
val error: LiveData<String>
get() = _error

val _dday: MutableLiveData<Int> = MutableLiveData()
val dday: LiveData<Int>
get() = _dday

private val _cheeringMessage: MutableLiveData<String> = MutableLiveData()
val cheeringMessage: LiveData<String>
get() = _cheeringMessage
val isFilledMemo: LiveData<Boolean> = MediatorLiveData<Boolean>().apply {
addSource(cheeringMessage) { value = isFieldFilled() }
}
private fun isFieldFilled(): Boolean {
return !cheeringMessage.value.isNullOrEmpty()
}

private val _isEditMode = MutableLiveData<Boolean>(false)
val isEditMode: LiveData<Boolean>
get() = _isEditMode

fun init(value: GradDateResponse) {
_dday.postValue(value.result.dday)
_cheeringMessage.postValue(value.result.message)
}

val isFilledMemo: LiveData<Boolean> = MediatorLiveData<Boolean>().apply {
addSource(cheeringMessage) { value = isFieldFilled() }
}
fun isFieldFilled(): Boolean {
return !cheeringMessage.value.isNullOrEmpty()
}

fun updateSelectedDate(year: String, month: String, day: String) {
val selectedDateString = "졸업 예정일 ${year}$month ${day}"
_selectedDate.value = selectedDateString
Expand All @@ -76,6 +87,10 @@ class GradDateViewModel : ViewModel() {
_cheeringMessage.value = message
}

fun onEditButtonClick() {
_isEditMode.value = !_isEditMode.value!!
}

fun getDateInfo() {
dateInfoApiService.getDateInfo().enqueue(object : Callback<GradDateResponse> {
override fun onResponse(
Expand Down
31 changes: 17 additions & 14 deletions app/src/main/res/layout/fragment_grad_date.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/linearLayoutCompat"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginTop="34dp"
android:layout_marginEnd="18dp"
Expand Down Expand Up @@ -112,8 +112,8 @@
style="@style/BoldFont.30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#7D7D7D"
android:text="@{String.format(`D - %s`, vm.dday)}"
android:textColor="#7D7D7D"
app:layout_constraintBottom_toBottomOf="@+id/iv_grad_date_card2"
app:layout_constraintEnd_toEndOf="@+id/iv_grad_date_card2"
app:layout_constraintStart_toStartOf="@+id/iv_grad_date_card2"
Expand Down Expand Up @@ -142,6 +142,20 @@
app:layout_constraintStart_toStartOf="@+id/iv_grad_date_card2"
app:layout_constraintTop_toBottomOf="@+id/iv_grad_date_card2" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_grad_date_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:layout_marginEnd="16dp"
android:onClick="@{(v) -> vm.onEditButtonClick()}"
android:text="@string/board_grad_date_edit"
android:textAppearance="@style/MediumFont.12"
android:textColor="#FFFFFF"
android:visibility="@{vm.isEditMode ? 8 : 0}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_grad_date_memo" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_save"
style="@style/SemiBoldFont.14"
Expand All @@ -156,21 +170,10 @@
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" />

<!--<TextView
android:id="@+id/tv_grad_date_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:layout_marginEnd="16dp"
android:text="@string/board_grad_date_edit"
android:textColor="#FFFFFF"
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_grad_date_memo" />-->
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
21 changes: 8 additions & 13 deletions app/src/main/res/layout/fragment_grad_date_bottom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?><!--<FrameLayout 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="match_parent">
Expand Down Expand Up @@ -72,7 +71,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="323dp"
android:background="@drawable/white_round_top_border_20"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down Expand Up @@ -113,33 +112,29 @@
<NumberPicker
android:id="@+id/np_grad_date_year"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp"
android:layout_height="0dp"
android:selectionDividerHeight="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/np_grad_date_month"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/v_grad_date_underline" />

<NumberPicker
android:id="@+id/np_grad_date_month"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp"
android:layout_height="0dp"
android:selectionDividerHeight="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/np_grad_date_day"
app:layout_constraintStart_toEndOf="@id/np_grad_date_year"
app:layout_constraintTop_toBottomOf="@id/v_grad_date_underline" />

<NumberPicker
android:id="@+id/np_grad_date_day"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:layout_height="0dp"
android:selectionDividerHeight="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/np_grad_date_month"
app:layout_constraintTop_toBottomOf="@id/v_grad_date_underline" />
Expand Down

0 comments on commit 360146c

Please sign in to comment.