diff options
author | pacien | 2018-08-09 00:09:39 +0200 |
---|---|---|
committer | pacien | 2018-08-09 00:09:39 +0200 |
commit | 0a7f8f489625d90b8969f112d80059d6757d5e8d (patch) | |
tree | d256bd8fc25dbbcfa6ba900137ab752547338227 /app/src/main | |
parent | faad43be437d857ad35570abe334cc333a6df00e (diff) | |
download | tincapp-0a7f8f489625d90b8969f112d80059d6757d5e8d.tar.gz |
Refactor configuration activity
Diffstat (limited to 'app/src/main')
28 files changed, 787 insertions, 452 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 517097e..ed9ddf0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml | |||
@@ -49,7 +49,7 @@ | |||
49 | </activity> | 49 | </activity> |
50 | 50 | ||
51 | <activity | 51 | <activity |
52 | android:name=".activities.ConfigureActivity" | 52 | android:name=".activities.configure.ConfigureActivity" |
53 | android:configChanges="orientation|screenSize" | 53 | android:configChanges="orientation|screenSize" |
54 | android:parentActivityName=".activities.StartActivity"> | 54 | android:parentActivityName=".activities.StartActivity"> |
55 | </activity> | 55 | </activity> |
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 4dc2381..af71544 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt | |||
@@ -19,19 +19,18 @@ | |||
19 | package org.pacien.tincapp.activities | 19 | package org.pacien.tincapp.activities |
20 | 20 | ||
21 | import android.os.Bundle | 21 | import android.os.Bundle |
22 | import android.support.annotation.LayoutRes | ||
22 | import android.support.annotation.StringRes | 23 | import android.support.annotation.StringRes |
23 | import android.support.design.widget.Snackbar | 24 | import android.support.design.widget.Snackbar |
24 | import android.support.v7.app.AlertDialog | 25 | import android.support.v7.app.AlertDialog |
25 | import android.support.v7.app.AppCompatActivity | 26 | import android.support.v7.app.AppCompatActivity |
26 | import android.view.Menu | 27 | import android.view.* |
27 | import android.view.MenuItem | ||
28 | import kotlinx.android.synthetic.main.base.* | 28 | import kotlinx.android.synthetic.main.base.* |
29 | import org.pacien.tincapp.R | 29 | import org.pacien.tincapp.R |
30 | import org.pacien.tincapp.context.App | 30 | import org.pacien.tincapp.context.App |
31 | import org.pacien.tincapp.context.AppInfo | 31 | import org.pacien.tincapp.context.AppInfo |
32 | import org.pacien.tincapp.context.AppPaths | 32 | import org.pacien.tincapp.context.AppPaths |
33 | import org.pacien.tincapp.context.CrashRecorder | 33 | import org.pacien.tincapp.context.CrashRecorder |
34 | import org.pacien.tincapp.utils.ProgressModal | ||
35 | 34 | ||
36 | /** | 35 | /** |
37 | * @author pacien | 36 | * @author pacien |
@@ -105,10 +104,13 @@ abstract class BaseActivity : AppCompatActivity() { | |||
105 | .show() | 104 | .show() |
106 | } | 105 | } |
107 | 106 | ||
108 | protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | 107 | fun inflate(@LayoutRes layout: Int) = layoutInflater.inflate(layout, main_content, false)!! |
109 | protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | 108 | fun inflate(inflateFunc: (LayoutInflater, ViewGroup, Boolean) -> View) = inflateFunc(layoutInflater, main_content, false) |
110 | protected fun showProgressDialog(@StringRes msg: Int): AlertDialog = ProgressModal.show(this, getString(msg)) | 109 | |
111 | protected fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this) | 110 | fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() |
111 | fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | ||
112 | |||
113 | fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this) | ||
112 | .setTitle(R.string.title_error).setMessage(msg) | 114 | .setTitle(R.string.title_error).setMessage(msg) |
113 | .setPositiveButton(R.string.action_close) { _, _ -> Unit }.show() | 115 | .setPositiveButton(R.string.action_close) { _, _ -> Unit }.show() |
114 | } | 116 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt deleted file mode 100644 index 2aab304..0000000 --- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt +++ /dev/null | |||
@@ -1,145 +0,0 @@ | |||
1 | /* | ||
2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon | ||
3 | * Copyright (C) 2017-2018 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation, either version 3 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | package org.pacien.tincapp.activities | ||
20 | |||
21 | import android.content.Intent | ||
22 | import android.os.Bundle | ||
23 | import android.support.annotation.StringRes | ||
24 | import android.support.v7.app.AlertDialog | ||
25 | import android.view.View | ||
26 | import com.google.zxing.integration.android.IntentIntegrator | ||
27 | import com.google.zxing.integration.android.IntentResult | ||
28 | import java8.util.concurrent.CompletableFuture | ||
29 | import kotlinx.android.synthetic.main.base.* | ||
30 | import kotlinx.android.synthetic.main.dialog_encrypt_decrypt_keys.view.* | ||
31 | import kotlinx.android.synthetic.main.dialog_network_generate.view.* | ||
32 | import kotlinx.android.synthetic.main.dialog_network_join.view.* | ||
33 | import kotlinx.android.synthetic.main.page_configure.* | ||
34 | import org.pacien.tincapp.R | ||
35 | import org.pacien.tincapp.commands.Tinc | ||
36 | import org.pacien.tincapp.commands.TincApp | ||
37 | import org.pacien.tincapp.context.AppPaths | ||
38 | import org.pacien.tincapp.extensions.Java.exceptionallyAccept | ||
39 | import java.util.regex.Pattern | ||
40 | |||
41 | /** | ||
42 | * @author pacien | ||
43 | */ | ||
44 | class ConfigureActivity : BaseActivity() { | ||
45 | companion object { | ||
46 | private val NETWORK_NAME_PATTERN = Pattern.compile("^[^\\x00/]*$") | ||
47 | } | ||
48 | |||
49 | private var joinDialog: View? = null | ||
50 | |||
51 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
52 | super.onActivityResult(requestCode, resultCode, data) | ||
53 | |||
54 | IntentIntegrator.parseActivityResult(requestCode, resultCode, data) | ||
55 | ?.let(IntentResult::getContents) | ||
56 | ?.let(String::trim) | ||
57 | ?.let { joinDialog?.invitation_url?.setText(it) } | ||
58 | } | ||
59 | |||
60 | override fun onCreate(savedInstanceState: Bundle?) { | ||
61 | super.onCreate(savedInstanceState) | ||
62 | supportActionBar!!.setDisplayHomeAsUpEnabled(true) | ||
63 | layoutInflater.inflate(R.layout.page_configure, main_content) | ||
64 | writeContent() | ||
65 | } | ||
66 | |||
67 | fun scanCode(@Suppress("UNUSED_PARAMETER") v: View) { | ||
68 | IntentIntegrator(this).initiateScan() | ||
69 | } | ||
70 | |||
71 | fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { | ||
72 | val genDialog = layoutInflater.inflate(R.layout.dialog_network_generate, main_content, false) | ||
73 | AlertDialog.Builder(this).setTitle(R.string.title_new_network).setView(genDialog) | ||
74 | .setPositiveButton(R.string.action_create) { _, _ -> | ||
75 | generateConf( | ||
76 | genDialog.new_net_name.text.toString(), | ||
77 | genDialog.new_node_name.text.toString(), | ||
78 | genDialog.new_passphrase.text.toString()) | ||
79 | }.setNegativeButton(R.string.action_cancel) { _, _ -> Unit }.show() | ||
80 | } | ||
81 | |||
82 | fun openJoinNetworkDialog(@Suppress("UNUSED_PARAMETER") v: View) { | ||
83 | joinDialog = layoutInflater.inflate(R.layout.dialog_network_join, main_content, false) | ||
84 | AlertDialog.Builder(this).setTitle(R.string.title_join_network).setView(joinDialog) | ||
85 | .setPositiveButton(R.string.action_join) { _, _ -> | ||
86 | joinNetwork( | ||
87 | joinDialog!!.net_name.text.toString(), | ||
88 | joinDialog!!.invitation_url.text.toString(), | ||
89 |