diff options
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.kt | 36 |
1 files changed, 21 insertions, 15 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 44f4f89..fb6ab73 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt | |||
@@ -10,6 +10,7 @@ import android.view.View | |||
10 | import android.widget.AdapterView | 10 | import android.widget.AdapterView |
11 | import android.widget.ArrayAdapter | 11 | import android.widget.ArrayAdapter |
12 | import android.widget.TextView | 12 | import android.widget.TextView |
13 | import java8.util.concurrent.CompletableFuture | ||
13 | import kotlinx.android.synthetic.main.base.* | 14 | import kotlinx.android.synthetic.main.base.* |
14 | import kotlinx.android.synthetic.main.dialog_text_monopsace.view.* | 15 | import kotlinx.android.synthetic.main.dialog_text_monopsace.view.* |
15 | import kotlinx.android.synthetic.main.fragment_network_status_header.* | 16 | import kotlinx.android.synthetic.main.fragment_network_status_header.* |
@@ -78,24 +79,28 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef | |||
78 | } | 79 | } |
79 | 80 | ||
80 | override fun onRefresh() { | 81 | override fun onRefresh() { |
81 | val nodes = getNodeNames() | 82 | getNodeNames().thenAccept { |
82 | runOnUiThread { | 83 | runOnUiThread { |
83 | nodeListAdapter?.setElements(nodes) | 84 | nodeListAdapter?.setElements(it) |
84 | node_list_wrapper.isRefreshing = false | 85 | node_list_wrapper.isRefreshing = false |
85 | if (!TincVpnService.isConnected()) openStartActivity() | 86 | if (!TincVpnService.isConnected()) openStartActivity() |
87 | } | ||
86 | } | 88 | } |
87 | } | 89 | } |
88 | 90 | ||
89 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { | 91 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { |
90 | val nodeName = (view as TextView).text.toString() | 92 | val nodeName = (view as TextView).text.toString() |
91 | val dialogTextView = layoutInflater.inflate(R.layout.dialog_text_monopsace, main_content, false) | 93 | val dialogTextView = layoutInflater.inflate(R.layout.dialog_text_monopsace, main_content, false) |
92 | dialogTextView.dialog_text_monospace.text = Tinc.info(TincVpnService.getCurrentNetName()!!, nodeName) | 94 | Tinc.info(TincVpnService.getCurrentNetName()!!, nodeName).thenAccept { |
93 | 95 | runOnUiThread { | |
94 | AlertDialog.Builder(this) | 96 | dialogTextView.dialog_text_monospace.text = it |
95 | .setTitle(R.string.title_node_info) | 97 | AlertDialog.Builder(this) |
96 | .setView(dialogTextView) | 98 | .setTitle(R.string.title_node_info) |
97 | .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ } | 99 | .setView(dialogTextView) |
98 | .show() | 100 | .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ } |
101 | .show() | ||
102 | } | ||
103 | } | ||
99 | } | 104 | } |
100 | 105 | ||
101 | fun writeNetworkInfo(cfg: VpnInterfaceConfiguration) { | 106 | fun writeNetworkInfo(cfg: VpnInterfaceConfiguration) { |
@@ -129,9 +134,10 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef | |||
129 | companion object { | 134 | companion object { |
130 | private val REFRESH_RATE = 5000L | 135 | private val REFRESH_RATE = 5000L |
131 | 136 | ||
132 | fun getNodeNames() = | 137 | fun getNodeNames(): CompletableFuture<List<String>> = when (TincVpnService.isConnected()) { |
133 | if (TincVpnService.isConnected()) Tinc.dumpNodes(TincVpnService.getCurrentNetName()!!).map { it.substringBefore(" ") } | 138 | true -> Tinc.dumpNodes(TincVpnService.getCurrentNetName()!!).thenApply<List<String>> { it.map { it.substringBefore(" ") } } |
134 | else emptyList() | 139 | false -> CompletableFuture.supplyAsync<List<String>> { emptyList() } |
140 | } | ||
135 | } | 141 | } |
136 | 142 | ||
137 | } | 143 | } |