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 +++++++++++++--------- app/src/main/res/layout/dialog_node_details.xml | 3 +- 2 files changed, 23 insertions(+), 14 deletions(-) (limited to 'app') 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() diff --git a/app/src/main/res/layout/dialog_node_details.xml b/app/src/main/res/layout/dialog_node_details.xml index 5d8a5f7..75d8f4c 100644 --- a/app/src/main/res/layout/dialog_node_details.xml +++ b/app/src/main/res/layout/dialog_node_details.xml @@ -28,6 +28,7 @@ android:id="@+id/dialog_node_details" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fontFamily="monospace"/> + android:fontFamily="monospace" + android:text="@string/message_loading"/> -- cgit v1.2.3