diff options
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt | 23 |
1 files changed, 7 insertions, 16 deletions
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 @@ | |||
1 | package org.pacien.tincapp.activities | 1 | package org.pacien.tincapp.activities |
2 | 2 | ||
3 | import android.app.Activity | ||
4 | import android.content.ActivityNotFoundException | ||
5 | import android.content.Intent | 3 | import android.content.Intent |
6 | import android.net.Uri | ||
7 | import android.os.Bundle | 4 | import android.os.Bundle |
8 | import android.support.annotation.StringRes | 5 | import android.support.annotation.StringRes |
9 | import android.support.v7.app.AlertDialog | 6 | import android.support.v7.app.AlertDialog |
10 | import android.view.View | 7 | import android.view.View |
8 | import com.google.zxing.integration.android.IntentIntegrator | ||
9 | import com.google.zxing.integration.android.IntentResult | ||
11 | import java8.util.concurrent.CompletableFuture | 10 | import java8.util.concurrent.CompletableFuture |
12 | import kotlinx.android.synthetic.main.base.* | 11 | import kotlinx.android.synthetic.main.base.* |
13 | import kotlinx.android.synthetic.main.dialog_encrypt_decrypt_keys.view.* | 12 | import kotlinx.android.synthetic.main.dialog_encrypt_decrypt_keys.view.* |
@@ -26,8 +25,6 @@ import java.util.regex.Pattern | |||
26 | */ | 25 | */ |
27 | class ConfigureActivity : BaseActivity() { | 26 | class ConfigureActivity : BaseActivity() { |
28 | companion object { | 27 | companion object { |
29 | private const val REQUEST_SCAN = 0 | ||
30 | private const val SCAN_PROVIDER = "com.google.zxing.client.android" | ||
31 | private val NETWORK_NAME_PATTERN = Pattern.compile("^[^\\x00/]*$") | 28 | private val NETWORK_NAME_PATTERN = Pattern.compile("^[^\\x00/]*$") |
32 | } | 29 | } |
33 | 30 | ||
@@ -36,8 +33,10 @@ class ConfigureActivity : BaseActivity() { | |||
36 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | 33 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
37 | super.onActivityResult(requestCode, resultCode, data) | 34 | super.onActivityResult(requestCode, resultCode, data) |
38 | 35 | ||
39 | if (requestCode == REQUEST_SCAN && resultCode == Activity.RESULT_OK) | 36 | IntentIntegrator.parseActivityResult(requestCode, resultCode, data) |
40 | joinDialog?.invitation_url?.setText(data!!.getStringExtra("SCAN_RESULT").trim()) | 37 | ?.let(IntentResult::getContents) |
38 | ?.let(String::trim) | ||
39 | ?.let { joinDialog?.invitation_url?.setText(it) } | ||
41 | } | 40 | } |
42 | 41 | ||
43 | override fun onCreate(savedInstanceState: Bundle?) { | 42 | override fun onCreate(savedInstanceState: Bundle?) { |
@@ -48,15 +47,7 @@ class ConfigureActivity : BaseActivity() { | |||
48 | } | 47 | } |
49 | 48 | ||
50 | fun scanCode(@Suppress("UNUSED_PARAMETER") v: View) { | 49 | fun scanCode(@Suppress("UNUSED_PARAMETER") v: View) { |
51 | try { | 50 | IntentIntegrator(this).initiateScan() |
52 | startActivityForResult(Intent("$SCAN_PROVIDER.SCAN"), REQUEST_SCAN) | ||
53 | } catch (e: ActivityNotFoundException) { | ||
54 | AlertDialog.Builder(this).setTitle(R.string.action_scan_qr_code) | ||
55 | .setMessage(R.string.message_no_qr_code_scanner) | ||
56 | .setPositiveButton(R.string.action_install) { _, _ -> | ||
57 | startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$SCAN_PROVIDER"))) | ||
58 | }.setNegativeButton(R.string.action_cancel, { _, _ -> Unit }).show() | ||
59 | } | ||
60 | } | 51 | } |
61 | 52 | ||
62 | fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { | 53 | fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { |