diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-04-28 04:45:17 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-04-28 04:51:43 +0200 |
commit | 63071f57b7b501c23843f502a5d2a1ac83338bc7 (patch) | |
tree | 21a9a0f4de77b67669949534c27e033d1ee896c3 /app/src/main/res | |
parent | 693228985df3aab03a53d9ae68aed7d309c4f6bd (diff) |
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>
Diffstat (limited to 'app/src/main/res')
-rw-r--r-- | app/src/main/res/layout/tunnel_detail_fragment.xml | 26 | ||||
-rw-r--r-- | app/src/main/res/layout/tunnel_detail_peer.xml | 10 | ||||
-rw-r--r-- | app/src/main/res/layout/tunnel_editor_fragment.xml | 24 | ||||
-rw-r--r-- | app/src/main/res/layout/tunnel_editor_peer.xml | 10 |
4 files changed, 42 insertions, 28 deletions
diff --git a/app/src/main/res/layout/tunnel_detail_fragment.xml b/app/src/main/res/layout/tunnel_detail_fragment.xml index 900d08ed..971d8784 100644 --- a/app/src/main/res/layout/tunnel_detail_fragment.xml +++ b/app/src/main/res/layout/tunnel_detail_fragment.xml @@ -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> diff --git a/app/src/main/res/layout/tunnel_detail_peer.xml b/app/src/main/res/layout/tunnel_detail_peer.xml index bde89390..d2240e31 100644 --- a/app/src/main/res/layout/tunnel_detail_peer.xml +++ b/app/src/main/res/layout/tunnel_detail_peer.xml @@ -6,12 +6,8 @@ <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> diff --git a/app/src/main/res/layout/tunnel_editor_fragment.xml b/app/src/main/res/layout/tunnel_editor_fragment.xml index 0d278bcb..4d56ee3e 100644 --- a/app/src/main/res/layout/tunnel_editor_fragment.xml +++ b/app/src/main/res/layout/tunnel_editor_fragment.xml @@ -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> diff --git a/app/src/main/res/layout/tunnel_editor_peer.xml b/app/src/main/res/layout/tunnel_editor_peer.xml index cc5fe933..b6caab8a 100644 --- a/app/src/main/res/layout/tunnel_editor_peer.xml +++ b/app/src/main/res/layout/tunnel_editor_peer.xml @@ -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> |