From cf24442cd7b18ffd7dfe3998ea40d8e5e1d3f16e Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 24 Aug 2017 15:54:31 +0200 Subject: Add invitation URL QR code scanning ; Refactor configuration dialogs --- .../pacien/tincapp/activities/ConfigureActivity.kt | 75 ++++++++++++---------- .../pacien/tincapp/activities/StatusActivity.kt | 10 +-- .../res/drawable/ic_photo_camera_primary_24dp.xml | 12 ++++ app/src/main/res/layout/dialog_frame.xml | 10 --- .../main/res/layout/dialog_network_generate.xml | 22 +++++++ app/src/main/res/layout/dialog_network_join.xml | 37 +++++++++++ app/src/main/res/layout/dialog_node_details.xml | 15 +++++ app/src/main/res/layout/dialog_text_monopsace.xml | 15 ----- app/src/main/res/values/strings.xml | 3 + 9 files changed, 136 insertions(+), 63 deletions(-) create mode 100644 app/src/main/res/drawable/ic_photo_camera_primary_24dp.xml delete mode 100644 app/src/main/res/layout/dialog_frame.xml create mode 100644 app/src/main/res/layout/dialog_network_generate.xml create mode 100644 app/src/main/res/layout/dialog_network_join.xml create mode 100644 app/src/main/res/layout/dialog_node_details.xml delete mode 100644 app/src/main/res/layout/dialog_text_monopsace.xml (limited to 'app') 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 ea37944..9027b14 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt @@ -1,14 +1,17 @@ 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 android.view.ViewGroup -import android.widget.EditText -import android.widget.FrameLayout import java8.util.concurrent.CompletableFuture import kotlinx.android.synthetic.main.base.* +import kotlinx.android.synthetic.main.dialog_network_generate.view.* +import kotlinx.android.synthetic.main.dialog_network_join.view.* import kotlinx.android.synthetic.main.page_configure.* import org.pacien.tincapp.R import org.pacien.tincapp.commands.Tinc @@ -22,6 +25,20 @@ import org.pacien.tincapp.extensions.Java.exceptionallyAccept */ class ConfigureActivity : BaseActivity() { + companion object { + val REQUEST_SCAN = 0 + val SCAN_PROVIDER = "com.google.zxing.client.android" + } + + private var joinDialog: View? = null + + 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()) + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) supportActionBar!!.setDisplayHomeAsUpEnabled(true) @@ -29,40 +46,32 @@ class ConfigureActivity : BaseActivity() { writeContent() } - fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { - val netNameField = EditText(this) - netNameField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) - netNameField.setHint(R.string.field_net_name) - - val nodeNameField = EditText(this) - nodeNameField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) - nodeNameField.setHint(R.string.field_node_name) - - val dialogFrame = layoutInflater.inflate(R.layout.dialog_frame, main_content, false) as ViewGroup - dialogFrame.addView(netNameField) - dialogFrame.addView(nodeNameField) + 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, App.dismissAction).show() + } + } - AlertDialog.Builder(this).setTitle(R.string.title_new_network).setView(dialogFrame) - .setPositiveButton(R.string.action_create) { _, _ -> generateConf(netNameField.text.toString(), nodeNameField.text.toString()) } - .setNegativeButton(R.string.action_cancel, App.dismissAction).show() + fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { + val genDialog = layoutInflater.inflate(R.layout.dialog_network_generate, main_content, false) + AlertDialog.Builder(this).setTitle(R.string.title_new_network).setView(genDialog) + .setPositiveButton(R.string.action_create) { _, _ -> + generateConf(genDialog.new_net_name.text.toString(), genDialog.new_node_name.text.toString()) + }.setNegativeButton(R.string.action_cancel, App.dismissAction).show() } fun openJoinNetworkDialog(@Suppress("UNUSED_PARAMETER") v: View) { - val netNameField = EditText(this) - netNameField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) - netNameField.setHint(R.string.field_net_name) - - val joinUrlField = EditText(this) - joinUrlField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) - joinUrlField.setHint(R.string.field_invitation_url) - - val dialogFrame = layoutInflater.inflate(R.layout.dialog_frame, main_content, false) as ViewGroup - dialogFrame.addView(netNameField) - dialogFrame.addView(joinUrlField) - - AlertDialog.Builder(this).setTitle(R.string.title_join_network).setView(dialogFrame) - .setPositiveButton(R.string.action_join) { _, _ -> joinNetwork(netNameField.text.toString(), joinUrlField.text.toString()) } - .setNegativeButton(R.string.action_cancel, App.dismissAction).show() + joinDialog = layoutInflater.inflate(R.layout.dialog_network_join, main_content, false) + AlertDialog.Builder(this).setTitle(R.string.title_join_network).setView(joinDialog) + .setPositiveButton(R.string.action_join) { _, _ -> + joinNetwork(joinDialog!!.net_name.text.toString(), joinDialog!!.invitation_url.text.toString()) + }.setNegativeButton(R.string.action_cancel, App.dismissAction).show() } private fun writeContent() { diff --git a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt index 6d97dca..356ff6e 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt @@ -12,7 +12,7 @@ import android.widget.ArrayAdapter import android.widget.TextView import java8.util.concurrent.CompletableFuture import kotlinx.android.synthetic.main.base.* -import kotlinx.android.synthetic.main.dialog_text_monopsace.view.* +import kotlinx.android.synthetic.main.dialog_node_details.view.* import kotlinx.android.synthetic.main.fragment_list_view.* import kotlinx.android.synthetic.main.fragment_network_status_header.* import org.pacien.tincapp.R @@ -36,7 +36,7 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - nodeListAdapter = ArrayAdapter(this, R.layout.fragment_list_item) + nodeListAdapter = ArrayAdapter(this, R.layout.fragment_list_item) refreshTimer = Timer(true) layoutInflater.inflate(R.layout.fragment_list_view, main_content) @@ -81,7 +81,7 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef getNodeNames().thenAccept { runOnUiThread { nodeListAdapter?.setElements(it) - node_list_placeholder.visibility = if (nodeListAdapter?.isEmpty ?: true) View.VISIBLE else View.GONE + node_list_placeholder.visibility = if (nodeListAdapter?.isEmpty != false) View.VISIBLE else View.GONE list_wrapper.isRefreshing = false if (!TincVpnService.isConnected()) openStartActivity() } @@ -90,10 +90,10 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { val nodeName = (view as TextView).text.toString() - val dialogTextView = layoutInflater.inflate(R.layout.dialog_text_monopsace, main_content, false) + val dialogTextView = layoutInflater.inflate(R.layout.dialog_node_details, main_content, false) Tinc.info(TincVpnService.getCurrentNetName()!!, nodeName).thenAccept { runOnUiThread { - dialogTextView.dialog_text_monospace.text = it + dialogTextView.dialog_node_details.text = it AlertDialog.Builder(this) .setTitle(R.string.title_node_info) .setView(dialogTextView) diff --git a/app/src/main/res/drawable/ic_photo_camera_primary_24dp.xml b/app/src/main/res/drawable/ic_photo_camera_primary_24dp.xml new file mode 100644 index 0000000..28172b6 --- /dev/null +++ b/app/src/main/res/drawable/ic_photo_camera_primary_24dp.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/dialog_frame.xml b/app/src/main/res/layout/dialog_frame.xml deleted file mode 100644 index 9b4a512..0000000 --- a/app/src/main/res/layout/dialog_frame.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/layout/dialog_network_generate.xml b/app/src/main/res/layout/dialog_network_generate.xml new file mode 100644 index 0000000..cc51b7b --- /dev/null +++ b/app/src/main/res/layout/dialog_network_generate.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/app/src/main/res/layout/dialog_network_join.xml b/app/src/main/res/layout/dialog_network_join.xml new file mode 100644 index 0000000..2d23d4b --- /dev/null +++ b/app/src/main/res/layout/dialog_network_join.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/dialog_node_details.xml b/app/src/main/res/layout/dialog_node_details.xml new file mode 100644 index 0000000..dc2aae9 --- /dev/null +++ b/app/src/main/res/layout/dialog_node_details.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/dialog_text_monopsace.xml b/app/src/main/res/layout/dialog_text_monopsace.xml deleted file mode 100644 index b7f6f5b..0000000 --- a/app/src/main/res/layout/dialog_text_monopsace.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 70a13da..c909933 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -50,6 +50,8 @@ Create Join Open manual + Scan QR code + Install No network configuration has been found. No known node @@ -60,6 +62,7 @@ No configuration has been found for network \"%1$s\". Network configuration file not found at \"%1$s\". Invalid network configuration:\n\n%1$s + No scanner could be started.\n\nInstall Barcode Scanner? none yes -- cgit v1.2.3