feat: 휴가 관리 컴팩트화 + 자동 저장 + 소숫점 표시 개선
- 레이아웃 컴팩트하게 변경 (패딩/마진 축소, 가로 배치) - 저장 버튼 제거하고 NumberPicker 변경 시 자동 저장 - 소숫점 없을 때 정수로 표시 (22), 0.5일 때 소숫점 표시 (21.5) - ScrollView 제거 (불필요한 스크롤 최소화) 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,16 +4,18 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import android.widget.NumberPicker
|
||||
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,7 +30,6 @@ class FragmentSettingsLab : Fragment() {
|
||||
|
||||
setupNumberPicker()
|
||||
loadAnnualLeave()
|
||||
setupSaveButton()
|
||||
}
|
||||
|
||||
private fun setupNumberPicker() {
|
||||
@@ -36,42 +37,65 @@ class FragmentSettingsLab : Fragment() {
|
||||
minValue = 1
|
||||
maxValue = 25
|
||||
wrapSelectorWheel = false
|
||||
|
||||
// 값 변경 시 자동 저장
|
||||
setOnValueChangedListener { _, _, newVal ->
|
||||
if (!isInitialLoad) {
|
||||
saveAnnualLeave(newVal)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadAnnualLeave() {
|
||||
lifecycleScope.launch {
|
||||
isInitialLoad = true
|
||||
val repo = ShiftRepository(requireContext())
|
||||
|
||||
val annualLeave = repo.getAnnualLeave()
|
||||
annualLeave?.let {
|
||||
binding.npTotalDays.value = it.totalDays.toInt()
|
||||
binding.tvRemainingDays.text = String.format("%.1f", it.remainingDays)
|
||||
binding.tvRemainingDays.text = formatRemainingDays(it.remainingDays)
|
||||
} ?: run {
|
||||
// Default: 15 days
|
||||
binding.npTotalDays.value = 15
|
||||
binding.tvRemainingDays.text = "15.0"
|
||||
binding.tvRemainingDays.text = "15"
|
||||
}
|
||||
|
||||
// 초기 로드 완료 후 플래그 변경
|
||||
delay(100)
|
||||
isInitialLoad = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveAnnualLeave(totalDays: Int) {
|
||||
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)}일)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSaveButton() {
|
||||
binding.btnSaveAnnualLeave.setOnClickListener {
|
||||
val totalDays = binding.npTotalDays.value.toFloat()
|
||||
|
||||
lifecycleScope.launch {
|
||||
val repo = ShiftRepository(requireContext())
|
||||
|
||||
repo.recalculateAndSaveAnnualLeave(totalDays)
|
||||
|
||||
val updated = repo.getAnnualLeave()
|
||||
updated?.let {
|
||||
binding.tvRemainingDays.text = String.format("%.1f", it.remainingDays)
|
||||
showCustomToast(requireContext(), "연차가 저장되었습니다. (남은 연차: ${String.format("%.1f", it.remainingDays)}일)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 남은 연차 표시 형식 개선
|
||||
* - 정수면 정수로 표시 (예: 22)
|
||||
* - 소숫점 있으면 소숫점 표시 (예: 21.5)
|
||||
*/
|
||||
private fun formatRemainingDays(days: Float): String {
|
||||
return if (days == days.toInt().toFloat()) {
|
||||
// 정수인 경우
|
||||
days.toInt().toString()
|
||||
} else {
|
||||
// 소숫점이 있는 경우 (0.5 등)
|
||||
String.format("%.1f", days)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
|
||||
@@ -1,135 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout 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"
|
||||
android:fillViewport="true">
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<LinearLayout
|
||||
<!-- Header Title -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="나의 연차 설정"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/text_primary"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- Total Annual Leave Setting -->
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp"
|
||||
android:gravity="center_horizontal">
|
||||
android:layout_marginBottom="12dp"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="2dp"
|
||||
app:cardBackgroundColor="@color/surface">
|
||||
|
||||
<!-- Header Title -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="나의 연차 설정"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/text_primary"
|
||||
android:layout_marginBottom="32dp"/>
|
||||
|
||||
<!-- Total Annual Leave Setting -->
|
||||
<androidx.cardview.widget.CardView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="4dp"
|
||||
app:cardBackgroundColor="@color/surface">
|
||||
android:orientation="horizontal"
|
||||
android:padding="12dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="총 연차"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/text_secondary"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp"
|
||||
android:gravity="center">
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="총 연차"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- NumberPicker for Total Days -->
|
||||
<NumberPicker
|
||||
android:id="@+id/npTotalDays"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="100dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="일"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/text_tertiary"/>
|
||||
|
||||
android:textColor="@color/text_tertiary"
|
||||
android:layout_marginStart="4dp"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
<!-- Remaining Annual Leave Display -->
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="2dp"
|
||||
app:cardBackgroundColor="@color/surface">
|
||||
|
||||
<!-- Remaining Annual Leave Display -->
|
||||
<androidx.cardview.widget.CardView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="32dp"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="4dp"
|
||||
app:cardBackgroundColor="@color/surface">
|
||||
android:orientation="horizontal"
|
||||
android:padding="12dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="남은 연차"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/text_secondary"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="남은 연차"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
android:orientation="horizontal"
|
||||
android:gravity="bottom">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRemainingDays"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0.0"
|
||||
android:textSize="36sp"
|
||||
android:text="15"
|
||||
android:textSize="28sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/primary"
|
||||
android:layout_marginBottom="4dp"/>
|
||||
android:textColor="@color/primary"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="일"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/text_tertiary"/>
|
||||
|
||||
android:textColor="@color/text_tertiary"
|
||||
android:layout_marginStart="4dp"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
<!-- 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="8dp"
|
||||
android:gravity="center"/>
|
||||
|
||||
<!-- Calculation Info -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="※ 연차: -1일 차감 / 반년: -0.5일 차감"
|
||||
android:textSize="13sp"
|
||||
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>
|
||||
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user