diff options
Diffstat (limited to 'app/src/main/java')
18 files changed, 323 insertions, 157 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt index 274e1ba..000320c 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt | |||
@@ -1,5 +1,6 @@ | |||
1 | package org.pacien.tincapp.activities | 1 | package org.pacien.tincapp.activities |
2 | 2 | ||
3 | import android.app.ProgressDialog | ||
3 | import android.content.Intent | 4 | import android.content.Intent |
4 | import android.net.Uri | 5 | import android.net.Uri |
5 | import android.os.Bundle | 6 | import android.os.Bundle |
@@ -38,12 +39,18 @@ abstract class BaseActivity : AppCompatActivity() { | |||
38 | resources.getString(R.string.app_license) + "\n\n" + | 39 | resources.getString(R.string.app_license) + "\n\n" + |
39 | AppInfo.all()) | 40 | AppInfo.all()) |
40 | .setNeutralButton(R.string.action_open_project_website) { _, _ -> openWebsite(R.string.app_website_url) } | 41 | .setNeutralButton(R.string.action_open_project_website) { _, _ -> openWebsite(R.string.app_website_url) } |
41 | .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ } | 42 | .setPositiveButton(R.string.action_close, dismiss) |
42 | .show() | 43 | .show() |
43 | } | 44 | } |
44 | 45 | ||
45 | protected fun openWebsite(@StringRes url: Int) = startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(resources.getString(url)))) | 46 | protected fun openWebsite(@StringRes url: Int) = startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(resources.getString(url)))) |
46 | protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | 47 | protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() |
47 | protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | 48 | protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() |
49 | protected fun showProgressDialog(@StringRes msg: Int): ProgressDialog = ProgressDialog.show(this, null, getString(msg), true, false) | ||
50 | protected fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this) | ||
51 | .setTitle(R.string.title_error).setMessage(msg) | ||
52 | .setPositiveButton(R.string.action_close, dismiss).show() | ||
53 | |||
54 | protected val dismiss = { _: Any, _: Any -> /* nop */ } | ||
48 | 55 | ||
49 | } | 56 | } |
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 3590f99..d11809c 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt | |||
@@ -1,11 +1,20 @@ | |||
1 | package org.pacien.tincapp.activities | 1 | package org.pacien.tincapp.activities |
2 | 2 | ||
3 | import android.os.Bundle | 3 | import android.os.Bundle |
4 | import android.support.annotation.StringRes | ||
5 | import android.support.v7.app.AlertDialog | ||
4 | import android.view.View | 6 | 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 | ||
5 | import kotlinx.android.synthetic.main.base.* | 11 | import kotlinx.android.synthetic.main.base.* |
6 | import kotlinx.android.synthetic.main.page_configure.* | 12 | import kotlinx.android.synthetic.main.page_configure.* |
7 | import org.pacien.tincapp.R | 13 | import org.pacien.tincapp.R |
14 | import org.pacien.tincapp.commands.Tinc | ||
15 | import org.pacien.tincapp.commands.TincApp | ||
8 | import org.pacien.tincapp.context.AppPaths | 16 | import org.pacien.tincapp.context.AppPaths |
17 | import org.pacien.tincapp.extensions.Java.exceptionallyAccept | ||
9 | 18 | ||
10 | /** | 19 | /** |
11 | * @author pacien | 20 | * @author pacien |
@@ -19,13 +28,61 @@ class ConfigureActivity : BaseActivity() { | |||
19 | writeContent() | 28 | writeContent() |
20 | } | 29 | } |
21 | 30 | ||
31 | fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { | ||
32 | val netNameField = EditText(this) | ||
33 | netNameField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) | ||
34 | netNameField.setHint(R.string.field_net_name) | ||
35 | |||
36 | val dialogFrame = layoutInflater.inflate(R.layout.dialog_frame, main_content, false) as ViewGroup | ||
37 | dialogFrame.addView(netNameField) | ||
38 | |||
39 | AlertDialog.Builder(this).setTitle(R.string.title_new_network).setView(dialogFrame) | ||
40 | .setPositiveButton(R.string.action_create) { _, _ -> generateConf(netNameField.text.toString()) } | ||
41 | .setNegativeButton(R.string.action_cancel, dismiss).show() | ||
42 | } | ||
43 | |||
44 | fun openJoinNetworkDialog(@Suppress("UNUSED_PARAMETER") v: View) { | ||
45 | val netNameField = EditText(this) | ||
46 | netNameField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) | ||
47 | netNameField.setHint(R.string.field_net_name) | ||
48 | |||
49 | val joinUrlField = EditText(this) | ||
50 | joinUrlField.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) | ||
51 | joinUrlField.setHint(R.string.field_invitation_url) | ||
52 | |||
53 | val dialogFrame = layoutInflater.inflate(R.layout.dialog_frame, main_content, false) as ViewGroup | ||
54 | dialogFrame.addView(netNameField) | ||
55 | dialogFrame.addView(joinUrlField) | ||
56 | |||
57 | AlertDialog.Builder(this).setTitle(R.string.title_join_network).setView(dialogFrame) | ||
58 | .setPositiveButton(R.string.action_join) { _, _ -> joinNetwork(netNameField.text.toString(), joinUrlField.text.toString()) } | ||
59 | .setNegativeButton(R.string.action_cancel, dismiss).show() | ||
60 | } | ||
61 | |||
22 | private fun writeContent() { | 62 | private fun writeContent() { |
23 | text_configuration_directory.text = AppPaths.confDir().absolutePath | 63 | text_configuration_directory.text = AppPaths.confDir().absolutePath |
24 | text_log_directory.text = AppPaths.cacheDir().absolutePath | 64 | text_log_directory.text = AppPaths.cacheDir().absolutePath |
25 | text_tinc_binary.text = AppPaths.tinc().absolutePath | 65 | text_tinc_binary.text = AppPaths.tinc().absolutePath |
26 | } | 66 | } |
27 | 67 | ||
28 | fun generateConf(@Suppress("UNUSED_PARAMETER") v: View) = notify("Not implemented yet") | 68 | private fun generateConf(netName: String) = execAction( |
29 | fun joinNetwork(@Suppress("UNUSED_PARAMETER") v: View) = notify("Not implemented yet") | 69 | R.string.message_generating_configuration, |
70 | Tinc.init(netName) | ||
71 | .thenCompose { TincApp.removeScripts(netName) }) | ||
72 | |||
73 | private fun joinNetwork(netName: String, url: String) = execAction( | ||
74 | R.string.message_joining_network, | ||
75 | Tinc.join(netName, url) | ||
76 | .thenCompose { TincApp.removeScripts(netName) } | ||
77 | .thenCompose { TincApp.generateIfaceCfg(netName) }) | ||
78 | |||
79 | private fun execAction(@StringRes label: Int, action: CompletableFuture<Void>) { | ||
80 | showProgressDialog(label).let { progressDialog -> | ||
81 | action | ||
82 | .whenComplete { _, _ -> progressDialog.dismiss() } | ||
83 | .thenAccept { notify(R.string.message_network_configuration_created) } | ||
84 | .exceptionallyAccept { runOnUiThread { showErrorDialog(it.cause!!.localizedMessage) } } | ||
85 | } | ||
86 | } | ||
30 | 87 | ||
31 | } | 88 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt index cecd474..6bd845d 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt | |||
@@ -13,9 +13,9 @@ import kotlinx.android.synthetic.main.base.* | |||
13 | import kotlinx.android.synthetic.main.page_start.* | 13 | import kotlinx.android.synthetic.main.page_start.* |
14 | import org.pacien.tincapp.R | 14 | import org.pacien.tincapp.R |
15 | import org.pacien.tincapp.context.AppPaths | 15 | import org.pacien.tincapp.context.AppPaths |
16 | import org.pacien.tincapp.extensions.Android.setElements | ||
16 | import org.pacien.tincapp.service.TincVpnService | 17 | import org.pacien.tincapp.service.TincVpnService |
17 | import org.pacien.tincapp.utils.FileObserver | 18 | import org.pacien.tincapp.utils.FileObserver |
18 | import org.pacien.tincapp.utils.setElements | ||
19 | 19 | ||
20 | /** | 20 | /** |
21 | * @author pacien | 21 | * @author pacien |
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 fb6ab73..a2c39dd 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt | |||
@@ -17,10 +17,10 @@ import kotlinx.android.synthetic.main.fragment_network_status_header.* | |||
17 | import kotlinx.android.synthetic.main.page_status.* | 17 | import kotlinx.android.synthetic.main.page_status.* |
18 | import org.pacien.tincapp.R | 18 | import org.pacien.tincapp.R |
19 | import org.pacien.tincapp.commands.Tinc | 19 | import org.pacien.tincapp.commands.Tinc |
20 | import org.pacien.tincapp.data.VpnInterfaceConfiguration | ||
21 | import org.pacien.tincapp.extensions.Android.setElements | ||
22 | import org.pacien.tincapp.extensions.Android.setText | ||
20 | import org.pacien.tincapp.service.TincVpnService | 23 | import org.pacien.tincapp.service.TincVpnService |
21 | import org.pacien.tincapp.service.VpnInterfaceConfiguration | ||
22 | import org.pacien.tincapp.utils.setElements | ||
23 | import org.pacien.tincapp.utils.setText | ||
24 | import java.util.* | 24 | import java.util.* |
25 | import kotlin.concurrent.timerTask | 25 | import kotlin.concurrent.timerTask |
26 | 26 | ||
@@ -105,8 +105,8 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef | |||
105 |