diff options
Diffstat (limited to 'app/src/main/kotlin')
29 files changed, 2396 insertions, 0 deletions
diff --git a/app/src/main/kotlin/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/kotlin/org/pacien/tincapp/activities/BaseActivity.kt new file mode 100644 index 0000000..4dc2381 --- /dev/null +++ b/app/src/main/kotlin/org/pacien/tincapp/activities/BaseActivity.kt | |||
@@ -0,0 +1,114 @@ | |||
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.os.Bundle | ||
22 | import android.support.annotation.StringRes | ||
23 | import android.support.design.widget.Snackbar | ||
24 | import android.support.v7.app.AlertDialog | ||
25 | import android.support.v7.app.AppCompatActivity | ||
26 | import android.view.Menu | ||
27 | import android.view.MenuItem | ||
28 | import kotlinx.android.synthetic.main.base.* | ||
29 | import org.pacien.tincapp.R | ||
30 | import org.pacien.tincapp.context.App | ||
31 | import org.pacien.tincapp.context.AppInfo | ||
32 | import org.pacien.tincapp.context.AppPaths | ||
33 | import org.pacien.tincapp.context.CrashRecorder | ||
34 | import org.pacien.tincapp.utils.ProgressModal | ||
35 | |||
36 | /** | ||
37 | * @author pacien | ||
38 | */ | ||
39 | abstract class BaseActivity : AppCompatActivity() { | ||
40 | private var active = false | ||
41 | |||
42 | override fun onCreate(savedInstanceState: Bundle?) { | ||
43 | super.onCreate(savedInstanceState) | ||
44 | setContentView(R.layout.base) | ||
45 | } | ||
46 | |||
47 | override fun onCreateOptionsMenu(m: Menu): Boolean { | ||
48 | menuInflater.inflate(R.menu.menu_base, m) | ||
49 | return true | ||
50 | } | ||
51 | |||
52 | override fun onStart() { | ||
53 | super.onStart() | ||
54 | active = true | ||
55 | } | ||
56 | |||
57 | override fun onResume() { | ||
58 | super.onResume() | ||
59 | active = true | ||
60 | } | ||
61 | |||
62 | override fun onPause() { | ||
63 | active = false | ||
64 | super.onPause() | ||
65 | } | ||
66 | |||
67 | override fun onStop() { | ||
68 | active = false | ||
69 | super.onStop() | ||
70 | } | ||
71 | |||
72 | fun aboutDialog(@Suppress("UNUSED_PARAMETER") i: MenuItem) { | ||
73 | AlertDialog.Builder(this) | ||
74 | .setTitle(resources.getString(R.string.app_name)) | ||
75 | .setMessage(resources.getString(R.string.app_short_desc) + "\n\n" + | ||
76 | resources.getString(R.string.app_copyright) + " " + | ||
77 | resources.getString(R.string.app_license) + "\n\n" + | ||
78 | AppInfo.all()) | ||
79 | .setNeutralButton(R.string.action_open_project_website) { _, _ -> App.openURL(resources.getString(R.string.app_website_url)) } | ||
80 | .setPositiveButton(R.string.action_close) { _, _ -> Unit } | ||
81 | .show() | ||
82 | } | ||
83 | |||
84 | fun runOnUiThread(action: () -> Unit) { | ||
85 | if (active) super.runOnUiThread(action) | ||
86 | } | ||
87 | |||
88 | fun handleRecentCrash() { | ||
89 | if (!CrashRecorder.hasPreviouslyCrashed()) return | ||
90 | CrashRecorder.dismissPreviousCrash() | ||
91 | |||
92 | AlertDialog.Builder(this) | ||
93 | .setTitle(R.string.title_app_crash) | ||
94 | .setMessage(listOf( | ||
95 | resources.getString(R.string.message_app_crash), | ||
96 | resources.getString(R.string.message_crash_logged, AppPaths.appLogFile().absolutePath) | ||
97 | ).joinToString("\n\n")) | ||
98 | .setNeutralButton(R.string.action_send_report) { _, _ -> | ||
99 | App.sendMail( | ||
100 | resources.getString(R.string.app_dev_email), | ||
101 | listOf(R.string.app_name, R.string.title_app_crash).joinToString(" / ", transform = resources::getString), | ||
102 | AppPaths.appLogFile().let { if (it.exists()) it.readText() else "" }) | ||
103 | } | ||
104 | .setPositiveButton(R.string.action_close) { _, _ -> Unit } | ||
105 | .show() | ||
106 | } | ||
107 | |||
108 | protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | ||
109 | protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | ||
110 | protected fun showProgressDialog(@StringRes msg: Int): AlertDialog = ProgressModal.show(this, getString(msg)) | ||
111 | protected fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this) | ||
112 | .setTitle(R.string.title_error).setMessage(msg) | ||
113 | .setPositiveButton(R.string.action_close) { _, _ -> Unit }.show() | ||
114 | } | ||
diff --git a/app/src/main/kotlin/org/pacien/tincapp/activities/ConfigureActivity.kt b/app/src/main/kotlin/org/pacien/tincapp/activities/ConfigureActivity.kt new file mode 100644 index 0000000..2aab304 --- /dev/null +++ b/app/src/main/kotlin/org/pacien/tincapp/activities/ConfigureActivity.kt | |||
@@ -0,0 +1,145 @@ | |||
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 | ||