Skip to content

Commit

Permalink
feat: 인증번호 만료 타이머 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ootr47 committed Feb 28, 2024
1 parent 0dc3274 commit e6c235e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.priceguard.ui.login.findpassword

import android.os.Bundle
import android.os.CountDownTimer
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -15,6 +16,7 @@ import app.priceguard.ui.util.lifecycle.repeatOnStarted
import app.priceguard.ui.util.safeNavigate
import app.priceguard.ui.util.showDialogWithAction
import dagger.hilt.android.AndroidEntryPoint
import java.util.concurrent.TimeUnit

@AndroidEntryPoint
class EmailVerificationFragment : Fragment() {
Expand Down Expand Up @@ -107,6 +109,22 @@ class EmailVerificationFragment : Fragment() {
}

private fun startTimer(totalTimeInSeconds: Int) {
val countDownTimer = object : CountDownTimer((totalTimeInSeconds * 1000).toLong(), 1000) {
override fun onTick(millisUntilFinished: Long) {
val timeLeft = millisUntilFinished / 1000
val minutes = TimeUnit.SECONDS.toMinutes(timeLeft)
val seconds = timeLeft - TimeUnit.MINUTES.toSeconds(minutes)

emailVerificationViewModel.updateTimer(String.format("%02d:%02d", minutes, seconds))
}

override fun onFinish() {
emailVerificationViewModel.updateTimer("0")
}
}
countDownTimer.start()
}

private fun goToResetPassword() {
val action =
EmailVerificationFragmentDirections.actionEmailVerificationFragmentToResetPasswordFragment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EmailVerificationViewModel @Inject constructor(
val email: String = "",
val verificationCode: String = "",
val verifyToken: String = "",
val expirationTime: String = "",
val isMatchedEmailRegex: Boolean = false,
val isRequestedVerificationCode: Boolean = false,
val isFinishedRequestVerificationCode: Boolean = false,
Expand Down Expand Up @@ -118,6 +119,10 @@ class EmailVerificationViewModel @Inject constructor(
checkNextEnabled()
}

fun updateTimer(timeString: String) {
_state.value = _state.value.copy(expirationTime = timeString)
}

private fun checkEmailRegex(email: String) {
val emailPattern =
"""^[\w.+-]+@((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$""".toRegex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:hint="@string/verification_number"
app:helperText='@{viewModel.state.finishedRequestVerificationCode ? "인증번호 전송 완료" : " "}'
app:helperText='@{viewModel.state.finishedRequestVerificationCode ? viewModel.state.expirationTime == "0" ? @string/expired : @string/finish_send_verification_code(viewModel.state.expirationTime) : " "}'
app:layout_constraintEnd_toEndOf="@id/btn_email_verification_verify"
app:layout_constraintStart_toStartOf="@id/til_email_verification_email"
app:layout_constraintTop_toBottomOf="@id/til_email_verification_email">
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@
<string name="reset_password_content">새로운 비밀번호로 재설정해 주세요.</string>
<string name="find_password_title_1">비밀번호 찾기 (1/2)</string>
<string name="find_password_title_2">비밀번호 찾기 (2/2)</string>
<string name="finish_send_verification_code">인증번호 전송 완료 %s</string>
<string name="expired">만료됨</string>
<string name="request_verification_code_limit_max_5">인증번호는 하루 최대 5번까지 전송 가능합니다.</string>
<string name="success_reset_password_retry_login">비밀번호가 재설정되었습니다.\n다시 로그인해 주세요</string>
<string name="finish_find_password">비밀번호 찾기 완료</string>
Expand Down

0 comments on commit e6c235e

Please sign in to comment.