diff --git a/feature/timer/src/main/java/com/project200/feature/timer/TimePickerDialog.kt b/feature/timer/src/main/java/com/project200/feature/timer/TimePickerDialog.kt index fe686671..59b4a584 100644 --- a/feature/timer/src/main/java/com/project200/feature/timer/TimePickerDialog.kt +++ b/feature/timer/src/main/java/com/project200/feature/timer/TimePickerDialog.kt @@ -3,8 +3,10 @@ package com.project200.feature.timer import android.graphics.Color import android.view.View import android.view.WindowManager +import android.widget.EditText import androidx.core.graphics.drawable.toDrawable import com.project200.presentation.base.BaseDialogFragment +import com.project200.presentation.utils.TimeEditTextLimiter.addRangeLimit import com.project200.undabang.feature.timer.R import com.project200.undabang.feature.timer.databinding.DialogTimePickerBinding import dagger.hilt.android.AndroidEntryPoint @@ -14,8 +16,7 @@ import java.util.Locale class TimePickerDialog( private val initialTime: Int? = null, private val onTimeSelected: (Int) -> Unit, -) : - BaseDialogFragment(R.layout.dialog_time_picker) { +) : BaseDialogFragment(R.layout.dialog_time_picker) { override fun getViewBinding(view: View): DialogTimePickerBinding { return DialogTimePickerBinding.bind(view) } @@ -23,6 +24,7 @@ class TimePickerDialog( override fun setupViews() { super.setupViews() + // 다이얼로그 가로 너비 및 배경 투명화 설정 dialog?.window?.let { window -> val screenWidth = resources.displayMetrics.widthPixels val desiredWidth = (screenWidth * 0.85).toInt() @@ -30,12 +32,13 @@ class TimePickerDialog( window.setBackgroundDrawable(Color.TRANSPARENT.toDrawable()) } - setupTimePickers() + setupTimeInputs() + setupFocusAndRangeListeners() binding.confirmBtn.setOnClickListener { - // NumberPicker에서 선택된 분과 초를 가져옵니다. - val minutes = binding.minutePicker.value - val seconds = binding.secondPicker.value + // 빈 칸일 경우 0으로 처리, 범위 재확인 + val minutes = (binding.minuteEt.text.toString().toIntOrNull() ?: 0).coerceIn(0, 59) + val seconds = (binding.secondEt.text.toString().toIntOrNull() ?: 0).coerceIn(0, 59) val totalTimeInSeconds = (minutes * 60) + seconds onTimeSelected(totalTimeInSeconds) @@ -47,22 +50,43 @@ class TimePickerDialog( } } - private fun setupTimePickers() { - binding.minutePicker.apply { - minValue = 0 - maxValue = 59 // 최대 59분 - value = initialTime?.div(60) ?: 0 // 초기값이 null인 경우 0으로 설정 - setFormatter { String.format(Locale.KOREA, "%02d", it) } - } + private fun setupTimeInputs() { + // 초 단위를 분과 초로 계산하여 초기값 설정 + val minutes = initialTime?.div(60) ?: 0 + val seconds = initialTime?.rem(60) ?: 0 - binding.secondPicker.apply { - minValue = 0 - maxValue = 59 // 최대 59초 - value = initialTime?.rem(60) ?: 0 // 초기값이 null인 경우 0으로 설정 - setFormatter { String.format(Locale.KOREA, "%02d", it) } - } + binding.minuteEt.setText(String.format(Locale.KOREA, "%02d", minutes)) + binding.secondEt.setText(String.format(Locale.KOREA, "%02d", seconds)) } - companion object { + private fun setupFocusAndRangeListeners() { + // 1. 포커스 상태에 따른 배경 및 포맷팅 처리 + val focusChangeListener = + View.OnFocusChangeListener { view, hasFocus -> + if (view is EditText) { + if (hasFocus) { + // 포커스 얻었을 때: 배경 적용 및 텍스트 전체 선택 + view.setBackgroundResource(com.project200.undabang.presentation.R.drawable.bg_solid_corner) + view.selectAll() + } else { + // 포커스 잃었을 때: 배경 제거 및 00~59 보정 후 포맷팅 + view.setBackgroundResource(0) + val input = view.text.toString().toIntOrNull() ?: 0 + val clamped = input.coerceIn(0, 59) + view.setText(String.format(Locale.KOREA, "%02d", clamped)) + } + } + } + + binding.minuteEt.onFocusChangeListener = focusChangeListener + binding.secondEt.onFocusChangeListener = focusChangeListener + + // 실시간 입력 범위 제한 (0~59) + binding.minuteEt.addRangeLimit(59) + binding.secondEt.addRangeLimit(59) + + // 초기 상태 배경 제거 + binding.minuteEt.setBackgroundResource(0) + binding.secondEt.setBackgroundResource(0) } } diff --git a/feature/timer/src/main/res/layout/dialog_time_picker.xml b/feature/timer/src/main/res/layout/dialog_time_picker.xml index effe59a6..d7603c49 100644 --- a/feature/timer/src/main/res/layout/dialog_time_picker.xml +++ b/feature/timer/src/main/res/layout/dialog_time_picker.xml @@ -2,32 +2,72 @@ - - - + style="@style/subtext_14" + android:text="@string/minute" + android:layout_marginBottom="6dp" + app:layout_constraintStart_toStartOf="@id/minute_et" + app:layout_constraintEnd_toEndOf="@id/minute_et" + app:layout_constraintBottom_toTopOf="@id/minute_et"/> + - - + android:layout_gravity="center" + android:text="@string/time_divider" + android:textSize="40sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/second_et" + app:layout_constraintStart_toEndOf="@id/minute_et" + app:layout_constraintTop_toTopOf="@+id/minute_et" /> + + + 시작 일시 정지 종료 + + + : %1$d / %2$d %3$s %02d:%02d