From a2ffefc02bdcbab6fc8f13f30585eb43aab2d078 Mon Sep 17 00:00:00 2001
From: pacien
Date: Sun, 10 Jun 2018 23:47:57 +0200
Subject: Better qr-code scanner integration
---
.../pacien/tincapp/activities/ConfigureActivity.kt | 23 +++++++---------------
app/src/main/res/values-zh-rCN/strings.xml | 1 -
app/src/main/res/values-zh-rHK/strings.xml | 1 -
app/src/main/res/values-zh-rTW/strings.xml | 1 -
app/src/main/res/values/strings.xml | 1 -
5 files changed, 7 insertions(+), 20 deletions(-)
(limited to 'app/src/main')
diff --git a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
index e311415..5f6a3fe 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
@@ -1,13 +1,12 @@
package org.pacien.tincapp.activities
-import android.app.Activity
-import android.content.ActivityNotFoundException
import android.content.Intent
-import android.net.Uri
import android.os.Bundle
import android.support.annotation.StringRes
import android.support.v7.app.AlertDialog
import android.view.View
+import com.google.zxing.integration.android.IntentIntegrator
+import com.google.zxing.integration.android.IntentResult
import java8.util.concurrent.CompletableFuture
import kotlinx.android.synthetic.main.base.*
import kotlinx.android.synthetic.main.dialog_encrypt_decrypt_keys.view.*
@@ -26,8 +25,6 @@ import java.util.regex.Pattern
*/
class ConfigureActivity : BaseActivity() {
companion object {
- private const val REQUEST_SCAN = 0
- private const val SCAN_PROVIDER = "com.google.zxing.client.android"
private val NETWORK_NAME_PATTERN = Pattern.compile("^[^\\x00/]*$")
}
@@ -36,8 +33,10 @@ class ConfigureActivity : BaseActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
- if (requestCode == REQUEST_SCAN && resultCode == Activity.RESULT_OK)
- joinDialog?.invitation_url?.setText(data!!.getStringExtra("SCAN_RESULT").trim())
+ IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
+ ?.let(IntentResult::getContents)
+ ?.let(String::trim)
+ ?.let { joinDialog?.invitation_url?.setText(it) }
}
override fun onCreate(savedInstanceState: Bundle?) {
@@ -48,15 +47,7 @@ class ConfigureActivity : BaseActivity() {
}
fun scanCode(@Suppress("UNUSED_PARAMETER") v: View) {
- try {
- startActivityForResult(Intent("$SCAN_PROVIDER.SCAN"), REQUEST_SCAN)
- } catch (e: ActivityNotFoundException) {
- AlertDialog.Builder(this).setTitle(R.string.action_scan_qr_code)
- .setMessage(R.string.message_no_qr_code_scanner)
- .setPositiveButton(R.string.action_install) { _, _ ->
- startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$SCAN_PROVIDER")))
- }.setNegativeButton(R.string.action_cancel, { _, _ -> Unit }).show()
- }
+ IntentIntegrator(this).initiateScan()
}
fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) {
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index ce0a854..5feb75d 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -70,7 +70,6 @@
没有找到网络“%1$s”的配置。
在“%1$s”找不到网络配置文件。
network.conf 中的网络配置无效:\n\n%1$s
- 无法启动扫描器。\n\n安装 Barcode Scanner?
加密/解密私钥
无法解密私钥:\n\n%1$s
diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml
index 6879117..dfc27fe 100644
--- a/app/src/main/res/values-zh-rHK/strings.xml
+++ b/app/src/main/res/values-zh-rHK/strings.xml
@@ -70,7 +70,6 @@
沒有找到網絡“%1$s”的配置。
在“%1$s”找不到網絡配置文件。
network.conf 中的網絡配置無效:\n\n%1$s
- 無法啟動掃描器。\n\n安裝 Barcode Scanner?
加密/解密私鑰
無法解密私鑰:\n\n%1$s
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 3c9927f..c553138 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -70,7 +70,6 @@
沒有找到網路“%1$s”的配置。
在“%1$s”找不到網路配置檔案。
network.conf 中的網路配置無效:\n\n%1$s
- 無法啟動掃描器。\n\n安裝 Barcode Scanner?
加密/解密私鑰
無法解密私鑰:\n\n%1$s
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6ac776f..ba0233d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -79,7 +79,6 @@
No configuration has been found for network \"%1$s\".
Network configuration file not found at \"%1$s\".
Invalid network configuration in network.conf:\n\n%1$s
- No scanner could be started.\n\nInstall Barcode Scanner?
Encrypting/decrypting private keys
Could not decrypt private keys:\n\n%1$s
Storage directory is unavailable.
--
cgit v1.2.3