aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2017-07-03 15:45:50 +0200
committerPacien TRAN-GIRARD2017-07-03 15:45:50 +0200
commit328ad552b0b508e08072ebcd9409f6214c748a0d (patch)
treeb7093ce3d6c839d5f89b8d05a42a0e8b5d42090b /app/src/main/java
parentd221543bb9d6bc9b7344cc96f010a501ff35bb7f (diff)
downloadtincapp-328ad552b0b508e08072ebcd9409f6214c748a0d.tar.gz
Add configure activity, displaying various paths
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt19
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt31
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt18
3 files changed, 43 insertions, 25 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 2146cec..274e1ba 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt
@@ -1,8 +1,5 @@
1package org.pacien.tincapp.activities 1package org.pacien.tincapp.activities
2 2
3import android.content.ClipData
4import android.content.ClipboardManager
5import android.content.Context
6import android.content.Intent 3import android.content.Intent
7import android.net.Uri 4import android.net.Uri
8import android.os.Bundle 5import android.os.Bundle
@@ -45,18 +42,8 @@ abstract class BaseActivity : AppCompatActivity() {
45 .show() 42 .show()
46 } 43 }
47 44
48 protected fun openWebsite(@StringRes url: Int) { 45 protected fun openWebsite(@StringRes url: Int) = startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(resources.getString(url))))
49 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()
50 } 47 protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show()
51
52 protected fun notify(@StringRes msg: Int) {
53 Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show()
54 }
55
56 protected fun copyIntoClipboard(label: String, str: String) {
57 val c = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
58 c.primaryClip = ClipData.newPlainText(label, str)
59 notify(R.string.message_text_copied)
60 }
61 48
62} 49}
diff --git a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
new file mode 100644
index 0000000..69408d8
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
@@ -0,0 +1,31 @@
1package org.pacien.tincapp.activities
2
3import android.os.Bundle
4import android.view.View
5import kotlinx.android.synthetic.main.base.*
6import kotlinx.android.synthetic.main.page_configure.*
7import org.pacien.tincapp.R
8import org.pacien.tincapp.context.AppPaths
9
10/**
11 * @author pacien
12 */
13class ConfigureActivity : BaseActivity() {
14
15 override fun onCreate(savedInstanceState: Bundle?) {
16 super.onCreate(savedInstanceState)
17 supportActionBar!!.setDisplayHomeAsUpEnabled(true)
18 layoutInflater.inflate(R.layout.page_configure, main_content)
19 writeContent()
20 }
21
22 private fun writeContent() {
23 text_configuration_directories.text = AppPaths.Storage.values().map { AppPaths.confDir(it) }.joinToString("\n")
24 text_log_directories.text = AppPaths.Storage.values().map { AppPaths.cacheDir(it) }.joinToString("\n")
25 text_tinc_binaries.text = listOf(AppPaths.tinc(), AppPaths.tincd()).joinToString("\n")
26 }
27
28 fun generateConf(@Suppress("UNUSED_PARAMETER") v: View) = notify("Not implemented yet")
29 fun joinNetwork(@Suppress("UNUSED_PARAMETER") v: View) = notify("Not implemented yet")
30
31}
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 910b36f..709989b 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
@@ -6,6 +6,8 @@ import android.content.Intent
6import android.net.VpnService 6import android.net.VpnService
7import android.os.Bundle 7import android.os.Bundle
8import android.support.v7.app.AlertDialog 8import android.support.v7.app.AlertDialog
9import android.view.Menu
10import android.view.MenuItem
9import android.view.View 11import android.view.View
10import android.view.ViewGroup 12import android.view.ViewGroup
11import android.widget.EditText 13import android.widget.EditText
@@ -26,6 +28,11 @@ class StartActivity : BaseActivity() {
26 layoutInflater.inflate(R.layout.page_start, main_content) 28 layoutInflater.inflate(R.layout.page_start, main_content)
27 } 29 }
28 30
31 override fun onCreateOptionsMenu(m: Menu): Boolean {
32 menuInflater.inflate(R.menu.menu_start, m)
33 return super.onCreateOptionsMenu(m)
34 }
35
29 override fun onActivityResult(request: Int, result: Int, data: Intent?) { 36 override fun onActivityResult(request: Int, result: Int, data: Intent?) {
30 notify(if (result == Activity.RESULT_OK) R.string.message_vpn_permissions_granted else R.string.message_vpn_permissions_denied) 37 notify(if (result == Activity.RESULT_OK) R.string.message_vpn_permissions_granted else R.string.message_vpn_permissions_denied)
31 } 38 }
@@ -45,7 +52,7 @@ class StartActivity : BaseActivity() {
45 i.setHint(R.string.field_net_name) 52 i.setHint(R.string.field_net_name)
46 53
47 @SuppressLint("InflateParams") 54 @SuppressLint("InflateParams")
48 val vg = layoutInflater.inflate(R.layout.dialog_frame, null) as ViewGroup 55 val vg = layoutInflater.inflate(R.layout.dialog_frame, main_content, false) as ViewGroup
49 vg.addView(i) 56 vg.addView(i)
50 57
51 AlertDialog.Builder(this) 58 AlertDialog.Builder(this)
@@ -56,14 +63,7 @@ class StartActivity : BaseActivity() {
56 .show() 63 .show()
57 } 64 }
58 65
59 fun confDirDialog(@Suppress("UNUSED_PARAMETER") v: View) { 66 fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) = startActivity(Intent(this, ConfigureActivity::class.java))
60 AlertDialog.Builder(this)
61 .setTitle(R.string.title_tinc_config_dir)
62 .setMessage("Internal: " + AppPaths.confDir(AppPaths.Storage.INTERNAL) + "\n\n" +
63 "External: " + AppPaths.confDir(AppPaths.Storage.EXTERNAL))
64 .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ }
65 .show()
66 }
67 67
68 private fun startVpn(netName: String) { 68 private fun startVpn(netName: String) {
69 startService(Intent(this, TincVpnService::class.java).putExtra(TincVpnService.INTENT_EXTRA_NET_CONF, 69 startService(Intent(this, TincVpnService::class.java).putExtra(TincVpnService.INTENT_EXTRA_NET_CONF,