diff options
Diffstat (limited to 'app')
15 files changed, 365 insertions, 188 deletions
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 84adc7f..7023316 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt | |||
@@ -39,7 +39,7 @@ import org.pacien.tincapp.activities.common.ProgressModal | |||
39 | import org.pacien.tincapp.activities.configure.ConfigureActivity | 39 | import org.pacien.tincapp.activities.configure.ConfigureActivity |
40 | import org.pacien.tincapp.activities.status.StatusActivity | 40 | import org.pacien.tincapp.activities.status.StatusActivity |
41 | import org.pacien.tincapp.context.AppPaths | 41 | import org.pacien.tincapp.context.AppPaths |
42 | import org.pacien.tincapp.extensions.Android.setElements | 42 | import org.pacien.tincapp.extensions.setElements |
43 | import org.pacien.tincapp.intent.Actions | 43 | import org.pacien.tincapp.intent.Actions |
44 | import org.pacien.tincapp.intent.BroadcastMapper | 44 | import org.pacien.tincapp.intent.BroadcastMapper |
45 | import org.pacien.tincapp.service.TincVpnService | 45 | import org.pacien.tincapp.service.TincVpnService |
diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt index e5ca307..1ac0e54 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt | |||
@@ -20,63 +20,36 @@ package org.pacien.tincapp.activities.status | |||
20 | 20 | ||
21 | import android.content.Intent | 21 | import android.content.Intent |
22 | import android.os.Bundle | 22 | import android.os.Bundle |
23 | import android.support.v4.widget.SwipeRefreshLayout | ||
24 | import android.support.v7.app.AlertDialog | 23 | import android.support.v7.app.AlertDialog |
25 | import android.view.Menu | 24 | import android.view.Menu |
26 | import android.view.MenuItem | 25 | import android.view.MenuItem |
27 | import android.view.View | 26 | import kotlinx.android.synthetic.main.status_activity.* |
28 | import android.widget.AdapterView | ||
29 | import android.widget.ArrayAdapter | ||
30 | import android.widget.TextView | ||
31 | import java8.util.concurrent.CompletableFuture | ||
32 | import kotlinx.android.synthetic.main.base.* | ||
33 | import kotlinx.android.synthetic.main.fragment_list_view.* | ||
34 | import kotlinx.android.synthetic.main.status_activity_list_header.* | ||
35 | import kotlinx.android.synthetic.main.status_node_info_dialog.view.* | ||
36 | import org.pacien.tincapp.R | 27 | import org.pacien.tincapp.R |
37 | import org.pacien.tincapp.activities.BaseActivity | 28 | import org.pacien.tincapp.activities.BaseActivity |
38 | import org.pacien.tincapp.activities.StartActivity | 29 | import org.pacien.tincapp.activities.StartActivity |
39 | import org.pacien.tincapp.activities.common.ProgressModal | 30 | import org.pacien.tincapp.activities.common.ProgressModal |
40 | import org.pacien.tincapp.activities.viewlog.ViewLogActivity | 31 | import org.pacien.tincapp.activities.viewlog.ViewLogActivity |
41 | import org.pacien.tincapp.commands.Executor | ||
42 | import org.pacien.tincapp.commands.Tinc | ||
43 | import org.pacien.tincapp.extensions.Android.setElements | ||
44 | import org.pacien.tincapp.intent.Actions | 32 | import org.pacien.tincapp.intent.Actions |
45 | import org.pacien.tincapp.intent.BroadcastMapper | 33 | import org.pacien.tincapp.intent.BroadcastMapper |
46 | import org.pacien.tincapp.service.TincVpnService | 34 | import org.pacien.tincapp.service.TincVpnService |
47 | import java.util.* | ||
48 | import kotlin.concurrent.timerTask | ||
49 | 35 | ||
50 | /** | 36 | /** |
51 | * @author pacien | 37 | * @author pacien |
52 | */ | 38 | */ |
53 | class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { | 39 | class StatusActivity : BaseActivity() { |
54 | private val vpnService by lazy { TincVpnService } | 40 | private val vpnService by lazy { TincVpnService } |
55 | private val netName by lazy { vpnService.getCurrentNetName() } | 41 | private val netName by lazy { vpnService.getCurrentNetName() } |
42 | private val pagerAdapter by lazy { StatusFragmentPagerAdapter(supportFragmentManager) } | ||
56 | private val broadcastMapper = BroadcastMapper(mapOf(Actions.EVENT_DISCONNECTED to this::onVpnShutdown)) | 43 | private val broadcastMapper = BroadcastMapper(mapOf(Actions.EVENT_DISCONNECTED to this::onVpnShutdown)) |
57 | private var shutdownDialog: AlertDialog? = null | 44 | private var shutdownDialog: AlertDialog? = null |
58 | private var nodeListAdapter: ArrayAdapter<String>? = null | ||
59 | private var refreshTimer: Timer? = null | ||
60 | private var listNetworksAfterExit = true | 45 | private var listNetworksAfterExit = true |
61 | 46 | ||
62 | override fun onCreate(savedInstanceState: Bundle?) { | 47 | override fun onCreate(savedInstanceState: Bundle?) { |
63 | super.onCreate(savedInstanceState) | 48 | super.onCreate(savedInstanceState) |
49 | setContentView(R.layout.status_activity) | ||
50 | status_activity_pager.adapter = pagerAdapter | ||
64 | supportActionBar.subtitle = getString(R.string.status_activity_state_connected_to_format, netName) | 51 | supportActionBar.subtitle = getString(R.string.status_activity_state_connected_to_format, netName) |
65 | nodeListAdapter = ArrayAdapter(this, R.layout.fragment_list_item) | 52 | handleStartIntentAction(intent.action) |
66 | |||
67 | layoutInflater.inflate(R.layout.fragment_list_view, main_content) | ||
68 | list_wrapper.setOnRefreshListener(this) | ||
69 | list.addHeaderView(layoutInflater.inflate(R.layout.status_activity_list_header, list, false), null, false) | ||
70 | list.addFooterView(View(this), null, false) | ||
71 | list.onItemClickListener = this | ||
72 | list.adapter = nodeListAdapter | ||
73 | |||
74 | if (intent.action == Actions.ACTION_DISCONNECT) { | ||
75 | listNetworksAfterExit = false | ||
76 | stopVpn() | ||
77 | } else { | ||
78 | listNetworksAfterExit = true | ||
79 | } | ||
80 | } | 53 | } |
81 | 54 | ||
82 | override fun onCreateOptionsMenu(m: Menu): Boolean { | 55 | override fun onCreateOptionsMenu(m: Menu): Boolean { |
@@ -84,27 +57,11 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef | |||
84 | return super.onCreateOptionsMenu(m) | 57 | return super.onCreateOptionsMenu(m) |
85 | } | 58 | } |
86 | 59 | ||
87 | override fun onDestroy() { | ||
88 | super.onDestroy() | ||
89 | nodeListAdapter = null | ||
90 | refreshTimer = null | ||
91 | } | ||
92 | |||
93 | override fun onStart() { | ||
94 | super.onStart() | ||
95 | refreshTimer = Timer(true) | ||
96 | refreshTimer?.schedule(timerTask { updateView() }, NOW, REFRESH_RATE) | ||
97 | } | ||
98 | |||
99 | override fun onStop() { | ||
100 | refreshTimer?.cancel() | ||
101 | super.onStop() | ||
102 | } | ||
103 | |||
104 | override fun onResume() { | 60 | override fun onResume() { |
105 | super.onResume() | 61 | super.onResume() |
62 | if (!TincVpnService.isConnected()) openStartActivity() | ||
63 | |||
106 | broadcastMapper.register() | 64 | broadcastMapper.register() |
107 | updateView() | ||
108 | handleRecentCrash() | 65 | handleRecentCrash() |
109 | } | 66 | } |
110 | 67 | ||
@@ -113,75 +70,36 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef | |||
113 | super.onPause() | 70 | super.onPause() |
114 | } | 71 | } |
115 | 72 | ||
116 | override fun onRefresh() { | ||
117 | refreshTimer?.schedule(timerTask { updateView() }, NOW) | ||
118 | } | ||
119 | |||
120 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) = when (view) { | ||
121 | is TextView -> showNodeInfo(view.text.toString()) | ||
122 | else -> Unit | ||
123 | } | ||
124 | |||
125 | private fun onVpnShutdown() { | 73 | private fun onVpnShutdown() { |
126 | shutdownDialog?.dismiss() | 74 | shutdownDialog?.dismiss() |
127 | if (listNetworksAfterExit) openStartActivity() | 75 | if (listNetworksAfterExit) openStartActivity() |
128 | finish() | 76 | finish() |
129 | } | 77 | } |
130 | 78 | ||
131 | fun stopVpn(@Suppress("UNUSED_PARAMETER") i: MenuItem? = null) { | 79 | @Suppress("UNUSED_PARAMETER") |
132 | refreshTimer?.cancel() | 80 | fun stopVpn(m: MenuItem) = |
133 | list_wrapper.isRefreshing = false | 81 | stopVpn() |
134 | shutdownDialog = ProgressModal.show(this, getString(R.string.message_disconnecting_vpn)) | ||
135 | TincVpnService.disconnect() | ||
136 | } | ||
137 | 82 | ||
138 | fun openLogViewer(@Suppress("UNUSED_PARAMETER") i: MenuItem) = | 83 | @Suppress("UNUSED_PARAMETER") |
84 | fun openLogViewer(m: MenuItem) = | ||
139 | startActivity(Intent(this, ViewLogActivity::class.java)) | 85 | startActivity(Intent(this, ViewLogActivity::class.java)) |
140 | 86 | ||
141 | private fun writeNodeList(nodeList: List<String>) { | 87 | private fun handleStartIntentAction(intentAction: String?) = when (intentAction) { |
142 | nodeListAdapter?.setElements(nodeList) | 88 | Actions.ACTION_DISCONNECT -> { |
143 | status_activity_node_list_placeholder.visibility = View.GONE |