Avoid crashing when importing an invalid image (#171)
This commit is contained in:
@@ -36,6 +36,7 @@ import org.fairscan.app.domain.CapturedPage
|
|||||||
import org.fairscan.app.platform.extractDocumentFromBitmap
|
import org.fairscan.app.platform.extractDocumentFromBitmap
|
||||||
import org.fairscan.imageprocessing.ImageSize
|
import org.fairscan.imageprocessing.ImageSize
|
||||||
import org.fairscan.imageprocessing.detectDocumentQuad
|
import org.fairscan.imageprocessing.detectDocumentQuad
|
||||||
|
import java.util.concurrent.CancellationException
|
||||||
|
|
||||||
sealed interface CameraEvent {
|
sealed interface CameraEvent {
|
||||||
data class ImageCaptured(val page: CapturedPage) : CameraEvent
|
data class ImageCaptured(val page: CapturedPage) : CameraEvent
|
||||||
@@ -203,6 +204,7 @@ class CameraViewModel(appContainer: AppContainer): ViewModel() {
|
|||||||
_importState.value = ImportState.Importing(0, uris.size)
|
_importState.value = ImportState.Importing(0, uris.size)
|
||||||
uris.forEachIndexed { index, uri ->
|
uris.forEachIndexed { index, uri ->
|
||||||
ensureActive()
|
ensureActive()
|
||||||
|
try {
|
||||||
val photoToImport = imageLoader.load(uri)
|
val photoToImport = imageLoader.load(uri)
|
||||||
ensureActive()
|
ensureActive()
|
||||||
val page = processCapturedImage(photoToImport, 0)
|
val page = processCapturedImage(photoToImport, 0)
|
||||||
@@ -210,6 +212,11 @@ class CameraViewModel(appContainer: AppContainer): ViewModel() {
|
|||||||
page?.let {
|
page?.let {
|
||||||
_events.emit(CameraEvent.ImageCaptured(it))
|
_events.emit(CameraEvent.ImageCaptured(it))
|
||||||
}
|
}
|
||||||
|
} catch (e: CancellationException) {
|
||||||
|
throw e
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.e("Import", "Failed to import image: $uri", e)
|
||||||
|
}
|
||||||
_importState.value = ImportState.Importing(index + 1, uris.size)
|
_importState.value = ImportState.Importing(index + 1, uris.size)
|
||||||
}
|
}
|
||||||
_importState.value = ImportState.Idle
|
_importState.value = ImportState.Idle
|
||||||
|
|||||||
Reference in New Issue
Block a user