Skip to content

Commit

Permalink
Fix issue where processing indicator shows when not supported
Browse files Browse the repository at this point in the history
- if the device does not support processing indicator then the indicator still appears
- this fixes the issue
  • Loading branch information
jsaund committed May 24, 2024
1 parent 7bb54ef commit c37d4a8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class MainActivity : AppCompatActivity() {
)
}
CaptureState.CaptureReady -> {
captureUri = null
progressComplete = false
captureScreenViewState.emit(
captureScreenViewState.value
.updateCameraScreen {
Expand All @@ -225,13 +227,8 @@ class MainActivity : AppCompatActivity() {
}
is CaptureState.CaptureFinished -> {
captureUri = state.outputResults.savedUri
if (!progressComplete) {
captureScreenViewState.emit(
captureScreenViewState.value
.updateCameraScreen {
it.showProcessProgressViewState(100)
}
)
if (!state.isProcessProgressSupported) {
progressComplete = true
}
showCapture()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ sealed class CaptureState {
/**
* Capture completed successfully.
*/
data class CaptureFinished(val outputResults: ImageCapture.OutputFileResults) : CaptureState()
data class CaptureFinished(
val outputResults: ImageCapture.OutputFileResults,
val isProcessProgressSupported: Boolean
) : CaptureState()

/**
* Capture failed with an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ class CameraExtensionsScreen(private val root: View) {

private fun showProcessProgressIndicator(progress: Int) {
processProgressContainer.isVisible = true
if (progress == processProgressIndicator.progress) return

ObjectAnimator.ofInt(processProgressIndicator, "progress", progress).apply {
val currentProgress = processProgressIndicator.progress
val progressStep = max(0, progress - currentProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,19 @@ class CameraExtensionsViewModel(
application,
outputFileResults.savedUri ?: photoFile.toUri()
)
val isProcessProgressSupported = camera?.cameraInfo?.let {
ImageCapture.getImageCaptureCapabilities(it).isCaptureProcessProgressSupported
} ?: false
viewModelScope.launch {
_captureUiState.emit(CaptureState.CaptureFinished(outputFileResults))
if (isProcessProgressSupported) {
_captureUiState.emit(CaptureState.CaptureProcessProgress(100))
}
_captureUiState.emit(
CaptureState.CaptureFinished(
outputFileResults,
isProcessProgressSupported
)
)
}
}

Expand Down

0 comments on commit c37d4a8

Please sign in to comment.