aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarsh Shandilya <harsh@prjkt.io>2018-08-01 03:00:58 +0530
committerHarsh Shandilya <harsh@prjkt.io>2018-08-01 20:53:16 +0530
commit8e9e9b31507ab536c4b8454eac8409e5d56de082 (patch)
tree9e283594ae667b018d63c40ca91af4161d1fffeb
parentSort dependencies (diff)
downloadwireguard-android-hs/realtime-validation.tar.xz
wireguard-android-hs/realtime-validation.zip
TunnelEditor: Start validating things in real-timehs/realtime-validation
Only handles names for now Signed-off-by: Harsh Shandilya <harsh@prjkt.io>
-rw-r--r--app/build.gradle2
-rw-r--r--app/src/main/java/com/wireguard/android/Application.java3
-rw-r--r--app/src/main/java/com/wireguard/android/model/Tunnel.java2
-rw-r--r--app/src/main/java/com/wireguard/config/Config.java22
-rw-r--r--app/src/main/res/layout/tunnel_editor_fragment.xml5
5 files changed, 25 insertions, 9 deletions
diff --git a/app/build.gradle b/app/build.gradle
index e8b5ce8..2c28284 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -71,6 +71,7 @@ ext {
jsr305Version = '3.0.2'
zxingEmbeddedVersion = '3.6.0'
acraVersion = '5.2.0-rc2'
+ valiFiVersion = '1.3.4'
}
dependencies {
@@ -82,6 +83,7 @@ dependencies {
implementation "com.android.support:support-annotations:$supportLibsVersion"
implementation "com.google.code.findbugs:jsr305:$jsr305Version"
implementation "com.journeyapps:zxing-android-embedded:$zxingEmbeddedVersion"
+ implementation "com.mlykotom:valifi:$valiFiVersion"
implementation "net.sourceforge.streamsupport:android-retrofuture:$streamsupportVersion"
implementation "net.sourceforge.streamsupport:android-retrostreams:$streamsupportVersion"
implementation "ch.acra:acra-http:$acraVersion"
diff --git a/app/src/main/java/com/wireguard/android/Application.java b/app/src/main/java/com/wireguard/android/Application.java
index 72545eb..dc3009c 100644
--- a/app/src/main/java/com/wireguard/android/Application.java
+++ b/app/src/main/java/com/wireguard/android/Application.java
@@ -18,6 +18,7 @@ import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDelegate;
+import com.mlykotom.valifi.ValiFi;
import com.wireguard.android.backend.Backend;
import com.wireguard.android.backend.GoBackend;
import com.wireguard.android.backend.WgQuickBackend;
@@ -169,6 +170,8 @@ public class Application extends android.app.Application {
public void onCreate() {
super.onCreate();
+ ValiFi.install(this);
+
asyncWorker = new AsyncWorker(AsyncTask.SERIAL_EXECUTOR, new Handler(Looper.getMainLooper()));
rootShell = new RootShell(getApplicationContext());
toolsInstaller = new ToolsInstaller(getApplicationContext());
diff --git a/app/src/main/java/com/wireguard/android/model/Tunnel.java b/app/src/main/java/com/wireguard/android/model/Tunnel.java
index b0d2c1d..465ea95 100644
--- a/app/src/main/java/com/wireguard/android/model/Tunnel.java
+++ b/app/src/main/java/com/wireguard/android/model/Tunnel.java
@@ -26,7 +26,7 @@ import java9.util.concurrent.CompletionStage;
public class Tunnel extends BaseObservable implements Keyed<String> {
public static final int NAME_MAX_LENGTH = 15;
- private static final Pattern NAME_PATTERN = Pattern.compile("[a-zA-Z0-9_=+.-]{1,15}");
+ public static final Pattern NAME_PATTERN = Pattern.compile("[a-zA-Z0-9_=+.-]{1,15}");
private final TunnelManager manager;
@Nullable private Config config;
diff --git a/app/src/main/java/com/wireguard/config/Config.java b/app/src/main/java/com/wireguard/config/Config.java
index fbfc35f..af1e067 100644
--- a/app/src/main/java/com/wireguard/config/Config.java
+++ b/app/src/main/java/com/wireguard/config/Config.java
@@ -16,8 +16,10 @@ import android.os.Parcelable;
import android.support.annotation.Nullable;
import com.android.databinding.library.baseAdapters.BR;
+import com.mlykotom.valifi.fields.ValiFieldText;
import com.wireguard.android.Application;
import com.wireguard.android.R;
+import com.wireguard.android.model.Tunnel;
import java.io.BufferedReader;
import java.io.IOException;
@@ -106,12 +108,13 @@ public class Config {
return new Observable[size];
}
};
- @Nullable private String name;
+ private final ValiFieldText tunnelName = new ValiFieldText().addRangeLengthValidator(1, Tunnel.NAME_MAX_LENGTH)
+ .addPatternValidator(R.string.tunnel_error_invalid_name, Tunnel.NAME_PATTERN);
private final Interface.Observable observableInterface;
private final ObservableList<Peer.Observable> observablePeers;
public Observable(@Nullable final Config parent, @Nullable final String name) {
- this.name = name;
+ tunnelName.setValue(name);
observableInterface = new Interface.Observable(parent == null ? null : parent.interfaceSection);
observablePeers = new ObservableArrayList<>();
@@ -122,7 +125,7 @@ public class Config {
}
private Observable(final Parcel in) {
- name = in.readString();
+ tunnelName.setValue(in.readString());
observableInterface = in.readParcelable(Interface.Observable.class.getClassLoader());
observablePeers = new ObservableArrayList<>();
in.readTypedList(observablePeers, Peer.Observable.CREATOR);
@@ -151,8 +154,15 @@ public class Config {
}
@Bindable
+ public ValiFieldText getTunnelName() {
+ return tunnelName;
+ }
+
+ // It's either this or changing method signatures across
+ // the tree so let's keep semantics as earlier and let
+ // our hacks be in one place
public String getName() {
- return name == null ? "" : name;
+ return tunnelName.getValue();
}
@Bindable
@@ -161,13 +171,13 @@ public class Config {
}
public void setName(final String name) {
- this.name = name;
+ tunnelName.setValue(name);
notifyPropertyChanged(BR.name);
}
@Override
public void writeToParcel(final Parcel dest, final int flags) {
- dest.writeString(name);
+ dest.writeString(tunnelName.getValue());
dest.writeParcelable(observableInterface, flags);
dest.writeTypedList(observablePeers);
}
diff --git a/app/src/main/res/layout/tunnel_editor_fragment.xml b/app/src/main/res/layout/tunnel_editor_fragment.xml
index 1020e34..8f3a45f 100644
--- a/app/src/main/res/layout/tunnel_editor_fragment.xml
+++ b/app/src/main/res/layout/tunnel_editor_fragment.xml
@@ -76,8 +76,9 @@
android:layout_height="wrap_content"
android:layout_below="@+id/interface_name_label"
android:inputType="textNoSuggestions|textVisiblePassword"
- android:text="@={config.name}"
- app:filter="@{NameInputFilter.newInstance()}" />
+ android:text="@={config.tunnelName.value}"
+ app:error="@{config.tunnelName.error}"
+ app:errorEnabled="true" />
<TextView
android:id="@+id/private_key_label"