Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,23 @@ internal class ExternalCredentialScanQrFragment : Fragment(R.layout.fragment_ext
}
}

override fun onPause() {
if (isCameraInitialized) {
cameraHelper.stopCamera()
isCameraInitialized = false
}
super.onPause()
}

override fun onResume() {
super.onResume()
val cameraPermissionStatus = requireActivity().getCurrentPermissionStatus(CAMERA)
viewModel.updateCameraPermissionStatus(cameraPermissionStatus)
}

override fun onDestroy() {
override fun onDestroyView() {
dismissDialog()
super.onDestroy()
super.onDestroyView()
}

private fun dismissDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:ellipsize="end"
android:maxLines="3"
tools:text="QR_CODE" />
</com.google.android.material.card.MaterialCardView>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CameraHelper @AssistedInject constructor(
private val cameraFocusManagerFactory: CameraFocusManager.Factory,
) {
private val cameraFocusManager by lazy { cameraFocusManagerFactory.create(crashReportTag) }
private var cameraProvider: ProcessCameraProvider? = null

@AssistedFactory
interface Factory {
Expand All @@ -43,9 +44,13 @@ class CameraHelper @AssistedInject constructor(
val providerFuture = ProcessCameraProvider.getInstance(context)
providerFuture.addListener(
{
val cameraProvider = providerFuture.get()
val provider = providerFuture.get().also { provider ->
cameraProvider = provider
provider.unbindAll()
}

// Check if the back camera is available
if (cameraProvider.hasCamera(CameraSelector.DEFAULT_BACK_CAMERA).not()) {
if (provider.hasCamera(CameraSelector.DEFAULT_BACK_CAMERA).not()) {
initializationErrorListener.onCameraError()
return@addListener
}
Expand All @@ -54,7 +59,7 @@ class CameraHelper @AssistedInject constructor(
val preview = buildPreview(cameraPreview)

try {
cameraProvider
provider
.bindToLifecycle(
lifecycleOwner,
cameraSelector,
Expand All @@ -75,6 +80,11 @@ class CameraHelper @AssistedInject constructor(
)
}

fun stopCamera() {
cameraProvider?.unbindAll()
cameraProvider = null
}

private fun buildAnalyser(qrAnalyser: QrCodeAnalyzer) = ImageAnalysis
.Builder()
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
Expand Down