Skip to content

Commit fae74dd

Browse files
committed
ui: upgrade zxing-android-embedded
Signed-off-by: Harsh Shandilya <[email protected]>
1 parent e462ae2 commit fae74dd

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ buildscript {
1717
lifecycleRuntimeKtxVersion = '2.3.1'
1818
materialComponentsVersion = '1.4.0'
1919
preferenceVersion = '1.1.1'
20-
zxingEmbeddedVersion = '4.2.0'
20+
zxingEmbeddedVersion = '4.3.0'
2121

2222
groupName = 'com.wireguard.android'
2323
}

ui/src/main/AndroidManifest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
android:label="@string/permission_label"
3030
android:protectionLevel="dangerous" />
3131

32-
<!-- This is safe to override, the APIs we use work perfectly fine on Android 6 -->
33-
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
34-
3532
<application
3633
android:name=".Application"
3734
android:allowBackup="false"

ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import androidx.appcompat.app.AppCompatActivity
2121
import androidx.appcompat.view.ActionMode
2222
import androidx.lifecycle.lifecycleScope
2323
import com.google.android.material.snackbar.Snackbar
24-
import com.google.zxing.integration.android.IntentIntegrator
24+
import com.journeyapps.barcodescanner.ScanContract
25+
import com.journeyapps.barcodescanner.ScanOptions
2526
import com.wireguard.android.Application
2627
import com.wireguard.android.R
2728
import com.wireguard.android.activity.TunnelCreatorActivity
@@ -55,12 +56,12 @@ class TunnelListFragment : BaseFragment() {
5556
}
5657
}
5758

58-
private val qrImportResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
59-
val qrCode = IntentIntegrator.parseActivityResult(result.resultCode, result.data)?.contents
60-
?: return@registerForActivityResult
61-
val activity = activity ?: return@registerForActivityResult
62-
val fragManager = parentFragmentManager
63-
activity.lifecycleScope.launch { TunnelImporter.importTunnel(fragManager, qrCode) { showSnackbar(it) } }
59+
private val qrImportResultLauncher = registerForActivityResult(ScanContract()) { result ->
60+
val qrCode = result.contents
61+
val activity = activity
62+
if (qrCode != null && activity != null) {
63+
activity.lifecycleScope.launch { TunnelImporter.importTunnel(parentFragmentManager, qrCode) { showSnackbar(it) } }
64+
}
6465
}
6566

6667
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -89,11 +90,10 @@ class TunnelListFragment : BaseFragment() {
8990
tunnelFileImportResultLauncher.launch("*/*")
9091
}
9192
AddTunnelsSheet.REQUEST_SCAN -> {
92-
qrImportResultLauncher.launch(IntentIntegrator(requireActivity())
93+
qrImportResultLauncher.launch(ScanOptions()
9394
.setOrientationLocked(false)
9495
.setBeepEnabled(false)
95-
.setPrompt(getString(R.string.qr_code_hint))
96-
.createScanIntent())
96+
.setPrompt(getString(R.string.qr_code_hint)))
9797
}
9898
}
9999
}

0 commit comments

Comments
 (0)