aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorpacien2018-08-11 01:54:04 +0200
committerpacien2018-08-11 01:54:04 +0200
commit3b353c4037f3c52710287777a17110dad6b9d720 (patch)
tree731c5f84bc68cc9268919d38960bec0241e06ec2 /app/src/main/java
parent1ff29ae86b441bc3d0f5eb75d0bdc76f92b7dabe (diff)
downloadtincapp-3b353c4037f3c52710287777a17110dad6b9d720.tar.gz
Refactor part of Status activity
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt1
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/NetworkInfoFragment.kt45
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt (renamed from app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt)35
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/VpnInterfaceConfigurationFormatter.kt41
-rw-r--r--app/src/main/java/org/pacien/tincapp/extensions/Android.kt7
5 files changed, 98 insertions, 31 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 70302e5..84adc7f 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
@@ -37,6 +37,7 @@ import kotlinx.android.synthetic.main.fragment_network_list_header.*
37import org.pacien.tincapp.R 37import org.pacien.tincapp.R
38import org.pacien.tincapp.activities.common.ProgressModal 38import org.pacien.tincapp.activities.common.ProgressModal
39import org.pacien.tincapp.activities.configure.ConfigureActivity 39import org.pacien.tincapp.activities.configure.ConfigureActivity
40import org.pacien.tincapp.activities.status.StatusActivity
40import org.pacien.tincapp.context.AppPaths 41import org.pacien.tincapp.context.AppPaths
41import org.pacien.tincapp.extensions.Android.setElements 42import org.pacien.tincapp.extensions.Android.setElements
42import org.pacien.tincapp.intent.Actions 43import org.pacien.tincapp.intent.Actions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/NetworkInfoFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/status/NetworkInfoFragment.kt
new file mode 100644
index 0000000..385f996
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/activities/status/NetworkInfoFragment.kt
@@ -0,0 +1,45 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2018 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.tincapp.activities.status
20
21import android.app.Fragment
22import android.os.Bundle
23import android.view.LayoutInflater
24import android.view.View
25import android.view.ViewGroup
26import org.pacien.tincapp.databinding.StatusNetworkInfoFragmentBinding
27import org.pacien.tincapp.service.TincVpnService
28
29/**
30 * @author pacien
31 */
32class NetworkInfoFragment : Fragment() {
33 private val vpnService by lazy { TincVpnService }
34 private val netName by lazy { vpnService.getCurrentNetName() }
35 private val interfaceConfiguration by lazy { vpnService.getCurrentInterfaceCfg() }
36 private val listFormatter = VpnInterfaceConfigurationFormatter
37
38 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
39 val binding = StatusNetworkInfoFragmentBinding.inflate(inflater, container, false)
40 binding.netName = netName
41 binding.vpnInterfaceConfiguration = interfaceConfiguration
42 binding.listFormatter = listFormatter
43 return binding.root
44 }
45}
diff --git a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt
index 88ce222..2bf42ce 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt
@@ -16,7 +16,7 @@
16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19package org.pacien.tincapp.activities 19package org.pacien.tincapp.activities.status
20 20
21import android.content.Intent 21import android.content.Intent
22import android.os.Bundle 22import android.os.Bundle
@@ -30,16 +30,17 @@ import android.widget.ArrayAdapter
30import android.widget.TextView 30import android.widget.TextView
31import java8.util.concurrent.CompletableFuture 31import java8.util.concurrent.CompletableFuture
32import kotlinx.android.synthetic.main.base.* 32import kotlinx.android.synthetic.main.base.*
33import kotlinx.android.synthetic.main.dialog_node_details.view.*
34import kotlinx.android.synthetic.main.fragment_list_view.* 33import kotlinx.android.synthetic.main.fragment_list_view.*
35import kotlinx.android.synthetic.main.fragment_network_status_header.* 34import kotlinx.android.synthetic.main.status_activity_list_header.*
35import kotlinx.android.synthetic.main.status_node_info_dialog.view.*
36import org.pacien.tincapp.R 36import org.pacien.tincapp.R
37import org.pacien.tincapp.activities.BaseActivity
38import org.pacien.tincapp.activities.StartActivity
39import org.pacien.tincapp.activities.ViewLogActivity
37import org.pacien.tincapp.activities.common.ProgressModal 40import org.pacien.tincapp.activities.common.ProgressModal
38import org.pacien.tincapp.commands.Executor 41import org.pacien.tincapp.commands.Executor
39import org.pacien.tincapp.commands.Tinc 42import org.pacien.tincapp.commands.Tinc
40import org.pacien.tincapp.data.VpnInterfaceConfiguration
41import org.pacien.tincapp.extensions.Android.setElements 43import org.pacien.tincapp.extensions.Android.setElements
42import org.pacien.tincapp.extensions.Android.setText
43import org.pacien.tincapp.intent.Actions 44import org.pacien.tincapp.intent.Actions
44import org.pacien.tincapp.intent.BroadcastMapper 45import org.pacien.tincapp.intent.BroadcastMapper
45import org.pacien.tincapp.service.TincVpnService 46import org.pacien.tincapp.service.TincVpnService
@@ -62,7 +63,7 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef
62 63
63 layoutInflater.inflate(R.layout.fragment_list_view, main_content) 64 layoutInflater.inflate(R.layout.fragment_list_view, main_content)
64 list_wrapper.setOnRefreshListener(this) 65 list_wrapper.setOnRefreshListener(this)
65 list.addHeaderView(layoutInflater.inflate(R.layout.fragment_network_status_header, list, false), null, false) 66 list.addHeaderView(layoutInflater.inflate(R.layout.status_activity_list_header, list, false), null, false)
66 list.addFooterView(View(this), null, false) 67 list.addFooterView(View(this), null, false)
67 list.onItemClickListener = this 68 list.onItemClickListener = this
68 list.adapter = nodeListAdapter 69 list.adapter = nodeListAdapter
@@ -90,7 +91,6 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef
90 super.onStart() 91 super.onStart()
91 refreshTimer = Timer(true) 92 refreshTimer = Timer(true)
92 refreshTimer?.schedule(timerTask { updateView() }, NOW, REFRESH_RATE) 93 refreshTimer?.schedule(timerTask { updateView() }, NOW, REFRESH_RATE)
93 writeNetworkInfo(TincVpnService.getCurrentInterfaceCfg() ?: VpnInterfaceConfiguration())
94 } 94 }
95 95
96 override fun onStop() { 96 override fun onStop() {
@@ -135,22 +135,9 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef
135 fun openLogViewer(@Suppress("UNUSED_PARAMETER") i: MenuItem) = 135 fun openLogViewer(@Suppress("UNUSED_PARAMETER") i: MenuItem) =
136 startActivity(Intent(this, ViewLogActivity::class.java)) 136 startActivity(Intent(this, ViewLogActivity::class.java))
137 137
138 private fun writeNetworkInfo(cfg: VpnInterfaceConfiguration) {
139 text_network_name.text = TincVpnService.getCurrentNetName() ?: getString(R.string.value_none)
140 text_network_ip_addresses.setText(cfg.addresses.map { it.toSlashSeparated() })
141 text_network_routes.setText(cfg.routes.map { it.toSlashSeparated() })
142 text_network_dns_servers.setText(cfg.dnsServers)
143 text_network_search_domains.setText(cfg.searchDomains)
144 text_network_allow_bypass.text = getString(if (cfg.allowBypass) R.string.value_yes else R.string.value_no)
145 block_network_allowed_applications.visibility = if (cfg.allowedApplications.isNotEmpty()) View.VISIBLE else View.GONE
146 text_network_allowed_applications.setText(cfg.allowedApplications)
147 block_network_disallowed_applications.visibility = if (cfg.disallowedApplications.isNotEmpty()) View.VISIBLE else View.GONE
148 text_network_disallowed_applications.setText(cfg.disallowedApplications)
149 }
150
151 private fun writeNodeList(nodeList: List<String>) { 138 private fun writeNodeList(nodeList: List<String>) {
152 nodeListAdapter?.setElements(nodeList) 139 nodeListAdapter?.setElements(nodeList)
153 node_list_placeholder.visibility = View.GONE 140 status_activity_node_list_placeholder.visibility = View.GONE
154 list_wrapper.isRefreshing = false 141 list_wrapper.isRefreshing = false
155 } 142 }
156 143
@@ -159,13 +146,13 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef
159 } 146 }
160 147
161 private fun showNodeInfo(nodeName: String) { 148 private fun showNodeInfo(nodeName: String) {
162 val dialogTextView = layoutInflater.inflate(R.layout.dialog_node_details, main_content, false) 149 val dialogTextView = layoutInflater.inflate(R.layout.status_node_info_dialog, main_content, false)
163 150
164 runOnUiThread { 151 runOnUiThread {
165 AlertDialog.Builder(this) 152 AlertDialog.Builder(this)
166 .setTitle(R.string.title_node_info) 153 .setTitle(R.string.status_node_info_dialog_title)
167 .setView(dialogTextView) 154 .setView(dialogTextView)
168 .setPositiveButton(R.string.action_close) { _, _ -> Unit } 155 .setPositiveButton(R.string.status_node_info_dialog_close_action) { _, _ -> Unit }
169 .show() 156 .show()
170 } 157 }
171 158
diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/VpnInterfaceConfigurationFormatter.kt b/app/src/main/java/org/pacien/tincapp/activities/status/VpnInterfaceConfigurationFormatter.kt
new file mode 100644
index 0000000..0bcdff5
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/activities/status/VpnInterfaceConfigurationFormatter.kt
@@ -0,0 +1,41 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2018 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *