aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorpacien2017-08-24 15:54:31 +0200
committerpacien2017-08-24 16:32:10 +0200
commitcf24442cd7b18ffd7dfe3998ea40d8e5e1d3f16e (patch)
treef215f87f6b9288ce77bab937570e75cb15e29f2e /app/src/main
parent5bd162da8412d637869b62fe0631106015a11bec (diff)
downloadtincapp-cf24442cd7b18ffd7dfe3998ea40d8e5e1d3f16e.tar.gz
Add invitation URL QR code scanning ; Refactor configuration dialogs
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt75
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt10
-rw-r--r--app/src/main/res/drawable/ic_photo_camera_primary_24dp.xml12
-rw-r--r--app/src/main/res/layout/dialog_network_generate.xml (renamed from app/src/main/res/layout/dialog_frame.xml)12
-rw-r--r--app/src/main/res/layout/dialog_network_join.xml37
-rw-r--r--app/src/main/res/layout/dialog_node_details.xml (renamed from app/src/main/res/layout/dialog_text_monopsace.xml)2
-rw-r--r--app/src/main/res/values/strings.xml3
7 files changed, 112 insertions, 39 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 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 @@
1package org.pacien.tincapp.activities 1package org.pacien.tincapp.activities
2 2
3import android.app.Activity
4import android.content.ActivityNotFoundException
5import android.content.Intent
6import android.net.Uri
3import android.os.Bundle 7import android.os.Bundle
4import android.support.annotation.StringRes 8import android.support.annotation.StringRes
5import android.support.v7.app.AlertDialog 9import android.support.v7.app.AlertDialog
6import android.view.View 10import android.view.View
7import android.view.ViewGroup
8import android.widget.EditText
9import android.widget.FrameLayout
10import java8.util.concurrent.CompletableFuture 11import java8.util.concurrent.CompletableFuture
11import kotlinx.android.synthetic.main.base.* 12import kotlinx.android.synthetic.main.base.*
13import kotlinx.android.synthetic.main.dialog_network_generate.view.*
14import kotlinx.android.synthetic.main.dialog_network_join.view.*
12import kotlinx.android.synthetic.main.page_configure.* 15import kotlinx.android.synthetic.main.page_configure.*
13import org.pacien.tincapp.R 16import org.pacien.tincapp.R
14import org.pacien.tincapp.commands.Tinc 17import org.pacien.tincapp.commands.Tinc
@@ -22,6 +25,20 @@ import org.pacien.tincapp.extensions.Java.exceptionallyAccept
22 */ 25 */
23class ConfigureActivity : BaseActivity() { 26class ConfigureActivity : BaseActivity() {
24 27
28 companion object {
29 val REQUEST_SCAN = 0
30 val SCAN_PROVIDER = "com.google.zxing.client.android"
31 }
32
33 private var joinDialog: View? = null
34
35 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
36 super.onActivityResult(requestCode, resultCode, data)
37
38 if (requestCode == REQUEST_SCAN && resultCode == Activity.RESULT_OK)
39 joinDialog?.invitation_url?.setText(data!!.getStringExtra("SCAN_RESULT").trim())
40 }
41
25 override fun onCreate(savedInstanceState: Bundle?) { 42 override fun onCreate(savedInstanceState: Bundle?) {
26 super.onCreate(savedInstanceState) 43 super.onCreate(savedInstanceState)
27 supportActionBar!!.setDisplayHomeAsUpEnabled(true) 44 supportActionBar!!.setDisplayHomeAsUpEnabled(true)
@@ -29,40 +46,32 @@ class ConfigureActivity : BaseActivity() {
29 writeContent() 46 writeContent()
30 } 47 }
31 48
32 fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { 49 fun scanCode(@Suppress("UNUSED_PARAMETER") v: View) {
33 val netNameField = EditText(this) 50 try {
34 netNameField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) 51 startActivityForResult(Intent("$SCAN_PROVIDER.SCAN"), REQUEST_SCAN)
35 netNameField.setHint(R.string.field_net_name) 52 } catch (e: ActivityNotFoundException) {
36 53 AlertDialog.Builder(this).setTitle(R.string.action_scan_qr_code)
37 val nodeNameField = EditText(this) 54 .setMessage(R.string.message_no_qr_code_scanner)
38 nodeNameField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) 55 .setPositiveButton(R.string.action_install) { _, _ ->
39 nodeNameField.setHint(R.string.field_node_name) 56 startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$SCAN_PROVIDER")))
40 57 }.setNegativeButton(R.string.action_cancel, App.dismissAction).show()
41 val dialogFrame = layoutInflater.inflate(R.layout.dialog_frame, main_content, false) as ViewGroup 58 }
42 dialogFrame.addView(netNameField) 59 }
43 dialogFrame.addView(nodeNameField)
44 60
45 AlertDialog.Builder(this).setTitle(R.string.title_new_network).setView(dialogFrame) 61 fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) {
46 .setPositiveButton(R.string.action_create) { _, _ -> generateConf(netNameField.text.toString(), nodeNameField.text.toString()) } 62 val genDialog = layoutInflater.inflate(R.layout.dialog_network_generate, main_content, false)
47 .setNegativeButton(R.string.action_cancel, App.dismissAction).show() 63 AlertDialog.Builder(this).setTitle(R.string.title_new_network).setView(genDialog)
64 .setPositiveButton(R.string.action_create) { _, _ ->
65 generateConf(genDialog.new_net_name.text.toString(), genDialog.new_node_name.text.toString())
66 }.setNegativeButton(R.string.action_cancel, App.dismissAction).show()
48 } 67 }
49 68
50 fun openJoinNetworkDialog(@Suppress("UNUSED_PARAMETER") v: View) { 69 fun openJoinNetworkDialog(@Suppress("UNUSED_PARAMETER") v: View) {
51 val netNameField = EditText(this) 70 joinDialog = layoutInflater.inflate(R.layout.dialog_network_join, main_content, false)
52 netNameField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) 71 AlertDialog.Builder(this).setTitle(R.string.title_join_network).setView(joinDialog)
53 netNameField.setHint(R.string.field_net_name) 72 .setPositiveButton(R.string.action_join) { _, _ ->
54 73 joinNetwork(joinDialog!!.net_name.text.toString(), joinDialog!!.invitation_url.text.toString())
55 val joinUrlField = EditText(this) 74 }.setNegativeButton(R.string.action_cancel, App.dismissAction).show()
56 joinUrlField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
57 joinUrlField.setHint(R.string.field_invitation_url)
58
59 val dialogFrame = layoutInflater.inflate(R.layout.dialog_frame, main_content, false) as ViewGroup
60 dialogFrame.addView(netNameField)
61 dialogFrame.addView(joinUrlField)
62
63 AlertDialog.Builder(this).setTitle(R.string.title_join_network).setView(dialogFrame)
64 .setPositiveButton(R.string.action_join) { _, _ -> joinNetwork(netNameField.text.toString(), joinUrlField.text.toString()) }
65 .setNegativeButton(R.string.action_cancel, App.dismissAction).show()
66 } 75 }
67 76
68 private fun writeContent() { 77 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
12import android.widget.TextView 12import android.widget.TextView
13import java8.util.concurrent.CompletableFuture 13import java8.util.concurrent.CompletableFuture
14import kotlinx.android.synthetic.main.base.* 14import kotlinx.android.synthetic.main.base.*
15import kotlinx.android.synthetic.main.dialog_text_monopsace.view.* 15import kotlinx.android.synthetic.main.dialog_node_details.view.*
16import kotlinx.android.synthetic.main.fragment_list_view.* 16import kotlinx.android.synthetic.main.fragment_list_view.*
17import kotlinx.android.synthetic.main.fragment_network_status_header.* 17import kotlinx.android.synthetic.main.fragment_network_status_header.*
18import org.pacien.tincapp.R 18import org.pacien.tincapp.R
@@ -36,7 +36,7 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef
36 override fun onCreate(savedInstanceState: Bundle?) { 36 override fun onCreate(savedInstanceState: Bundle?) {
37 super.onCreate(savedInstanceState) 37 super.onCreate(savedInstanceState)
38 38
39 nodeListAdapter = ArrayAdapter<String>(this, R.layout.fragment_list_item) 39 nodeListAdapter = ArrayAdapter(this, R.layout.fragment_list_item)
40 refreshTimer = Timer(true) 40 refreshTimer = Timer(true)
41 41
42 layoutInflater.inflate(R.layout.fragment_list_view, main_content) 42 layoutInflater.inflate(R.layout.fragment_list_view, main_content)
@@ -81,7 +81,7 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef
81 getNodeNames().thenAccept { 81 getNodeNames().thenAccept {
82 runOnUiThread { 82 runOnUiThread {
83 nodeListAdapter?.setElements(it) 83 nodeListAdapter?.setElements(it)
84 node_list_placeholder.visibility = if (nodeListAdapter?.isEmpty ?: true) View.VISIBLE else View.GONE 84 node_list_placeholder.visibility = if (nodeListAdapter?.isEmpty != false) View.VISIBLE else View.GONE
85 list_wrapper.isRefreshing = false 85 list_wrapper.isRefreshing = false
86 if (!TincVpnService.isConnected()) openStartActivity() 86 if (!TincVpnService.isConnected()) openStartActivity()
87 } 87 }
@@ -90,10 +90,10 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef
90 90
91 override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { 91 override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
92 val nodeName = (view as TextView).text.toString() 92 val nodeName = (view as TextView).text.toString()
93 val dialogTextView = layoutInflater.inflate(R.layout.dialog_text_monopsace, main_content, false) 93 val dialogTextView = layoutInflater.inflate(R.layout.dialog_node_details, main_content, false)
94 Tinc.info(TincVpnService.getCurrentNetName()!!, nodeName).thenAccept { 94 Tinc.info(TincVpnService.getCurrentNetName()!!, nodeName).thenAccept {
95 runOnUiThread { 95 runOnUiThread {
96 dialogTextView.dialog_text_monospace.text = it 96 dialogTextView.dialog_node_details.text = it
97 AlertDialog.Builder(this) 97 AlertDialog.Builder(this)
98 .setTitle(R.string.title_node_info) 98 .setTitle(R.string.title_node_info)
99 .setView(dialogTextView) 99 .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 @@
1<vector xmlns:android="http://schemas.android.com/apk/res/android"
2 android:width="24dp"
3 android:height="24dp"
4 android:viewportHeight="24.0"
5 android:viewportWidth="24.0">
6 <path
7 android:fillColor="@color/textPrimary"
8 android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
9 <path
10 android:fillColor="@color/textPrimary"
11 android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
12