diff options
-rw-r--r-- | ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt | 4 | ||||
-rw-r--r-- | ui/src/main/java/com/wireguard/android/util/QrCodeFromFileScanner.kt | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt index 7b196ce8..390a6396 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt @@ -54,9 +54,9 @@ class TunnelListFragment : BaseFragment() { val activity = activity ?: return@registerForActivityResult val contentResolver = activity.contentResolver ?: return@registerForActivityResult activity.lifecycleScope.launch { - val qrCodeFromFileScanner = QrCodeFromFileScanner(contentResolver, QRCodeReader()) - if (qrCodeFromFileScanner.validContentType(data)) { + if (QrCodeFromFileScanner.validContentType(contentResolver, data)) { try { + val qrCodeFromFileScanner = QrCodeFromFileScanner(contentResolver, QRCodeReader()) val result = qrCodeFromFileScanner.scan(data) TunnelImporter.importTunnel(parentFragmentManager, result.text) { showSnackbar(it) } } catch (e: Exception) { diff --git a/ui/src/main/java/com/wireguard/android/util/QrCodeFromFileScanner.kt b/ui/src/main/java/com/wireguard/android/util/QrCodeFromFileScanner.kt index 5d1007e4..3e54a52a 100644 --- a/ui/src/main/java/com/wireguard/android/util/QrCodeFromFileScanner.kt +++ b/ui/src/main/java/com/wireguard/android/util/QrCodeFromFileScanner.kt @@ -96,15 +96,15 @@ class QrCodeFromFileScanner( */ suspend fun scan(data: Uri) = withContext(Dispatchers.Default) { doScan(data) } - /** - * Given a reference to a file, check if this file could be parsed by this class - * @return true if the file can be parsed, false if not - */ - fun validContentType(data: Uri): Boolean { - return contentResolver.getType(data)?.startsWith("image/") == true - } - companion object { private const val TAG = "QrCodeFromFileScanner" + + /** + * Given a reference to a file, check if this file could be parsed by this class + * @return true if the file can be parsed, false if not + */ + fun validContentType(contentResolver: ContentResolver, data: Uri): Boolean { + return contentResolver.getType(data)?.startsWith("image/") == true + } } } |