Skip to content

Commit c37d4a8

Browse files
committed
Fix issue where processing indicator shows when not supported
- if the device does not support processing indicator then the indicator still appears - this fixes the issue
1 parent 7bb54ef commit c37d4a8

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

CameraXExtensions/app/src/main/java/com/example/android/cameraxextensions/MainActivity.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ class MainActivity : AppCompatActivity() {
206206
)
207207
}
208208
CaptureState.CaptureReady -> {
209+
captureUri = null
210+
progressComplete = false
209211
captureScreenViewState.emit(
210212
captureScreenViewState.value
211213
.updateCameraScreen {
@@ -225,13 +227,8 @@ class MainActivity : AppCompatActivity() {
225227
}
226228
is CaptureState.CaptureFinished -> {
227229
captureUri = state.outputResults.savedUri
228-
if (!progressComplete) {
229-
captureScreenViewState.emit(
230-
captureScreenViewState.value
231-
.updateCameraScreen {
232-
it.showProcessProgressViewState(100)
233-
}
234-
)
230+
if (!state.isProcessProgressSupported) {
231+
progressComplete = true
235232
}
236233
showCapture()
237234
}

CameraXExtensions/app/src/main/java/com/example/android/cameraxextensions/model/CameraUiState.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ sealed class CaptureState {
8888
/**
8989
* Capture completed successfully.
9090
*/
91-
data class CaptureFinished(val outputResults: ImageCapture.OutputFileResults) : CaptureState()
91+
data class CaptureFinished(
92+
val outputResults: ImageCapture.OutputFileResults,
93+
val isProcessProgressSupported: Boolean
94+
) : CaptureState()
9295

9396
/**
9497
* Capture failed with an error.

CameraXExtensions/app/src/main/java/com/example/android/cameraxextensions/ui/CameraExtensionsScreen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ class CameraExtensionsScreen(private val root: View) {
242242

243243
private fun showProcessProgressIndicator(progress: Int) {
244244
processProgressContainer.isVisible = true
245+
if (progress == processProgressIndicator.progress) return
246+
245247
ObjectAnimator.ofInt(processProgressIndicator, "progress", progress).apply {
246248
val currentProgress = processProgressIndicator.progress
247249
val progressStep = max(0, progress - currentProgress)

CameraXExtensions/app/src/main/java/com/example/android/cameraxextensions/viewmodel/CameraExtensionsViewModel.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,19 @@ class CameraExtensionsViewModel(
261261
application,
262262
outputFileResults.savedUri ?: photoFile.toUri()
263263
)
264+
val isProcessProgressSupported = camera?.cameraInfo?.let {
265+
ImageCapture.getImageCaptureCapabilities(it).isCaptureProcessProgressSupported
266+
} ?: false
264267
viewModelScope.launch {
265-
_captureUiState.emit(CaptureState.CaptureFinished(outputFileResults))
268+
if (isProcessProgressSupported) {
269+
_captureUiState.emit(CaptureState.CaptureProcessProgress(100))
270+
}
271+
_captureUiState.emit(
272+
CaptureState.CaptureFinished(
273+
outputFileResults,
274+
isProcessProgressSupported
275+
)
276+
)
266277
}
267278
}
268279

0 commit comments

Comments
 (0)