diff options
Diffstat (limited to 'app/src/main/java/org/pacien')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt | 75 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt | 10 |
2 files changed, 47 insertions, 38 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 @@ | |||
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 | ||
6 | import android.net.Uri | ||
3 | import android.os.Bundle | 7 | import android.os.Bundle |
4 | import android.support.annotation.StringRes | 8 | import android.support.annotation.StringRes |
5 | import android.support.v7.app.AlertDialog | 9 | import android.support.v7.app.AlertDialog |
6 | import android.view.View | 10 | import android.view.View |
7 | import android.view.ViewGroup | ||
8 | import android.widget.EditText | ||
9 | import android.widget.FrameLayout | ||
10 | import java8.util.concurrent.CompletableFuture | 11 | import java8.util.concurrent.CompletableFuture |
11 | import kotlinx.android.synthetic.main.base.* | 12 | import kotlinx.android.synthetic.main.base.* |
13 | import kotlinx.android.synthetic.main.dialog_network_generate.view.* | ||
14 | import kotlinx.android.synthetic.main.dialog_network_join.view.* | ||
12 | import kotlinx.android.synthetic.main.page_configure.* | 15 | import kotlinx.android.synthetic.main.page_configure.* |
13 | import org.pacien.tincapp.R | 16 | import org.pacien.tincapp.R |
14 | import org.pacien.tincapp.commands.Tinc | 17 | import org.pacien.tincapp.commands.Tinc |
@@ -22,6 +25,20 @@ import org.pacien.tincapp.extensions.Java.exceptionallyAccept | |||
22 | */ | 25 | */ |
23 | class ConfigureActivity : BaseActivity() { | 26 | class 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 | |||
12 | import android.widget.TextView | 12 | import android.widget.TextView |
13 | import java8.util.concurrent.CompletableFuture | 13 | import java8.util.concurrent.CompletableFuture |
14 | import kotlinx.android.synthetic.main.base.* | 14 | import kotlinx.android.synthetic.main.base.* |
15 | import kotlinx.android.synthetic.main.dialog_text_monopsace.view.* | 15 | import kotlinx.android.synthetic.main.dialog_node_details.view.* |
16 | import kotlinx.android.synthetic.main.fragment_list_view.* | 16 | import kotlinx.android.synthetic.main.fragment_list_view.* |
17 | import kotlinx.android.synthetic.main.fragment_network_status_header.* | 17 | import kotlinx.android.synthetic.main.fragment_network_status_header.* |
18 | import org.pacien.tincapp.R | 18 | import 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) |