Skip to content

Commit

Permalink
release-1.0.0 fix: ocr 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
Heonbyeong committed Feb 8, 2024
1 parent 77a0379 commit a3e6b4a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ fun String.toWonFormat(unit: Boolean = false): String {
return if (this.isEmpty()) {
this
} else {
if (unit) {
"${DecimalFormat("#,###").format(this.toLong())}"
} else {
DecimalFormat("#,###").format(this.toLong())
try {
if (unit) {
"${DecimalFormat("#,###").format(this.toLong())}"
} else {
DecimalFormat("#,###").format(this.toLong())
}
} catch (e: Exception) {
""
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.moneymong.moneymong.design_system.theme.White
import com.moneymong.moneymong.common.ext.hasPermission
import com.moneymong.moneymong.common.ui.noRippleClickable
import com.moneymong.moneymong.common.util.DisposableEffectWithLifeCycle
import com.moneymong.moneymong.design_system.error.ErrorDialog
import com.moneymong.moneymong.design_system.theme.Black
import com.moneymong.moneymong.ocr.view.OCRCameraPermissionDeniedView
import com.moneymong.moneymong.ocr.view.OCRCaptureView
Expand Down Expand Up @@ -105,6 +106,12 @@ fun OCRScreen(
)
}

if (state.visibleErrorDialog) {
ErrorDialog(message = state.errorMessage) {
viewModel.onChangeVisibleErrorDialog(false)
}
}

Scaffold {
Box(
modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ data class OCRState(
val permissionDialogStatus: Boolean = false,
val isDeniedCamera: Boolean = false,
val visibleHelper: Boolean = true,
val isLoading: Boolean = false
val isLoading: Boolean = false,
val visibleErrorDialog: Boolean = false,
val errorMessage: String = ""
): State {

val isReceipt: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class OCRViewModel @Inject constructor(
.onSuccess {
reduce { state.copy(document = it) }
possibleNavigateToOCRResult(it.images.first().inferResult.orEmpty())
}.onFailure {
reduce {
state.copy(
visibleErrorDialog = true,
errorMessage = "영수증을 인식하지 못했습니다."
)
}
}.also { reduce { state.copy(isLoading = false) } }
}
}
Expand Down Expand Up @@ -110,4 +117,8 @@ class OCRViewModel @Inject constructor(
fun onClickHelper() = intent {
reduce { state.copy(visibleHelper = !state.visibleHelper) }
}

fun onChangeVisibleErrorDialog(visible: Boolean) = intent {
reduce { state.copy(visibleErrorDialog = visible) }
}
}

0 comments on commit a3e6b4a

Please sign in to comment.