summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-03-06 21:40:13 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2022-03-06 10:48:15 -0700
commit70d9a87d0d73d92f20c45f84361630b72435840f (patch)
tree25c4189e127349e09b73061f786963191c6c24aa /ui/src/main/java
parent0bd39309c8ba839191684d5d34c247c0af7b42aa (diff)
ui: make validity check from QR code image scanner static
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'ui/src/main/java')
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt4
-rw-r--r--ui/src/main/java/com/wireguard/android/util/QrCodeFromFileScanner.kt16
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
+ }
}
}