diff --git a/sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/SyncFeature.kt b/sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/SyncFeature.kt index be105cff5e67..bb9afd5d278e 100644 --- a/sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/SyncFeature.kt +++ b/sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/SyncFeature.kt @@ -53,4 +53,7 @@ interface SyncFeature { @Toggle.DefaultValue(true) fun automaticallyUpdateSyncSettings(): Toggle + + @Toggle.DefaultValue(true) + fun qrCodeScannerHints(): Toggle } diff --git a/sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/ui/qrcode/SyncBarcodeView.kt b/sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/ui/qrcode/SyncBarcodeView.kt index d4b6994c0dec..5a0c3dc20e6c 100644 --- a/sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/ui/qrcode/SyncBarcodeView.kt +++ b/sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/ui/qrcode/SyncBarcodeView.kt @@ -35,11 +35,14 @@ import androidx.lifecycle.findViewTreeLifecycleOwner import androidx.lifecycle.findViewTreeViewModelStoreOwner import androidx.lifecycle.lifecycleScope import com.duckduckgo.anvil.annotations.InjectWith +import com.duckduckgo.appbuildconfig.api.AppBuildConfig +import com.duckduckgo.appbuildconfig.api.isInternalBuild import com.duckduckgo.common.ui.viewbinding.viewBinding import com.duckduckgo.common.utils.ConflatedJob import com.duckduckgo.common.utils.DispatcherProvider import com.duckduckgo.di.scopes.ViewScope import com.duckduckgo.sync.impl.R +import com.duckduckgo.sync.impl.SyncFeature import com.duckduckgo.sync.impl.databinding.ViewSquareDecoratedBarcodeBinding import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Command import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Command.CheckCameraAvailable @@ -47,9 +50,12 @@ import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Comman import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Command.OpenSettings import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.Command.RequestPermissions import com.duckduckgo.sync.impl.ui.qrcode.SquareDecoratedBarcodeViewModel.ViewState +import com.google.zxing.BarcodeFormat.QR_CODE +import com.google.zxing.client.android.BeepManager +import com.journeyapps.barcodescanner.DefaultDecoderFactory +import com.journeyapps.barcodescanner.camera.CameraSettings import dagger.android.support.AndroidSupportInjection import javax.inject.Inject -import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -72,6 +78,12 @@ constructor( @Inject lateinit var dispatchers: DispatcherProvider + @Inject + lateinit var appBuildConfig: AppBuildConfig + + @Inject + lateinit var syncFeature: SyncFeature + private val cameraBlockedDrawable by lazy { ContextCompat.getDrawable(context, R.drawable.camera_blocked) } @@ -86,6 +98,13 @@ constructor( ViewModelProvider(findViewTreeViewModelStoreOwner()!!, viewModelFactory)[SquareDecoratedBarcodeViewModel::class.java] } + private var beepManager: BeepManager? = null + + private val cameraSettings = CameraSettings().apply { + isAutoFocusEnabled = true + isContinuousFocusEnabled = true + } + private val conflatedStateJob = ConflatedJob() private val conflatedCommandJob = ConflatedJob() @@ -93,6 +112,8 @@ constructor( AndroidSupportInjection.inject(this) super.onAttachedToWindow() + initQRScanner() + findViewTreeLifecycleOwner()?.lifecycle?.addObserver(viewModel) val scope = findViewTreeLifecycleOwner()?.lifecycleScope!! @@ -110,6 +131,16 @@ constructor( } } + private fun initQRScanner() { + if (syncFeature.qrCodeScannerHints().isEnabled()) { + if (appBuildConfig.isInternalBuild()) { + beepManager = BeepManager(getActivity()) + } + binding.barcodeView.cameraSettings = cameraSettings + binding.barcodeView.decoderFactory = DefaultDecoderFactory(listOf(QR_CODE)) + } + } + override fun onDetachedFromWindow() { conflatedStateJob.cancel() conflatedCommandJob.cancel() @@ -135,6 +166,7 @@ constructor( fun decodeSingle(onQrCodeRead: (String) -> Unit) { binding.barcodeView.decodeSingle { + beepManager?.playBeepSoundAndVibrate() onQrCodeRead(it.text) } }