aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt212
1 files changed, 106 insertions, 106 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
index 356ff6e..4b5384c 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
@@ -29,115 +29,115 @@ import kotlin.concurrent.timerTask
29 */ 29 */
30class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { 30class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
31 31
32 private var nodeListAdapter: ArrayAdapter<String>? = null 32 private var nodeListAdapter: ArrayAdapter<String>? = null
33 private var refreshTimer: Timer? = null 33 private var refreshTimer: Timer? = null
34 private var updateView: Boolean = false 34 private var updateView: Boolean = false
35 35
36 override fun onCreate(savedInstanceState: Bundle?) { 36 override fun onCreate(savedInstanceState: Bundle?) {
37 super.onCreate(savedInstanceState) 37 super.onCreate(savedInstanceState)
38 38
39 nodeListAdapter = ArrayAdapter(this, R.layout.fragment_list_item) 39 nodeListAdapter = ArrayAdapter(this, R.layout.fragment_list_item)
40 refreshTimer = Timer(true) 40 refreshTimer = Timer(true)
41 41
42 layoutInflater.inflate(R.layout.fragment_list_view, main_content) 42 layoutInflater.inflate(R.layout.fragment_list_view, main_content)
43 list_wrapper.setOnRefreshListener(this) 43 list_wrapper.setOnRefreshListener(this)
44 list.addHeaderView(layoutInflater.inflate(R.layout.fragment_network_status_header, list, false), null, false) 44 list.addHeaderView(layoutInflater.inflate(R.layout.fragment_network_status_header, list, false), null, false)
45 list.addFooterView(View(this), null, false) 45 list.addFooterView(View(this), null, false)
46 list.onItemClickListener = this 46 list.onItemClickListener = this
47 list.adapter = nodeListAdapter 47 list.adapter = nodeListAdapter
48 } 48 }
49 49
50 override fun onCreateOptionsMenu(m: Menu): Boolean { 50 override fun onCreateOptionsMenu(m: Menu): Boolean {
51 menuInflater.inflate(R.menu.menu_status, m) 51 menuInflater.inflate(R.menu.menu_status, m)
52 return super.onCreateOptionsMenu(m) 52 return super.onCreateOptionsMenu(m)
53 } 53 }
54 54
55 override fun onDestroy() { 55 override fun onDestroy() {
56 super.onDestroy() 56 super.onDestroy()
57 refreshTimer?.cancel() 57 refreshTimer?.cancel()
58 nodeListAdapter = null 58 nodeListAdapter = null
59 refreshTimer = null 59 refreshTimer = null
60 } 60 }
61 61
62 override fun onStart() { 62 override fun onStart() {
63 super.onStart() 63 super.onStart()
64 writeNetworkInfo(TincVpnService.getCurrentInterfaceCfg() ?: VpnInterfaceConfiguration()) 64 writeNetworkInfo(TincVpnService.getCurrentInterfaceCfg() ?: VpnInterfaceConfiguration())
65 updateView = true 65 updateView = true
66 onRefresh() 66 onRefresh()
67 updateNodeList() 67 updateNodeList()
68 } 68 }
69 69
70 override fun onStop() { 70 override fun onStop() {
71 super.onStop() 71 super.onStop()
72 updateView = false 72 updateView = false
73 } 73 }
74 74
75 override fun onResume() { 75 override fun onResume() {
76 super.onResume() 76 super.onResume()
77 if (!TincVpnService.isConnected()) openStartActivity()
78 }
79
80 override fun onRefresh() {
81 getNodeNames().thenAccept {
82 runOnUiThread {
83 nodeListAdapter?.setElements(it)
84 node_list_placeholder.visibility = if (nodeListAdapter?.isEmpty != false) View.VISIBLE else View.GONE
85 list_wrapper.isRefreshing = false
77 if (!TincVpnService.isConnected()) openStartActivity() 86 if (!TincVpnService.isConnected()) openStartActivity()
87 }
78 } 88 }
79 89 }
80 override fun onRefresh() { 90
81 getNodeNames().thenAccept { 91 override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
82 runOnUiThread { 92 val nodeName = (view as TextView).text.toString()
83 nodeListAdapter?.setElements(it) 93 val dialogTextView = layoutInflater.inflate(R.layout.dialog_node_details, main_content, false)
84 node_list_placeholder.visibility = if (nodeListAdapter?.isEmpty != false) View.VISIBLE else View.GONE 94 Tinc.info(TincVpnService.getCurrentNetName()!!, nodeName).thenAccept {
85 list_wrapper.isRefreshing = false 95 runOnUiThread {
86 if (!TincVpnService.isConnected()) openStartActivity() 96 dialogTextView.dialog_node_details.text = it
87 } 97 AlertDialog.Builder(this)
88 } 98 .setTitle(R.string.title_node_info)
89 } 99 .setView(dialogTextView)
90 100 .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ }
91 override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { 101 .show()
92 val nodeName = (view as TextView).text.toString() 102 }
93 val dialogTextView = layoutInflater.inflate(R.layout.dialog_node_details, main_content, false)
94 Tinc.info(TincVpnService.getCurrentNetName()!!, nodeName).thenAccept {
95 runOnUiThread {
96 dialogTextView.dialog_node_details.text = it
97 AlertDialog.Builder(this)
98 .setTitle(R.string.title_node_info)
99 .setView(dialogTextView)
100 .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ }
101 .show()
102 }
103 }
104 }
105
106 fun writeNetworkInfo(cfg: VpnInterfaceConfiguration) {
107 text_network_name.text = TincVpnService.getCurrentNetName() ?: getString(R.string.value_none)
108 text_network_ip_addresses.setText(cfg.addresses.map { it.toSlashSeparated() })
109 text_network_routes.setText(cfg.routes.map { it.toSlashSeparated() })
110 text_network_dns_servers.setText(cfg.dnsServers)
111 text_network_search_domains.setText(cfg.searchDomains)
112 text_network_allow_bypass.text = getString(if (cfg.allowBypass) R.string.value_yes else R.string.value_no)
113 block_network_allowed_applications.visibility = if (cfg.allowedApplications.isNotEmpty()) View.VISIBLE else View.GONE
114 text_network_allowed_applications.setText(cfg.allowedApplications)
115 block_network_disallowed_applications.visibility = if (cfg.disallowedApplications.isNotEmpty()) View.VISIBLE else View.GONE
116 text_network_disallowed_applications.setText(cfg.disallowedApplications)
117 }
118
119 fun updateNodeList() {
120 refreshTimer?.schedule(timerTask {
121 onRefresh()
122 if (updateView) updateNodeList()
123 }, REFRESH_RATE)
124 } 103 }
125 104 }
126 fun stopVpn(@Suppress("UNUSED_PARAMETER") i: MenuItem) { 105
127 TincVpnService.stopVpn() 106 fun writeNetworkInfo(cfg: VpnInterfaceConfiguration) {
128 openStartActivity() 107 text_network_name.text = TincVpnService.getCurrentNetName() ?: getString(R.string.value_none)
129 finish() 108 text_network_ip_addresses.setText(cfg.addresses.map { it.toSlashSeparated() })
130 } 109 text_network_routes.setText(cfg.routes.map { it.toSlashSeparated() })
131 110 text_network_dns_servers.setText(cfg.dnsServers)
132 fun openStartActivity() = startActivity(Intent(this, StartActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) 111 text_network_search_domains.setText(cfg.searchDomains)
133 112 text_network_allow_bypass.text = getString(if (cfg.allowBypass) R.string.value_yes else R.string.value_no)
134 companion object { 113 block_network_allowed_applications.visibility = if (cfg.allowedApplications.isNotEmpty()) View.VISIBLE else View.GONE
135 private val REFRESH_RATE = 5000L 114 text_network_allowed_applications.setText(cfg.allowedApplications)
136 115 block_network_disallowed_applications.visibility = if (cfg.disallowedApplications.isNotEmpty()) View.VISIBLE else View.GONE
137 fun getNodeNames(): CompletableFuture<List<String>> = when (TincVpnService.isConnected()) { 116 text_network_disallowed_applications.setText(cfg.disallowedApplications)
138 true -> Tinc.dumpNodes(TincVpnService.getCurrentNetName()!!).thenApply<List<String>> { it.map { it.substringBefore(' ') } } 117 }
139 false -> CompletableFuture.supplyAsync<List<String>> { emptyList() } 118
140 } 119 fun updateNodeList() {
120 refreshTimer?.schedule(timerTask {
121 onRefresh()
122 if (updateView) updateNodeList()
123 }, REFRESH_RATE)
124 }
125
126 fun stopVpn(@Suppress("UNUSED_PARAMETER") i: MenuItem) {
127 TincVpnService.stopVpn()
128 openStartActivity()
129 finish()
130 }
131
132 fun openStartActivity() = startActivity(Intent(this, StartActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
133
134 companion object {
135 private val REFRESH_RATE = 5000L
136
137 fun getNodeNames(): CompletableFuture<List<String>> = when (TincVpnService.isConnected()) {
138 true -> Tinc.dumpNodes(TincVpnService.getCurrentNetName()!!).thenApply<List<String>> { it.map { it.substringBefore(' ') } }
139 false -> CompletableFuture.supplyAsync<List<String>> { emptyList() }
141 } 140 }
141 }
142 142
143} 143}