Use validation instead of two-way binding
This is insane, but it appears to be working. We essentially store things in a separate class for editing, and then commit it back at a given time. This business with onViewStateRestored in both TunnelEditorFragment and in TunnelDetailFragment is buggy and likely wrong. In general TunnelEditorFragment should probably be rewritten. The relationship with the changed name is not clear. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -14,6 +14,10 @@
|
||||
<variable
|
||||
name="tunnel"
|
||||
type="com.wireguard.android.model.Tunnel" />
|
||||
|
||||
<variable
|
||||
name="config"
|
||||
type="com.wireguard.config.Config.Observable" />
|
||||
</data>
|
||||
|
||||
<ScrollView
|
||||
@@ -92,7 +96,25 @@
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:onClick="@{ClipboardUtils::copyTextView}"
|
||||
android:text="@{tunnel.config.interface.publicKey}" />
|
||||
android:text="@{config.interfaceSection.publicKey}" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/addresses_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/public_key_text"
|
||||
android:layout_marginTop="8dp"
|
||||
android:labelFor="@+id/addresses_text"
|
||||
android:text="@string/addresses" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/addresses_text"
|
||||
style="?android:attr/textAppearanceMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/addresses_label"
|
||||
android:contentDescription="@string/addresses"
|
||||
android:text="@{config.interfaceSection.addresses}" />
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
@@ -101,7 +123,7 @@
|
||||
android:layout_marginBottom="4dp"
|
||||
android:divider="@null"
|
||||
android:orientation="vertical"
|
||||
app:items="@{tunnel.config.peers}"
|
||||
app:items="@{config.peers}"
|
||||
app:layout="@{@layout/tunnel_detail_peer}"
|
||||
tools:ignore="UselessLeaf" />
|
||||
</LinearLayout>
|
||||
|
||||
@@ -5,13 +5,9 @@
|
||||
|
||||
<import type="com.wireguard.android.util.ClipboardUtils" />
|
||||
|
||||
<variable
|
||||
name="collection"
|
||||
type="android.databinding.ObservableList<com.wireguard.config.Peer>" />
|
||||
|
||||
<variable
|
||||
name="item"
|
||||
type="com.wireguard.config.Peer" />
|
||||
type="com.wireguard.config.Peer.Observable" />
|
||||
</data>
|
||||
|
||||
<RelativeLayout
|
||||
@@ -69,7 +65,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/allowed_ips_label"
|
||||
android:text="@{item.allowedIPsString}" />
|
||||
android:text="@{item.allowedIPs}" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/endpoint_label"
|
||||
@@ -86,6 +82,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/endpoint_label"
|
||||
android:text="@{item.endpointString}" />
|
||||
android:text="@{item.endpoint}" />
|
||||
</RelativeLayout>
|
||||
</layout>
|
||||
|
||||
@@ -15,11 +15,7 @@
|
||||
|
||||
<variable
|
||||
name="config"
|
||||
type="com.wireguard.config.Config" />
|
||||
|
||||
<variable
|
||||
name="name"
|
||||
type="android.databinding.ObservableField<String>" />
|
||||
type="com.wireguard.config.Config.Observable" />
|
||||
</data>
|
||||
|
||||
<com.commonsware.cwac.crossport.design.widget.CoordinatorLayout
|
||||
@@ -71,7 +67,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/interface_name_label"
|
||||
android:inputType="textNoSuggestions|textVisiblePassword"
|
||||
android:text="@={name}"
|
||||
android:text="@={config.name}"
|
||||
app:filter="@{NameInputFilter.newInstance()}" />
|
||||
|
||||
<TextView
|
||||
@@ -91,7 +87,7 @@
|
||||
android:layout_toStartOf="@+id/generate_private_key_button"
|
||||
android:contentDescription="@string/public_key_description"
|
||||
android:inputType="textNoSuggestions|textVisiblePassword"
|
||||
android:text="@={config.interface.privateKey}"
|
||||
android:text="@={config.interfaceSection.privateKey}"
|
||||
app:filter="@{KeyInputFilter.newInstance()}" />
|
||||
|
||||
<Button
|
||||
@@ -101,7 +97,7 @@
|
||||
android:layout_alignBottom="@id/private_key_text"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_below="@+id/private_key_label"
|
||||
android:onClick="@{() -> config.interface.generateKeypair()}"
|
||||
android:onClick="@{() -> config.interfaceSection.generateKeypair()}"
|
||||
android:text="@string/generate" />
|
||||
|
||||
<TextView
|
||||
@@ -124,7 +120,7 @@
|
||||
android:maxLines="1"
|
||||
android:contentDescription="@string/public_key_description"
|
||||
android:onClick="@{ClipboardUtils::copyTextView}"
|
||||
android:text="@{config.interface.publicKey}" />
|
||||
android:text="@{config.interfaceSection.publicKey}" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/addresses_label"
|
||||
@@ -144,7 +140,7 @@
|
||||
android:layout_below="@+id/addresses_label"
|
||||
android:layout_toStartOf="@+id/listen_port_text"
|
||||
android:inputType="textNoSuggestions|textVisiblePassword"
|
||||
android:text="@={config.interface.addressString}" />
|
||||
android:text="@={config.interfaceSection.addresses}" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/listen_port_label"
|
||||
@@ -165,7 +161,7 @@
|
||||
android:layout_alignStart="@+id/generate_private_key_button"
|
||||
android:hint="@string/hint_random"
|
||||
android:inputType="number"
|
||||
android:text="@={config.interface.listenPortString}"
|
||||
android:text="@={config.interfaceSection.listenPort}"
|
||||
android:textAlignment="center" />
|
||||
|
||||
<TextView
|
||||
@@ -186,7 +182,7 @@
|
||||
android:layout_below="@+id/dns_servers_label"
|
||||
android:layout_toStartOf="@+id/mtu_text"
|
||||
android:inputType="textNoSuggestions|textVisiblePassword"
|
||||
android:text="@={config.interface.dnsString}" />
|
||||
android:text="@={config.interfaceSection.dnses}" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/mtu_label"
|
||||
@@ -207,7 +203,7 @@
|
||||
android:layout_alignStart="@+id/generate_private_key_button"
|
||||
android:hint="@string/hint_automatic"
|
||||
android:inputType="number"
|
||||
android:text="@={config.interface.mtuString}"
|
||||
android:text="@={config.interfaceSection.mtu}"
|
||||
android:textAlignment="center" />
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -226,7 +222,7 @@
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:onClick="@{() -> config.peers.add(Peer.newInstance())}"
|
||||
android:onClick="@{() -> config.peers.add(Peer.Observable.newInstance())}"
|
||||
android:text="@string/add_peer" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
<variable
|
||||
name="collection"
|
||||
type="android.databinding.ObservableList<com.wireguard.config.Peer>" />
|
||||
type="android.databinding.ObservableList<com.wireguard.config.Peer.Observable>" />
|
||||
|
||||
<variable
|
||||
name="item"
|
||||
type="com.wireguard.config.Peer" />
|
||||
type="com.wireguard.config.Peer.Observable" />
|
||||
</data>
|
||||
|
||||
<RelativeLayout
|
||||
@@ -96,7 +96,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/allowed_ips_label"
|
||||
android:inputType="textNoSuggestions|textVisiblePassword"
|
||||
android:text="@={item.allowedIPsString}" />
|
||||
android:text="@={item.allowedIPs}" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/endpoint_label"
|
||||
@@ -116,7 +116,7 @@
|
||||
android:layout_below="@+id/endpoint_label"
|
||||
android:layout_toStartOf="@+id/persistent_keepalive_text"
|
||||
android:inputType="textNoSuggestions|textVisiblePassword"
|
||||
android:text="@={item.endpointString}" />
|
||||
android:text="@={item.endpoint}" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/persistent_keepalive_label"
|
||||
@@ -136,7 +136,7 @@
|
||||
android:layout_alignStart="@+id/persistent_keepalive_label"
|
||||
android:hint="@string/hint_optional"
|
||||
android:inputType="number"
|
||||
android:text="@={item.persistentKeepaliveString}"
|
||||
android:text="@={item.persistentKeepalive}"
|
||||
android:textAlignment="center" />
|
||||
</RelativeLayout>
|
||||
</layout>
|
||||
|
||||
Reference in New Issue
Block a user