diff options
author | Samuel Holland <samuel@sholland.org> | 2018-09-05 20:17:14 -0500 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-12-08 02:39:41 +0100 |
commit | d1e85633fbe8d871355d2b9feb51e2c9983d8a21 (patch) | |
tree | d95ad1ae84d02fc3e18a211aa1e1ef8150d8fa35 /app/src/main/res | |
parent | a264f7ab36bf1335999d53cb4a0d753c54b231d0 (diff) |
Remodel the Model
- The configuration and crypto model is now entirely independent
of Android classes other than Nullable and TextUtils.
- Model classes are immutable and use builders that enforce the
appropriate optional/required attributes.
- The Android config proxies (for Parcelable and databinding) are
moved to the Android side of the codebase, and are designed to be
safe for two-way databinding. This allows proper observability in
TunnelDetailFragment.
- Various robustness fixes and documentation updates to helper classes.
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 | 6 | ||||
-rw-r--r-- | app/src/main/res/layout/tunnel_detail_peer.xml | 6 | ||||
-rw-r--r-- | app/src/main/res/layout/tunnel_editor_fragment.xml | 28 | ||||
-rw-r--r-- | app/src/main/res/layout/tunnel_editor_peer.xml | 13 | ||||
-rw-r--r-- | app/src/main/res/layout/tunnel_list_fragment.xml | 3 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 5 |
6 files changed, 29 insertions, 32 deletions
diff --git a/app/src/main/res/layout/tunnel_detail_fragment.xml b/app/src/main/res/layout/tunnel_detail_fragment.xml index 11cfafae..9b06ddd4 100644 --- a/app/src/main/res/layout/tunnel_detail_fragment.xml +++ b/app/src/main/res/layout/tunnel_detail_fragment.xml @@ -19,7 +19,7 @@ <variable name="config" - type="com.wireguard.config.Config.Observable" /> + type="com.wireguard.config.Config" /> </data> <ScrollView @@ -102,7 +102,7 @@ android:ellipsize="end" android:maxLines="1" android:onClick="@{ClipboardUtils::copyTextView}" - android:text="@{config.interfaceSection.publicKey}" /> + android:text="@{config.interface.keyPair.publicKey.toBase64}" /> <TextView android:id="@+id/addresses_label" @@ -120,7 +120,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/addresses_label" android:contentDescription="@string/addresses" - android:text="@{config.interfaceSection.addresses}" /> + android:text="@{config.interface.addresses}" /> </RelativeLayout> </android.support.v7.widget.CardView> diff --git a/app/src/main/res/layout/tunnel_detail_peer.xml b/app/src/main/res/layout/tunnel_detail_peer.xml index 91be0011..767e0383 100644 --- a/app/src/main/res/layout/tunnel_detail_peer.xml +++ b/app/src/main/res/layout/tunnel_detail_peer.xml @@ -8,7 +8,7 @@ <variable name="item" - type="com.wireguard.config.Peer.Observable" /> + type="com.wireguard.config.Peer" /> </data> <android.support.v7.widget.CardView @@ -54,7 +54,7 @@ android:ellipsize="end" android:maxLines="1" android:onClick="@{ClipboardUtils::copyTextView}" - android:text="@{item.publicKey}" /> + android:text="@{item.publicKey.toBase64}" /> <TextView android:id="@+id/allowed_ips_label" @@ -71,7 +71,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/allowed_ips_label" - android:text="@{item.allowedIPs}" /> + android:text="@{item.allowedIps}" /> <TextView android:id="@+id/endpoint_label" diff --git a/app/src/main/res/layout/tunnel_editor_fragment.xml b/app/src/main/res/layout/tunnel_editor_fragment.xml index f7976459..3945fffc 100644 --- a/app/src/main/res/layout/tunnel_editor_fragment.xml +++ b/app/src/main/res/layout/tunnel_editor_fragment.xml @@ -11,15 +11,17 @@ <import type="com.wireguard.android.widget.NameInputFilter" /> - <import type="com.wireguard.config.Peer" /> - <variable name="fragment" type="com.wireguard.android.fragment.TunnelEditorFragment" /> <variable name="config" - type="com.wireguard.config.Config.Observable" /> + type="com.wireguard.android.viewmodel.ConfigProxy" /> + + <variable + name="name" + type="String" /> </data> <android.support.design.widget.CoordinatorLayout @@ -76,7 +78,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/interface_name_label" android:inputType="textNoSuggestions|textVisiblePassword" - android:text="@={config.name}" + android:text="@={name}" app:filter="@{NameInputFilter.newInstance()}" /> <TextView @@ -96,7 +98,7 @@ android:layout_toStartOf="@+id/generate_private_key_button" android:contentDescription="@string/public_key_description" android:inputType="textNoSuggestions|textVisiblePassword" - android:text="@={config.interfaceSection.privateKey}" + android:text="@={config.interface.privateKey}" app:filter="@{KeyInputFilter.newInstance()}" /> <Button @@ -107,7 +109,7 @@ android:layout_alignBottom="@id/private_key_text" android:layout_alignParentEnd="true" android:layout_below="@+id/private_key_label" - android:onClick="@{() -> config.interfaceSection.generateKeypair()}" + android:onClick="@{() -> config.interface.generateKeyPair()}" android:text="@string/generate" /> <TextView @@ -130,7 +132,7 @@ android:hint="@string/hint_generated" android:maxLines="1" android:onClick="@{ClipboardUtils::copyTextView}" - android:text="@{config.interfaceSection.publicKey}" /> + android:text="@{config.interface.publicKey}" /> <TextView android:id="@+id/addresses_label" @@ -150,7 +152,7 @@ android:layout_below="@+id/addresses_label" android:layout_toStartOf="@+id/listen_port_text" android:inputType="textNoSuggestions|textVisiblePassword" - android:text="@={config.interfaceSection.addresses}" /> + android:text="@={config.interface.addresses}" /> <TextView android:id="@+id/listen_port_label" @@ -171,7 +173,7 @@ android:layout_alignStart="@+id/generate_private_key_button" android:hint="@string/hint_random" android:inputType="number" - android:text="@={config.interfaceSection.listenPort}" + android:text="@={config.interface.listenPort}" android:textAlignment="center" /> <TextView @@ -192,7 +194,7 @@ android:layout_below="@+id/dns_servers_label" android:layout_toStartOf="@+id/mtu_text" android:inputType="textNoSuggestions|textVisiblePassword" - android:text="@={config.interfaceSection.dnses}" /> + android:text="@={config.interface.dnsServers}" /> <TextView android:id="@+id/mtu_label" @@ -213,7 +215,7 @@ android:layout_alignStart="@+id/generate_private_key_button" android:hint="@string/hint_automatic" android:inputType="number" - android:text="@={config.interfaceSection.mtu}" + android:text="@={config.interface.mtu}" android:textAlignment="center" /> <Button @@ -224,7 +226,7 @@ android:layout_below="@+id/dns_servers_text" android:layout_marginLeft="-8dp" android:onClick="@{fragment::onRequestSetExcludedApplications}" - android:text="@{@plurals/set_excluded_applications(config.interfaceSection.excludedApplicationsCount, config.interfaceSection.excludedApplicationsCount)}" /> + android:text="@{@plurals/set_excluded_applications(config.interface.excludedApplications.size, config.interface.excludedApplications.size)}" /> </RelativeLayout> </android.support.v7.widget.CardView> @@ -244,7 +246,7 @@ android:layout_marginBottom="4dp" android:layout_marginEnd="4dp" android:layout_marginStart="4dp" - android:onClick="@{() -> config.peers.add(Peer.Observable.newInstance())}" + android:onClick="@{() -> config.addPeer()}" 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 e270b71a..1224ddd3 100644 --- a/app/src/main/res/layout/tunnel_editor_peer.xml +++ b/app/src/main/res/layout/tunnel_editor_peer.xml @@ -10,11 +10,11 @@ <variable name="collection" - type="android.databinding.ObservableList<com.wireguard.config.Peer.Observable>" /> + type="android.databinding.ObservableList<com.wireguard.android.viewmodel.PeerProxy>" /> <variable name="item" - type="com.wireguard.config.Peer.Observable" /> + type="com.wireguard.android.viewmodel.PeerProxy" /> </data> <android.support.v7.widget.CardView @@ -52,7 +52,7 @@ android:layout_alignParentTop="true" android:background="@null" android:contentDescription="@string/delete" - android:onClick="@{() -> collection.remove(item)}" + android:onClick="@{() -> item.unbind()}" android:src="@drawable/ic_action_delete" /> <TextView @@ -104,10 +104,9 @@ android:layout_height="wrap_content" android:layout_alignBaseline="@+id/allowed_ips_label" android:layout_alignParentEnd="true" - android:checked="@{item.isExcludePrivateIPsOn}" - android:onClick="@{() -> item.toggleExcludePrivateIPs()}" + android:checked="@={item.excludingPrivateIps}" android:text="@string/exclude_private_ips" - android:visibility="@{item.canToggleExcludePrivateIPs ? View.VISIBLE : View.GONE}" /> + android:visibility="@{item.ableToExcludePrivateIps ? View.VISIBLE : View.GONE}" /> <EditText android:id="@+id/allowed_ips_text" @@ -115,7 +114,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/allowed_ips_label" android:inputType="textNoSuggestions|textVisiblePassword" - android:text="@={item.allowedIPs}" /> + android:text="@={item.allowedIps}" /> <TextView android:id="@+id/endpoint_label" diff --git a/app/src/main/res/layout/tunnel_list_fragment.xml b/app/src/main/res/layout/tunnel_list_fragment.xml index ccc1c5ae..d255005a 100644 --- a/app/src/main/res/layout/tunnel_list_fragment.xml +++ b/app/src/main/res/layout/tunnel_list_fragment.xml @@ -84,7 +84,7 @@ app:srcCompat="@drawable/ic_action_open_white" /> <com.wireguard.android.widget.fab.LabeledFloatingActionButton - android:id="@+id/scan_qr_code" + android:id="@+id/create_from_qrcode" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="@{fragment::onRequestScanQRCode}" @@ -101,6 +101,5 @@ app:fab_title="@string/create_empty" app:srcCompat="@drawable/ic_action_edit_white" /> </com.wireguard.android.widget.fab.FloatingActionsMenu> - </android.support.design.widget.CoordinatorLayout> </layout> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 87ea18f5..6202ee78 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,6 +63,7 @@ <string name="log_export_summary">Log file will be saved to downloads folder</string> <string name="mtu">MTU</string> <string name="name">Name</string> + <string name="parse_error">Cannot parse “%s” at %s</string> <string name="peer">Peer</string> <string name="permission_label">control WireGuard tunnels</string> <string name="permission_description">Allows an app to control WireGuard tunnels. Apps with this permission may enable and disable WireGuard tunnels at will, potentially misdirecting Internet traffic.</string> @@ -99,13 +100,9 @@ <string name="tunnel_rename_success">Successfully renamed tunnel to “%s”</string> <string name="tunnel_error_invalid_name">Invalid name</string> <string name="tunnel_error_already_exists">Tunnel %s already exists</string> - <string name="tunnel_error_empty_inetaddress">Empty address</string> <string name="tunnel_error_empty_interface_address">Address is empty</string> - <string name="tunnel_error_interface_parse_failed">Unable to parse line: “%s”</string> <string name="tunnel_error_forbidden_endpoint_chars">Forbidden characters in endpoint</string> <string name="tunnel_error_empty_peer_public_key">Peer public key may not be empty</string> - <string name="tunnel_error_invalid_config_line">Invalid configuration line: %s</string> - <string name="tunnel_error_no_config_information">Could not find any config information</string> <string name="key_length_base64_exception_message">WireGuard base64 keys must be 44 characters encoding 32 bytes</string> <string name="key_length_exception_message">WireGuard keys must be 32 bytes</string> <string name="key_length_hex_exception_message">WireGuard hex keys must be 64 characters encoding 32 bytes</string> |