aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/AndroidManifest.xml3
-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
-rw-r--r--app/src/main/res/values/strings.xml7
11 files changed, 119 insertions, 61 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5611e4c..dc406f3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,7 @@
5 5
6 <uses-permission android:name="android.permission.INTERNET"/> 6 <uses-permission android:name="android.permission.INTERNET"/>
7 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 7 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
8 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
8 9
9 <application 10 <application
10 android:name="org.pacien.tincapp.context.App" 11 android:name="org.pacien.tincapp.context.App"
@@ -37,7 +38,7 @@
37 </activity> 38 </activity>
38 39
39 <activity 40 <activity
40 android:name=".activities.PromptActivity" 41 android:name=".activities.LaunchActivity"
41 android:theme="@android:style/Theme.Translucent.NoTitleBar"> 42 android:theme="@android:style/Theme.Translucent.NoTitleBar">
42 <intent-filter> 43 <intent-filter>
43 <action android:name="org.pacien.tincapp.intent.action.CONNECT"/> 44 <action android:name="org.pacien.tincapp.intent.action.CONNECT"/>
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) =