summaryrefslogtreecommitdiffhomepage
path: root/ui
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-04-06 18:24:08 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-04-06 18:24:08 -0600
commit4bbb1a0fcdc32e1629436acf58437779f5789f3e (patch)
treeb0d9f478d2aebb852772e794101e2ffb9191fa2f /ui
parent77b5937fbb8490b368acac85f434113a175f1bba (diff)
ui: add suffix to persistent keepalive in editor
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt11
-rw-r--r--ui/src/main/res/layout/tunnel_editor_peer.xml5
-rw-r--r--ui/src/main/res/values/strings.xml4
3 files changed, 19 insertions, 1 deletions
diff --git a/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt b/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt
index fe828004..055c2f06 100644
--- a/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt
+++ b/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt
@@ -151,4 +151,15 @@ object BindingAdapters {
fun setInetAddressSetText(view: TextView, addresses: Iterable<InetAddress?>?) {
view.text = if (addresses != null) Attribute.join(addresses.map { it?.hostAddress }) else ""
}
+
+ @JvmStatic
+ fun tryParseInt(s: String?): Int {
+ if (s == null)
+ return 0
+ return try {
+ Integer.parseInt(s)
+ } catch (_: Exception) {
+ 0
+ }
+ }
}
diff --git a/ui/src/main/res/layout/tunnel_editor_peer.xml b/ui/src/main/res/layout/tunnel_editor_peer.xml
index f4d64e23..88c9044b 100644
--- a/ui/src/main/res/layout/tunnel_editor_peer.xml
+++ b/ui/src/main/res/layout/tunnel_editor_peer.xml
@@ -8,6 +8,8 @@
<import type="com.wireguard.android.widget.KeyInputFilter" />
+ <import type="com.wireguard.android.databinding.BindingAdapters" />
+
<variable
name="collection"
type="androidx.databinding.ObservableList&lt;com.wireguard.android.viewmodel.PeerProxy&gt;" />
@@ -104,6 +106,7 @@
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:hint="@string/persistent_keepalive"
+ app:suffixText="@{@plurals/persistent_keepalive_seconds_suffix(BindingAdapters.tryParseInt(item.persistentKeepalive))}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/pre_shared_key_label_layout">
@@ -114,7 +117,7 @@
android:layout_height="wrap_content"
android:hint="@string/hint_optional_discouraged"
android:inputType="number"
- android:text="@={item.persistentKeepalive}" />
+ android:text="@={item.persistentKeepalive}"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml
index 41bb31ac..5539b24a 100644
--- a/ui/src/main/res/values/strings.xml
+++ b/ui/src/main/res/values/strings.xml
@@ -43,6 +43,10 @@
<item quantity="one">every second</item>
<item quantity="other">every %d seconds</item>
</plurals>
+ <plurals name="persistent_keepalive_seconds_suffix">
+ <item quantity="one">second</item>
+ <item quantity="other">seconds</item>
+ </plurals>
<string name="use_all_applications">Use all apps</string>
<string name="add_peer">Add peer</string>
<string name="addresses">Addresses</string>