summaryrefslogtreecommitdiffhomepage
path: root/app/src/main
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-07-29 06:08:54 -0500
committerSamuel Holland <samuel@sholland.org>2017-07-29 06:08:54 -0500
commitaa19063f57a3543f3e69a150b51b23af5e10dd39 (patch)
tree80258ba3b5d729fa9549d9db5b1d008945fbf0ea /app/src/main
parent588ef223ecdef12f8b85fd0cec9e7206c0308dc6 (diff)
Profile: Add minimal implementation
This represents a wg-quick profile as two strings: the file name and the file contents.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/wireguard/config/Profile.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/config/Profile.java b/app/src/main/java/com/wireguard/config/Profile.java
new file mode 100644
index 00000000..b8fd55a4
--- /dev/null
+++ b/app/src/main/java/com/wireguard/config/Profile.java
@@ -0,0 +1,56 @@
+package com.wireguard.config;
+
+import android.databinding.BaseObservable;
+import android.databinding.Bindable;
+import android.databinding.Observable;
+
+import com.wireguard.android.BR;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+/**
+ * Represents a wg-quick profile.
+ */
+
+public class Profile extends BaseObservable implements Observable {
+ private String config;
+ private final String name;
+
+ public Profile(String name) {
+ this.name = name;
+ }
+
+ public void fromStream(InputStream stream)
+ throws IOException {
+ final StringBuilder sb = new StringBuilder(stream.available());
+ String line;
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
+ while ((line = reader.readLine()) != null)
+ sb.append(line).append('\n');
+ }
+ setConfig(sb.toString());
+ }
+
+ @Bindable
+ public String getConfig() {
+ return config;
+ }
+
+ @Bindable
+ public String getName() {
+ return name;
+ }
+
+ public void setConfig(String config) {
+ this.config = config;
+ notifyPropertyChanged(BR.config);
+ }
+
+ @Override
+ public String toString() {
+ return getConfig();
+ }
+}