aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org
diff options
context:
space:
mode:
authorpacien2018-09-09 14:39:15 +0200
committerpacien2018-09-09 14:39:15 +0200
commit22d42234b8d5570447acf874b73fb183765b27a3 (patch)
tree525973cb798c8270166ebbf0de7ec86702ae1ab6 /app/src/main/java/org
parent4c1144bc103a74d8fbdef79b3eb6c69c3e723b83 (diff)
downloadtincapp-22d42234b8d5570447acf874b73fb183765b27a3.tar.gz
Avoid updating node and subnet lists when no daemon is running
Diffstat (limited to 'app/src/main/java/org')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListLiveData.kt13
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListViewModel.kt3
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListLiveData.kt13
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListViewModel.kt3
4 files changed, 16 insertions, 16 deletions
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
20 20
21import org.pacien.tincapp.activities.common.SelfRefreshingLiveData 21import org.pacien.tincapp.activities.common.SelfRefreshingLiveData
22import org.pacien.tincapp.commands.Tinc 22import org.pacien.tincapp.commands.Tinc
23import org.pacien.tincapp.service.TincVpnService
23import java.util.concurrent.TimeUnit 24import java.util.concurrent.TimeUnit
24 25
25/** 26/**
26 * @author pacien 27 * @author pacien
27 */ 28 */
28class NodeListLiveData(private val netName: String) : SelfRefreshingLiveData<List<NodeInfo>>(1, TimeUnit.SECONDS) { 29class NodeListLiveData : SelfRefreshingLiveData<List<NodeInfo>>(1, TimeUnit.SECONDS) {
30 private val vpnService = TincVpnService
29 private val tincCtl = Tinc 31 private val tincCtl = Tinc
30 32
31 override fun onRefresh() { 33 override fun onRefresh() {
32 val nodeList = tincCtl.dumpNodes(netName) 34 vpnService.getCurrentNetName()
33 .thenApply { list -> list.map { NodeInfo.ofNodeDump(it) } } 35 ?.let { netName -> tincCtl.dumpNodes(netName) }
34 .get() 36 ?.thenApply { list -> list.map { NodeInfo.ofNodeDump(it) } }
35 37 ?.thenAccept(this::postValue)
36 postValue(nodeList)
37 } 38 }
38} 39}
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
25 * @author pacien 25 * @author pacien
26 */ 26 */
27class NodeListViewModel : ViewModel() { 27class NodeListViewModel : ViewModel() {
28 private val netName by lazy { TincVpnService.getCurrentNetName()!! } 28 val nodeList by lazy { NodeListLiveData() }
29 val nodeList by lazy { NodeListLiveData(netName) }
30} 29}
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
20 20
21import org.pacien.tincapp.activities.common.SelfRefreshingLiveData 21import org.pacien.tincapp.activities.common.SelfRefreshingLiveData
22import org.pacien.tincapp.commands.Tinc 22import org.pacien.tincapp.commands.Tinc
23import org.pacien.tincapp.service.TincVpnService
23import java.util.concurrent.TimeUnit 24import java.util.concurrent.TimeUnit
24 25
25/** 26/**
26 * @author pacien 27 * @author pacien
27 */ 28 */
28class SubnetListLiveData(private val netName: String) : SelfRefreshingLiveData<List<SubnetInfo>>(1, TimeUnit.SECONDS) { 29class SubnetListLiveData : SelfRefreshingLiveData<List<SubnetInfo>>(1, TimeUnit.SECONDS) {
30 private val vpnService = TincVpnService
29 private val tincCtl = Tinc 31 private val tincCtl = Tinc
30 32
31 override fun onRefresh() { 33 override fun onRefresh() {
32 val subnetList = tincCtl.dumpSubnets(netName) 34 vpnService.getCurrentNetName()
33 .thenApply { list -> list.map { SubnetInfo.ofSubnetDump(it) } } 35 ?.let { netName -> tincCtl.dumpSubnets(netName) }
34 .get() 36 ?.thenApply { list -> list.map { SubnetInfo.ofSubnetDump(it) } }
35 37 ?.thenAccept(this::postValue)
36 postValue(subnetList)
37 } 38 }
38} 39}
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
25 * @author pacien 25 * @author pacien
26 */ 26 */
27class SubnetListViewModel : ViewModel() { 27class SubnetListViewModel : ViewModel() {
28 private val netName by lazy { TincVpnService.getCurrentNetName()!! } 28 val nodeList by lazy { SubnetListLiveData() }
29 val nodeList by lazy { SubnetListLiveData(netName) }
30} 29}