From fae74dd3ca4d05f99c9301fcd6ba82e2fbd4a002 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 25 Oct 2021 22:37:01 +0530 Subject: ui: upgrade zxing-android-embedded Signed-off-by: Harsh Shandilya --- build.gradle | 2 +- ui/src/main/AndroidManifest.xml | 3 --- .../wireguard/android/fragment/TunnelListFragment.kt | 20 ++++++++++---------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 2bda0118..336c4631 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { lifecycleRuntimeKtxVersion = '2.3.1' materialComponentsVersion = '1.4.0' preferenceVersion = '1.1.1' - zxingEmbeddedVersion = '4.2.0' + zxingEmbeddedVersion = '4.3.0' groupName = 'com.wireguard.android' } diff --git a/ui/src/main/AndroidManifest.xml b/ui/src/main/AndroidManifest.xml index ce527498..4c957bd7 100644 --- a/ui/src/main/AndroidManifest.xml +++ b/ui/src/main/AndroidManifest.xml @@ -29,9 +29,6 @@ android:label="@string/permission_label" android:protectionLevel="dangerous" /> - - - - val qrCode = IntentIntegrator.parseActivityResult(result.resultCode, result.data)?.contents - ?: return@registerForActivityResult - val activity = activity ?: return@registerForActivityResult - val fragManager = parentFragmentManager - activity.lifecycleScope.launch { TunnelImporter.importTunnel(fragManager, qrCode) { showSnackbar(it) } } + private val qrImportResultLauncher = registerForActivityResult(ScanContract()) { result -> + val qrCode = result.contents + val activity = activity + if (qrCode != null && activity != null) { + activity.lifecycleScope.launch { TunnelImporter.importTunnel(parentFragmentManager, qrCode) { showSnackbar(it) } } + } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -89,11 +90,10 @@ class TunnelListFragment : BaseFragment() { tunnelFileImportResultLauncher.launch("*/*") } AddTunnelsSheet.REQUEST_SCAN -> { - qrImportResultLauncher.launch(IntentIntegrator(requireActivity()) + qrImportResultLauncher.launch(ScanOptions() .setOrientationLocked(false) .setBeepEnabled(false) - .setPrompt(getString(R.string.qr_code_hint)) - .createScanIntent()) + .setPrompt(getString(R.string.qr_code_hint))) } } } -- cgit v1.2.3