From ea92a3f0797509d8f33833b00b5b5ae115b5d4d6 Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 1 Aug 2018 16:19:29 +0200 Subject: Fix node info display race condition --- .../pacien/tincapp/activities/StatusActivity.kt | 34 +++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'app/src/main/java/org') 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 8ea62cb..a7a1853 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt @@ -113,19 +113,9 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef refreshTimer?.schedule(timerTask { updateView() }, NOW) } - override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { - val nodeName = (view as TextView).text.toString() - val dialogTextView = layoutInflater.inflate(R.layout.dialog_node_details, main_content, false) - Tinc.info(TincVpnService.getCurrentNetName()!!, nodeName).thenAccept { - runOnUiThread { - dialogTextView.dialog_node_details.text = it - AlertDialog.Builder(this) - .setTitle(R.string.title_node_info) - .setView(dialogTextView) - .setPositiveButton(R.string.action_close) { _, _ -> Unit } - .show() - } - } + override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) = when (view) { + is TextView -> showNodeInfo(view.text.toString()) + else -> Unit } private fun onVpnShutdown() { @@ -167,6 +157,24 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef getNodeNames().thenAccept { nodeList -> runOnUiThread { writeNodeList(nodeList) } } } + private fun showNodeInfo(nodeName: String) { + val dialogTextView = layoutInflater.inflate(R.layout.dialog_node_details, main_content, false) + + runOnUiThread { + AlertDialog.Builder(this) + .setTitle(R.string.title_node_info) + .setView(dialogTextView) + .setPositiveButton(R.string.action_close) { _, _ -> Unit } + .show() + } + + TincVpnService.getCurrentNetName()?.let { netName -> + Tinc.info(netName, nodeName).thenAccept { nodeInfo -> + runOnUiThread { dialogTextView.dialog_node_details.text = nodeInfo } + } + } + } + private fun updateView() = when { TincVpnService.isConnected() -> updateNodeList() else -> openStartActivity() -- cgit v1.2.3