summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2021-03-15 22:39:56 +0000
committerMikael Magnusson <mikma@users.sourceforge.net>2023-02-07 22:43:23 +0100
commit279e9297b9700c6db9cef22d86755f5f8337ad35 (patch)
tree3ef226c1c23c9e37ea2918c7a110098d517de443 /ui/src/main/java/com
parent421bae85375dbef7fb64759eae22134d3c42a1fe (diff)
WIP: add dhcp information to detail
Diffstat (limited to 'ui/src/main/java/com')
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt4
-rw-r--r--ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt30
-rw-r--r--ui/src/main/java/com/wireguard/android/model/TunnelManager.kt5
3 files changed, 39 insertions, 0 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt
index 7046cb96..1f0eca5d 100644
--- a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt
+++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt
@@ -100,6 +100,10 @@ class TunnelDetailFragment : BaseFragment() {
if (state != Tunnel.State.UP && lastState == state) return
lastState = state
try {
+ binding.dhcpInfoText.text = tunnel.getDhcpInfo().get()
+ binding.dhcpInfoLabel.visibility = View.VISIBLE
+ binding.dhcpInfoText.visibility = View.VISIBLE
+
val statistics = tunnel.getStatisticsAsync()
for (i in 0 until binding.peersLayout.childCount) {
val peer: TunnelDetailPeerBinding = DataBindingUtil.getBinding(binding.peersLayout.getChildAt(i))
diff --git a/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt b/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt
index 252e8759..edf8feaf 100644
--- a/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt
+++ b/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt
@@ -8,6 +8,7 @@ import android.util.Log
import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import com.wireguard.android.BR
+import com.wireguard.android.backend.DhcpInfo
import com.wireguard.android.backend.Statistics
import com.wireguard.android.backend.Tunnel
import com.wireguard.android.databinding.Keyed
@@ -136,6 +137,35 @@ class ObservableTunnel internal constructor(
return statistics
}
+ @get:Bindable
+ var dhcpInfo: DhcpInfo? = null
+ get() {
+ if (field == null || field?.isStale != false)
+ applicationScope.launch {
+ try {
+ manager.getTunnelDhcpInfo(this@ObservableTunnel)
+ } catch (e: Throwable) {
+ Log.e(TAG, Log.getStackTraceString(e))
+ }
+ }
+ return field
+ }
+ private set
+
+ suspend fun getDhcpInfo(): DhcpInfo = withContext(Dispatchers.Main.immediate) {
+ dhcpInfo.let {
+ if (it == null || it.isStale)
+ manager.getTunnelDhcpInfo(this@ObservableTunnel)
+ else
+ it
+ }
+ }
+
+ fun onDhcpInfoChanged(dhcpInfo: DhcpInfo?): DhcpInfo? {
+ this.dhcpInfo = dhcpInfo
+ notifyPropertyChanged(BR.dhcpInfo)
+ return dhcpInfo
+ }
suspend fun deleteAsync() = manager.delete(this)
diff --git a/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt b/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt
index ec796164..ac39ac4a 100644
--- a/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt
+++ b/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt
@@ -17,6 +17,7 @@ import com.wireguard.android.Application.Companion.getBackend
import com.wireguard.android.Application.Companion.getTunnelManager
import com.wireguard.android.BR
import com.wireguard.android.R
+import com.wireguard.android.backend.DhcpInfo
import com.wireguard.android.backend.Statistics
import com.wireguard.android.backend.Tunnel
import com.wireguard.android.configStore.ConfigStore
@@ -240,6 +241,10 @@ class TunnelManager(private val configStore: ConfigStore) : BaseObservable() {
}
}
+ suspend fun getTunnelDhcpInfo(tunnel: ObservableTunnel): DhcpInfo = withContext(Dispatchers.Main.immediate) {
+ tunnel.onDhcpInfoChanged(withContext(Dispatchers.IO) { getBackend().getDhcpInfo(tunnel) })!!
+ }
+
suspend fun getTunnelState(tunnel: ObservableTunnel): Tunnel.State = withContext(Dispatchers.Main.immediate) {
tunnel.onStateChanged(withContext(Dispatchers.IO) { getBackend().getState(tunnel) })
}