aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt2
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt124
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/StatusFragmentPagerAdapter.kt41
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/NetworkInfoFragment.kt (renamed from app/src/main/java/org/pacien/tincapp/activities/status/NetworkInfoFragment.kt)4
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/VpnInterfaceConfigurationFormatter.kt (renamed from app/src/main/java/org/pacien/tincapp/activities/status/VpnInterfaceConfigurationFormatter.kt)2
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt89
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListLiveData.kt47
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListViewModel.kt30
-rw-r--r--app/src/main/java/org/pacien/tincapp/extensions/ListViewExtensions.kt (renamed from app/src/main/java/org/pacien/tincapp/extensions/Android.kt)17
9 files changed, 247 insertions, 109 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
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.activities.status.StatusActivity
41import org.pacien.tincapp.context.AppPaths 41import org.pacien.tincapp.context.AppPaths
42import org.pacien.tincapp.extensions.Android.setElements 42import org.pacien.tincapp.extensions.setElements
43import org.pacien.tincapp.intent.Actions 43import org.pacien.tincapp.intent.Actions
44import org.pacien.tincapp.intent.BroadcastMapper 44import org.pacien.tincapp.intent.BroadcastMapper
45import org.pacien.tincapp.service.TincVpnService 45import 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
21import android.content.Intent 21import android.content.Intent
22import android.os.Bundle 22import android.os.Bundle
23import android.support.v4.widget.SwipeRefreshLayout
24import android.support.v7.app.AlertDialog 23import android.support.v7.app.AlertDialog
25import android.view.Menu 24import android.view.Menu
26import android.view.MenuItem 25import android.view.MenuItem
27import android.view.View 26import kotlinx.android.synthetic.main.status_activity.*
28import android.widget.AdapterView
29import android.widget.ArrayAdapter
30import android.widget.TextView
31import java8.util.concurrent.CompletableFuture
32import kotlinx.android.synthetic.main.base.*
33import kotlinx.android.synthetic.main.fragment_list_view.*
34import kotlinx.android.synthetic.main.status_activity_list_header.*
35import kotlinx.android.synthetic.main.status_node_info_dialog.view.*
36import org.pacien.tincapp.R 27import org.pacien.tincapp.R
37import org.pacien.tincapp.activities.BaseActivity 28import org.pacien.tincapp.activities.BaseActivity
38import org.pacien.tincapp.activities.StartActivity 29import org.pacien.tincapp.activities.StartActivity
39import org.pacien.tincapp.activities.common.ProgressModal 30import org.pacien.tincapp.activities.common.ProgressModal
40import org.pacien.tincapp.activities.viewlog.ViewLogActivity 31import org.pacien.tincapp.activities.viewlog.ViewLogActivity
41import org.pacien.tincapp.commands.Executor
42import org.pacien.tincapp.commands.Tinc
43import org.pacien.tincapp.extensions.Android.setElements
44import org.pacien.tincapp.intent.Actions 32import org.pacien.tincapp.intent.Actions
45import org.pacien.tincapp.intent.BroadcastMapper 33import org.pacien.tincapp.intent.BroadcastMapper
46import org.pacien.tincapp.service.TincVpnService 34import org.pacien.tincapp.service.TincVpnService
47import java.util.*
48import kotlin.concurrent.timerTask
49 35
50/** 36/**
51 * @author pacien 37 * @author pacien
52 */ 38 */
53class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { 39class 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 89 listNetworksAfterExit = false
144 list_wrapper.isRefreshing = false 90 stopVpn()
145 }
146