aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt12
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt5
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/LaunchActivity.kt (renamed from app/src/main/java/org/pacien/tincapp/activities/PromptActivity.kt)11
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt2
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/App.kt21
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppPaths.kt3
-rw-r--r--app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt8
-rw-r--r--app/src/main/java/org/pacien/tincapp/intent/action/Actions.kt3
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt105
9 files changed, 110 insertions, 60 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 000320c..4904a66 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,6 @@
1package org.pacien.tincapp.activities 1package org.pacien.tincapp.activities
2 2
3import android.app.ProgressDialog 3import android.app.ProgressDialog
4import android.content.Intent
5import android.net.Uri
6import android.os.Bundle 4import android.os.Bundle
7import android.support.annotation.StringRes 5import android.support.annotation.StringRes
8import android.support.design.widget.Snackbar 6import android.support.design.widget.Snackbar
@@ -13,6 +11,7 @@ import android.view.MenuItem
13import kotlinx.android.synthetic.main.base.* 11import kotlinx.android.synthetic.main.base.*
14import org.pacien.tincapp.BuildConfig 12import org.pacien.tincapp.BuildConfig
15import org.pacien.tincapp.R 13import org.pacien.tincapp.R
14import org.pacien.tincapp.context.App
16import org.pacien.tincapp.context.AppInfo 15import org.pacien.tincapp.context.AppInfo
17 16
18/** 17/**
@@ -38,19 +37,16 @@ abstract class BaseActivity : AppCompatActivity() {
38 resources.getString(R.string.app_copyright) + " " + 37 resources.getString(R.string.app_copyright) + " " +
39 resources.getString(R.string.app_license) + "\n\n" + 38 resources.getString(R.string.app_license) + "\n\n" +
40 AppInfo.all()) 39 AppInfo.all())
41 .setNeutralButton(R.string.action_open_project_website) { _, _ -> openWebsite(R.string.app_website_url) } 40 .setNeutralButton(R.string.action_open_project_website) { _, _ -> App.openURL(resources.getString(R.string.app_website_url)) }
42 .setPositiveButton(R.string.action_close, dismiss) 41 .setPositiveButton(R.string.action_close, App.dismissAction)
43 .show() 42 .show()
44 } 43 }
45 44
46 protected fun openWebsite(@StringRes url: Int) = startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(resources.getString(url))))
47 protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() 45 protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show()
48 protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() 46 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) 47 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) 48 protected fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this)
51 .setTitle(R.string.title_error).setMessage(msg) 49 .setTitle(R.string.title_error).setMessage(msg)
52 .setPositiveButton(R.string.action_close, dismiss).show() 50 .setPositiveButton(R.string.action_close, App.dismissAction).show()
53
54 protected val dismiss = { _: Any, _: Any -> /* nop */ }
55 51
56} 52}
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 b030a85..ea37944 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
@@ -13,6 +13,7 @@ import kotlinx.android.synthetic.main.page_configure.*
13import org.pacien.tincapp.R 13import org.pacien.tincapp.R
14import org.pacien.tincapp.commands.Tinc 14import org.pacien.tincapp.commands.Tinc
15import org.pacien.tincapp.commands.TincApp 15import org.pacien.tincapp.commands.TincApp
16import org.pacien.tincapp.context.App
16import org.pacien.tincapp.context.AppPaths 17import org.pacien.tincapp.context.AppPaths
17import org.pacien.tincapp.extensions.Java.exceptionallyAccept 18import org.pacien.tincapp.extensions.Java.exceptionallyAccept
18 19
@@ -43,7 +44,7 @@ class ConfigureActivity : BaseActivity() {
43 44
44 AlertDialog.Builder(this).setTitle(R.string.title_new_network).setView(dialogFrame) 45 AlertDialog.Builder(this).setTitle(R.string.title_new_network).setView(dialogFrame)
45 .setPositiveButton(R.string.action_create) { _, _ -> generateConf(netNameField.text.toString(), nodeNameField.text.toString()) } 46 .setPositiveButton(R.string.action_create) { _, _ -> generateConf(netNameField.text.toString(), nodeNameField.text.toString()) }
46 .setNegativeButton(R.string.action_cancel, dismiss).show() 47 .setNegativeButton(R.string.action_cancel, App.dismissAction).show()
47 } 48 }
48 49
49 fun openJoinNetworkDialog(@Suppress("UNUSED_PARAMETER") v: View) { 50 fun openJoinNetworkDialog(@Suppress("UNUSED_PARAMETER") v: View) {
@@ -61,7 +62,7 @@ class ConfigureActivity : BaseActivity() {
61 62
62 AlertDialog.Builder(this).setTitle(R.string.title_join_network).setView(dialogFrame) 63 AlertDialog.Builder(this).setTitle(R.string.title_join_network).setView(dialogFrame)
63 .setPositiveButton(R.string.action_join) { _, _ -> joinNetwork(netNameField.text.toString(), joinUrlField.text.toString()) } 64 .setPositiveButton(R.string.action_join) { _, _ -> joinNetwork(netNameField.text.toString(), joinUrlField.text.toString()) }
64 .setNegativeButton(R.string.action_cancel, dismiss).show() 65 .setNegativeButton(R.string.action_cancel, App.dismissAction).show()
65 } 66 }
66 67
67 private fun writeContent() { 68 private fun writeContent() {
diff --git a/app/src/main/java/org/pacien/tincapp/activities/PromptActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/LaunchActivity.kt
index 6310d63..6eb630d 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/PromptActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/LaunchActivity.kt
@@ -5,7 +5,6 @@ import android.content.Intent
5import android.net.Uri 5import android.net.Uri
6import android.net.VpnService 6import android.net.VpnService
7import android.os.Bundle 7import android.os.Bundle
8import org.pacien.tincapp.BuildConfig
9import org.pacien.tincapp.context.App 8import org.pacien.tincapp.context.App
10import org.pacien.tincapp.intent.action.ACTION_CONNECT 9import org.pacien.tincapp.intent.action.ACTION_CONNECT
11import org.pacien.tincapp.intent.action.ACTION_DISCONNECT 10import org.pacien.tincapp.intent.action.ACTION_DISCONNECT
@@ -15,13 +14,13 @@ import org.pacien.tincapp.service.TincVpnService
15/** 14/**
16 * @author pacien 15 * @author pacien
17 */ 16 */
18class PromptActivity : Activity() { 17class LaunchActivity : Activity() {
19 18
20 override fun onCreate(savedInstanceState: Bundle?) { 19 override fun onCreate(savedInstanceState: Bundle?) {
21 super.onCreate(savedInstanceState) 20 super.onCreate(savedInstanceState)
22 21
23 when (intent.action) { 22 when (intent.action) {
24 ACTION_CONNECT -> connect() 23 ACTION_CONNECT -> requestPerm()
25 ACTION_DISCONNECT -> disconnect() 24 ACTION_DISCONNECT -> disconnect()
26 } 25 }
27 } 26 }
@@ -31,7 +30,7 @@ class PromptActivity : Activity() {
31 finish() 30 finish()
32 } 31 }
33 32
34 private fun connect() = VpnService.prepare(this).let { 33 private fun requestPerm() = VpnService.prepare(this).let {
35 if (it != null) 34 if (it != null)
36 startActivityForResult(it, 0) 35 startActivityForResult(it, 0)
37 else 36 else
@@ -46,14 +45,14 @@ class PromptActivity : Activity() {
46 companion object { 45 companion object {
47 46
48 fun connect(netName: String) { 47 fun connect(netName: String) {
49 App.getContext().startActivity(Intent(App.getContext(), PromptActivity::class.java) 48 App.getContext().startActivity(Intent(App.getContext(), LaunchActivity::class.java)
50 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 49 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
51 .setAction(ACTION_CONNECT) 50 .setAction(ACTION_CONNECT)
52 .setData(Uri.Builder().scheme(TINC_SCHEME).opaquePart(netName).build())) 51 .setData(Uri.Builder().scheme(TINC_SCHEME).opaquePart(netName).build()))
53 } 52 }
54 53
55 fun disconnect() { 54 fun disconnect() {
56 App.getContext().startActivity(Intent(App.getContext(), PromptActivity::class.java) 55 App.getContext().startActivity(Intent(App.getContext(), LaunchActivity::class.java)
57 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 56 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
58 .setAction(ACTION_DISCONNECT)) 57 .setAction(ACTION_DISCONNECT))
59 } 58 }
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 e49e261..6ef8974 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
@@ -77,7 +77,7 @@ class StartActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefr
77 } 77 }
78 78
79 override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) = 79 override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) =
80 PromptActivity.connect((view as TextView).text.toString()) 80 LaunchActivity.connect((view as TextView).text.toString())
81 81
82 fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) = 82 fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) =
83 startActivity(Intent(this, ConfigureActivity::class.java)) 83 startActivity(Intent(this, ConfigureActivity::class.java))
diff --git a/app/src/main/java/org/pacien/tincapp/context/App.kt b/app/src/main/java/org/pacien/tincapp/context/App.kt
index 4b7e44e..7aaa3d0 100644
--- a/app/src/main/java/org/pacien/tincapp/context/App.kt
+++ b/app/src/main/java/org/pacien/tincapp/context/App.kt
@@ -2,6 +2,12 @@ package org.pacien.tincapp.context
2 2
3import android.app.Application 3import android.app.Application
4import android.content.Context 4import android.content.Context
5import android.content.Intent
6import android.net.Uri
7import android.support.annotation.StringRes
8import android.support.v7.app.AlertDialog
9import android.view.WindowManager
10import org.pacien.tincapp.R
5 11
6/**