feat: 휴가 관리 NumberPicker → Spinner 변경 + 저장 버튼 복원
- NumberPicker 대신 Spinner(드롭다운) 사용 - 값 변경 시 자동 저장 제거하고 저장 버튼 복원 - 더 직관적인 UI 제공 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -4,18 +4,16 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.NumberPicker
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.example.shiftalarm.databinding.FragmentSettingsLabBinding
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
class FragmentSettingsLab : Fragment() {
|
||||
|
||||
private var _binding: FragmentSettingsLabBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
private var isInitialLoad = true
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
@@ -28,56 +26,51 @@ class FragmentSettingsLab : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupNumberPicker()
|
||||
setupSpinner()
|
||||
loadAnnualLeave()
|
||||
setupSaveButton()
|
||||
}
|
||||
|
||||
private fun setupNumberPicker() {
|
||||
binding.npTotalDays.apply {
|
||||
minValue = 1
|
||||
maxValue = 25
|
||||
wrapSelectorWheel = false
|
||||
|
||||
// 값 변경 시 자동 저장
|
||||
setOnValueChangedListener { _, _, newVal ->
|
||||
if (!isInitialLoad) {
|
||||
saveAnnualLeave(newVal)
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun setupSpinner() {
|
||||
// 1~25일 선택 가능한 어댑터 설정
|
||||
val daysList = (1..25).map { "${it}일" }.toList()
|
||||
val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, daysList)
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
binding.spinnerTotalDays.adapter = adapter
|
||||
}
|
||||
|
||||
private fun loadAnnualLeave() {
|
||||
lifecycleScope.launch {
|
||||
isInitialLoad = true
|
||||
val repo = ShiftRepository(requireContext())
|
||||
|
||||
val annualLeave = repo.getAnnualLeave()
|
||||
annualLeave?.let {
|
||||
binding.npTotalDays.value = it.totalDays.toInt()
|
||||
// 저장된 값이 있으면 해당 위치 선택 (0-indexed)
|
||||
binding.spinnerTotalDays.setSelection(it.totalDays.toInt() - 1)
|
||||
binding.tvRemainingDays.text = formatRemainingDays(it.remainingDays)
|
||||
} ?: run {
|
||||
// Default: 15 days
|
||||
binding.npTotalDays.value = 15
|
||||
// Default: 15 days (index 14)
|
||||
binding.spinnerTotalDays.setSelection(14)
|
||||
binding.tvRemainingDays.text = "15"
|
||||
}
|
||||
|
||||
// 초기 로드 완료 후 플래그 변경
|
||||
delay(100)
|
||||
isInitialLoad = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveAnnualLeave(totalDays: Int) {
|
||||
lifecycleScope.launch {
|
||||
val repo = ShiftRepository(requireContext())
|
||||
private fun setupSaveButton() {
|
||||
binding.btnSaveAnnualLeave.setOnClickListener {
|
||||
val selectedPosition = binding.spinnerTotalDays.selectedItemPosition
|
||||
val totalDays = selectedPosition + 1 // 0-indexed to actual days
|
||||
|
||||
repo.recalculateAndSaveAnnualLeave(totalDays.toFloat())
|
||||
|
||||
val updated = repo.getAnnualLeave()
|
||||
updated?.let {
|
||||
binding.tvRemainingDays.text = formatRemainingDays(it.remainingDays)
|
||||
showCustomToast(requireContext(), "총 연차 ${totalDays}일로 설정되었습니다 (남은 연차: ${formatRemainingDays(it.remainingDays)}일)")
|
||||
lifecycleScope.launch {
|
||||
val repo = ShiftRepository(requireContext())
|
||||
|
||||
repo.recalculateAndSaveAnnualLeave(totalDays.toFloat())
|
||||
|
||||
val updated = repo.getAnnualLeave()
|
||||
updated?.let {
|
||||
binding.tvRemainingDays.text = formatRemainingDays(it.remainingDays)
|
||||
showCustomToast(requireContext(), "총 연차 ${totalDays}일로 저장되었습니다 (남은 연차: ${formatRemainingDays(it.remainingDays)}일)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,10 @@
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<NumberPicker
|
||||
<Spinner
|
||||
android:id="@+id/spinnerTotalDays"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="48dp"/>
|
||||
android:id="@+id/npTotalDays"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="100dp"/>
|
||||
@@ -123,4 +126,25 @@
|
||||
android:layout_marginBottom="8dp"
|
||||
android:gravity="center"/>
|
||||
|
||||
<!-- Calculation Info -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="※ 연차: -1일 / 반년: -0.5일 차감"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/text_tertiary"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:gravity="center"/>
|
||||
|
||||
<!-- Save Button -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnSaveAnnualLeave"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:text="저장"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:cornerRadius="12dp"
|
||||
android:backgroundTint="@color/primary"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user