diff options
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/AndroidManifest.xml | 5 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/PromptActivity.kt | 49 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt | 55 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt | 8 | ||||
-rw-r--r-- | app/src/main/res/layout/base.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/layout/fragment_list_item.xml | 9 | ||||
-rw-r--r-- | app/src/main/res/layout/fragment_network_list_empty_placeholder.xml | 5 | ||||
-rw-r--r-- | app/src/main/res/layout/fragment_network_list_header.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/layout/page_configure.xml | 113 | ||||
-rw-r--r-- | app/src/main/res/layout/page_start.xml | 40 | ||||
-rw-r--r-- | app/src/main/res/values-ja/strings.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/values-nb-rNO/strings.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/values/styles.xml | 4 |
14 files changed, 176 insertions, 132 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4866800..a3f5569 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml | |||
@@ -29,6 +29,11 @@ | |||
29 | android:theme="@style/AppTheme.NoActionBar"> | 29 | android:theme="@style/AppTheme.NoActionBar"> |
30 | </activity> | 30 | </activity> |
31 | 31 | ||
32 | <activity | ||
33 | android:name=".activities.PromptActivity" | ||
34 | android:theme="@android:style/Theme.Translucent.NoTitleBar"> | ||
35 | </activity> | ||
36 | |||
32 | <service | 37 | <service |
33 | android:name="org.pacien.tincapp.service.TincVpnService" | 38 | android:name="org.pacien.tincapp.service.TincVpnService" |
34 | android:permission="android.permission.BIND_VPN_SERVICE"> | 39 | android:permission="android.permission.BIND_VPN_SERVICE"> |
diff --git a/app/src/main/java/org/pacien/tincapp/activities/PromptActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/PromptActivity.kt new file mode 100644 index 0000000..6906ead --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/activities/PromptActivity.kt | |||
@@ -0,0 +1,49 @@ | |||
1 | package org.pacien.tincapp.activities | ||
2 | |||
3 | import android.app.Activity | ||
4 | import android.content.Intent | ||
5 | import android.net.VpnService | ||
6 | import android.os.Bundle | ||
7 | import org.pacien.tincapp.context.App | ||
8 | import org.pacien.tincapp.service.TincVpnService | ||
9 | |||
10 | /** | ||
11 | * @author pacien | ||
12 | */ | ||
13 | class PromptActivity : Activity() { | ||
14 | |||
15 | override fun onCreate(savedInstanceState: Bundle?) { | ||
16 | super.onCreate(savedInstanceState) | ||
17 | |||
18 | when (intent.getSerializableExtra(INTENT_EXTRA_ACTION) as Action) { | ||
19 | Action.REQUEST_PERMISSION -> requestVpnPermission() | ||
20 | } | ||
21 | } | ||
22 | |||
23 | override fun onActivityResult(request: Int, result: Int, data: Intent?) { | ||
24 | if (result == Activity.RESULT_OK) TincVpnService.startVpn(intent.getStringExtra(INTENT_EXTRA_NET_NAME)) | ||
25 | finish() | ||
26 | } | ||
27 | |||
28 | private fun requestVpnPermission() = VpnService.prepare(this).let { | ||
29 | if (it != null) | ||
30 | startActivityForResult(it, 0) | ||
31 | else | ||
32 | onActivityResult(0, Activity.RESULT_OK, Intent()) | ||
33 | } | ||
34 | |||
35 | companion object { | ||
36 | private val INTENT_EXTRA_ACTION = "action" | ||
37 | private val INTENT_EXTRA_NET_NAME = "netName" | ||
38 | |||
39 | private enum class Action { REQUEST_PERMISSION } | ||
40 | |||
41 | fun requestVpnPermission(netName: String) { | ||
42 | App.getContext().startActivity(Intent(App.getContext(), PromptActivity::class.java) | ||
43 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
44 | .putExtra(INTENT_EXTRA_ACTION, Action.REQUEST_PERMISSION) | ||
45 | .putExtra(INTENT_EXTRA_NET_NAME, netName)) | ||
46 | } | ||
47 | } | ||
48 | |||
49 | } | ||
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 1c4b5a1..28d0a29 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt | |||
@@ -1,29 +1,27 @@ | |||
1 | package org.pacien.tincapp.activities | 1 | package org.pacien.tincapp.activities |
2 | 2 | ||
3 | import android.annotation.SuppressLint | ||
4 | import android.app.Activity | ||
5 | import android.content.Intent | 3 | import android.content.Intent |
6 | import android.net.VpnService | ||
7 | import android.os.Bundle | 4 | import android.os.Bundle |
8 | import android.support.v7.app.AlertDialog | ||
9 | import android.view.Menu | 5 | import android.view.Menu |
10 | import android.view.MenuItem | 6 | import android.view.MenuItem |
11 | import android.view.View | 7 | import android.view.View |
12 | import android.view.ViewGroup | 8 | import android.widget.AdapterView |
13 | import android.widget.EditText | 9 | import android.widget.ArrayAdapter |
14 | import android.widget.FrameLayout | 10 | import android.widget.TextView |
15 | import kotlinx.android.synthetic.main.base.* | 11 | import kotlinx.android.synthetic.main.base.* |
12 | import kotlinx.android.synthetic.main.page_start.* | ||
16 | import org.pacien.tincapp.R | 13 | import org.pacien.tincapp.R |
17 | import org.pacien.tincapp.service.TincVpnService | 14 | import org.pacien.tincapp.context.AppPaths |
18 | 15 | ||
19 | /** | 16 | /** |
20 | * @author pacien | 17 | * @author pacien |
21 | */ | 18 | */ |
22 | class StartActivity : BaseActivity() { | 19 | class StartActivity : BaseActivity(), AdapterView.OnItemClickListener { |
23 | 20 | ||
24 | override fun onCreate(savedInstanceState: Bundle?) { | 21 | override fun onCreate(savedInstanceState: Bundle?) { |
25 | super.onCreate(savedInstanceState) | 22 | super.onCreate(savedInstanceState) |
26 | layoutInflater.inflate(R.layout.page_start, main_content) | 23 | layoutInflater.inflate(R.layout.page_start, main_content) |
24 | writeContent() | ||
27 | } | 25 | } |
28 | 26 | ||
29 | override fun onCreateOptionsMenu(m: Menu): Boolean { | 27 | override fun onCreateOptionsMenu(m: Menu): Boolean { |
@@ -31,39 +29,20 @@ class StartActivity : BaseActivity() { | |||
31 | return super.onCreateOptionsMenu(m) | 29 | return super.onCreateOptionsMenu(m) |
32 | } | 30 | } |
33 | 31 | ||
34 | override fun onActivityResult(request: Int, result: Int, data: Intent?) { | 32 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { |
35 | notify(if (result == Activity.RESULT_OK) R.string.message_vpn_permissions_granted else R.string.message_vpn_permissions_denied) | 33 | PromptActivity.requestVpnPermission((view as TextView).text.toString()) |
36 | } | 34 | } |
37 | 35 | ||
38 | fun requestVpnPermission(@Suppress("UNUSED_PARAMETER") v: View) { | 36 | fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) { |
39 | val askPermIntent = VpnService.prepare(this) | 37 | startActivity(Intent(this, ConfigureActivity::class.java)) |
40 | |||
41 | if (askPermIntent != null) | ||
42 | startActivityForResult(askPermIntent, 0) | ||
43 | else | ||
44 | onActivityResult(0, Activity.RESULT_OK, null) | ||
45 | } | 38 | } |
46 | 39 | ||
47 | fun startVpnDialog(@Suppress("UNUSED_PARAMETER") v: View) { | 40 | private fun writeContent() { |
48 | val i = EditText(this) | 41 | network_list.addHeaderView(layoutInflater.inflate(R.layout.fragment_network_list_header, network_list, false)) |
49 | i.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) | 42 | network_list.addFooterView(View(this)) |
50 | i.setHint(R.string.field_net_name) | 43 | network_list.emptyView = layoutInflater.inflate(R.layout.fragment_network_list_empty_placeholder, network_list, false) |
51 | 44 | network_list.adapter = ArrayAdapter<String>(this, R.layout.fragment_list_item, AppPaths.confDir().list()) | |
52 | @SuppressLint("InflateParams") | 45 | network_list.onItemClickListener = this |
53 | val vg = layoutInflater.inflate(R.layout.dialog_frame, main_content, false) as ViewGroup | ||
54 | vg.addView(i) | ||
55 | |||
56 | AlertDialog.Builder(this) | ||
57 | .setTitle(R.string.title_connect_to_network) | ||
58 | .setView(vg) | ||
59 | .setPositiveButton(R.string.action_connect) { _, _ -> startVpn(i.text.toString()) } | ||
60 | .setNegativeButton(R.string.action_close) { _, _ -> /* nop */ } | ||
61 | .show() | ||
62 | } | 46 | } |
63 | 47 | ||
64 | fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) = startActivity(Intent(this, ConfigureActivity::class.java)) | ||
65 | |||
66 | private fun startVpn(netName: String) = | ||
67 | startService(Intent(this, TincVpnService::class.java).putExtra(TincVpnService.INTENT_EXTRA_NET_NAME, netName)) | ||
68 | |||
69 | } | 48 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt index 31541b3..59d9e34 100644 --- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt +++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt | |||
@@ -6,6 +6,7 @@ import android.net.VpnService | |||
6 | import org.pacien.tincapp.BuildConfig | 6 | import org.pacien.tincapp.BuildConfig |
7 | import org.pacien.tincapp.commands.Tinc | 7 | import org.pacien.tincapp.commands.Tinc |
8 | import org.pacien.tincapp.commands.Tincd | 8 | import org.pacien.tincapp.commands.Tincd |
9 | import org.pacien.tincapp.context.App | ||
9 | import org.pacien.tincapp.context.AppPaths | 10 | import org.pacien.tincapp.context.AppPaths |
10 | import org.pacien.tincapp.utils.applyIgnoringException | 11 | import org.pacien.tincapp.utils.applyIgnoringException |
11 | import java.io.IOException | 12 | import java.io.IOException |
@@ -43,7 +44,12 @@ class TincVpnService : VpnService() { | |||
43 | } | 44 | } |
44 | 45 | ||
45 | companion object { | 46 | companion object { |
46 | val INTENT_EXTRA_NET_NAME = "netName" |