From 22d42234b8d5570447acf874b73fb183765b27a3 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 9 Sep 2018 14:39:15 +0200 Subject: Avoid updating node and subnet lists when no daemon is running --- .../tincapp/activities/status/nodes/NodeListLiveData.kt | 13 +++++++------ .../tincapp/activities/status/nodes/NodeListViewModel.kt | 3 +-- .../tincapp/activities/status/subnets/SubnetListLiveData.kt | 13 +++++++------ .../activities/status/subnets/SubnetListViewModel.kt | 3 +-- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'app/src/main/java/org/pacien') diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListLiveData.kt b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListLiveData.kt index cada4bc..1036cc9 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListLiveData.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListLiveData.kt @@ -20,19 +20,20 @@ package org.pacien.tincapp.activities.status.nodes import org.pacien.tincapp.activities.common.SelfRefreshingLiveData import org.pacien.tincapp.commands.Tinc +import org.pacien.tincapp.service.TincVpnService import java.util.concurrent.TimeUnit /** * @author pacien */ -class NodeListLiveData(private val netName: String) : SelfRefreshingLiveData>(1, TimeUnit.SECONDS) { +class NodeListLiveData : SelfRefreshingLiveData>(1, TimeUnit.SECONDS) { + private val vpnService = TincVpnService private val tincCtl = Tinc override fun onRefresh() { - val nodeList = tincCtl.dumpNodes(netName) - .thenApply { list -> list.map { NodeInfo.ofNodeDump(it) } } - .get() - - postValue(nodeList) + vpnService.getCurrentNetName() + ?.let { netName -> tincCtl.dumpNodes(netName) } + ?.thenApply { list -> list.map { NodeInfo.ofNodeDump(it) } } + ?.thenAccept(this::postValue) } } diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListViewModel.kt b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListViewModel.kt index 560f62a..81b0aca 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListViewModel.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListViewModel.kt @@ -25,6 +25,5 @@ import org.pacien.tincapp.service.TincVpnService * @author pacien */ class NodeListViewModel : ViewModel() { - private val netName by lazy { TincVpnService.getCurrentNetName()!! } - val nodeList by lazy { NodeListLiveData(netName) } + val nodeList by lazy { NodeListLiveData() } } diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListLiveData.kt b/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListLiveData.kt index 1dbd8c3..d76badc 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListLiveData.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListLiveData.kt @@ -20,19 +20,20 @@ package org.pacien.tincapp.activities.status.subnets import org.pacien.tincapp.activities.common.SelfRefreshingLiveData import org.pacien.tincapp.commands.Tinc +import org.pacien.tincapp.service.TincVpnService import java.util.concurrent.TimeUnit /** * @author pacien */ -class SubnetListLiveData(private val netName: String) : SelfRefreshingLiveData>(1, TimeUnit.SECONDS) { +class SubnetListLiveData : SelfRefreshingLiveData>(1, TimeUnit.SECONDS) { + private val vpnService = TincVpnService private val tincCtl = Tinc override fun onRefresh() { - val subnetList = tincCtl.dumpSubnets(netName) - .thenApply { list -> list.map { SubnetInfo.ofSubnetDump(it) } } - .get() - - postValue(subnetList) + vpnService.getCurrentNetName() + ?.let { netName -> tincCtl.dumpSubnets(netName) } + ?.thenApply { list -> list.map { SubnetInfo.ofSubnetDump(it) } } + ?.thenAccept(this::postValue) } } diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListViewModel.kt b/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListViewModel.kt index 4390aad..ff0afca 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListViewModel.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListViewModel.kt @@ -25,6 +25,5 @@ import org.pacien.tincapp.service.TincVpnService * @author pacien */ class SubnetListViewModel : ViewModel() { - private val netName by lazy { TincVpnService.getCurrentNetName()!! } - val nodeList by lazy { SubnetListLiveData(netName) } + val nodeList by lazy { SubnetListLiveData() } } -- cgit v1.2.3