Skip to content

Commit ed0f5ce

Browse files
committed
moneymong-306 feat: ocr 스캔 예외 핸들링
1 parent b785b90 commit ed0f5ce

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

feature/ocr-detail/src/main/java/com/moneymong/moneymong/ocr_detail/OCRDetailViewModel.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import org.orbitmvi.orbit.syntax.simple.intent
2121
import org.orbitmvi.orbit.syntax.simple.postSideEffect
2222
import org.orbitmvi.orbit.syntax.simple.reduce
2323
import java.io.File
24+
import java.text.SimpleDateFormat
25+
import java.util.Date
26+
import java.util.Locale
2427
import javax.inject.Inject
2528

2629
@HiltViewModel
@@ -39,12 +42,14 @@ class OCRDetailViewModel @Inject constructor(
3942

4043
fun init(document: DocumentEntity?) = intent {
4144
val receipt = document?.images?.first()?.receipt?.result
42-
val paymentDateString = receipt?.paymentInfo?.date?.formatted.run {
43-
"${this?.year ?: ""}${this?.month ?: ""}${this?.day ?: ""}"
44-
}
45-
val paymentTimeString = receipt?.paymentInfo?.time?.formatted.run {
46-
"${this?.hour ?: ""}${this?.minute ?: ""}${this?.second ?: ""}"
47-
}
45+
val currentDate = SimpleDateFormat("yyyyMMdd", Locale.KOREA).format(Date(System.currentTimeMillis()))
46+
val currentTime = SimpleDateFormat("HHmmss", Locale.KOREA).format(Date(System.currentTimeMillis()))
47+
val paymentDateString = receipt?.paymentInfo?.date?.let {
48+
"${it.formatted?.year}${it.formatted?.month}${it.formatted?.day}"
49+
} ?: currentDate
50+
val paymentTimeString = receipt?.paymentInfo?.time?.let {
51+
"${it.formatted?.hour}:${it.formatted?.minute}:${it.formatted?.second}"
52+
} ?: currentTime
4853
reduce {
4954
state.copy(
5055
document = document,
@@ -77,7 +82,7 @@ class OCRDetailViewModel @Inject constructor(
7782
id = state.agencyId,
7883
storeInfo = state.storeNameValue.text,
7984
fundType = state.fundType,
80-
amount = state.totalPriceValue.text.toInt(),
85+
amount = state.totalPriceValue.text.replace(".", "").toInt(),
8186
description = state.memoValue.text,
8287
paymentDate = state.postPaymentDate,
8388
receiptImageUrls = state.receiptImageUrls,

0 commit comments

Comments
 (0)