From ccfd28abbc33d9f64a52d1950dba4130d830bb68 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 24 Sep 2014 18:51:14 +0300 Subject: [PATCH] Added compression preference to node settings. --- .../fragments/NodeSettingsFragment.java | 11 +++++++++++ .../nutomic/syncthingandroid/syncthing/RestApi.java | 3 +++ src/main/res/values/strings.xml | 3 +++ src/main/res/xml/node_settings_create.xml | 4 ++++ src/main/res/xml/node_settings_edit.xml | 4 ++++ 5 files changed, 25 insertions(+) diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java index 42f25b3b..f3992c8d 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java @@ -6,6 +6,7 @@ import android.content.ActivityNotFoundException; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.Preference; import android.support.v4.preference.PreferenceFragment; @@ -46,6 +47,8 @@ public class NodeSettingsFragment extends PreferenceFragment implements private EditTextPreference mAddresses; + private CheckBoxPreference mCompression; + private Preference mVersion; private Preference mCurrentAddress; @@ -73,6 +76,8 @@ public class NodeSettingsFragment extends PreferenceFragment implements mName.setOnPreferenceChangeListener(this); mAddresses = (EditTextPreference) findPreference("addresses"); mAddresses.setOnPreferenceChangeListener(this); + mCompression = (CheckBoxPreference) findPreference("compression"); + mCompression.setOnPreferenceChangeListener(this); if (!mIsCreate) { mVersion = findPreference("version"); mVersion.setSummary("?"); @@ -102,6 +107,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements mNode.Name = ""; mNode.NodeID = ""; mNode.Addresses = "dynamic"; + mNode.Compression = true; ((EditTextPreference) mNodeId).setText(mNode.NodeID); } else { getActivity().setTitle(R.string.edit_node); @@ -122,6 +128,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements mName.setSummary(mNode.Name); mAddresses.setText(mNode.Addresses); mAddresses.setSummary(mNode.Addresses); + mCompression.setChecked(mNode.Compression); } @Override @@ -196,6 +203,10 @@ public class NodeSettingsFragment extends PreferenceFragment implements mNode.Addresses = (String) o; nodeUpdated(); return true; + } else if (preference.equals(mCompression)) { + mNode.Compression = (Boolean) o; + nodeUpdated(); + return true; } return false; } diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index 39842110..5dc9f592 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -65,6 +65,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, public String Addresses; public String Name; public String NodeID; + public boolean Compression; } public static class SystemInfo { @@ -446,6 +447,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, } n.Name = json.getString("Name"); n.NodeID = json.getString("NodeID"); + n.Compression = json.getBoolean("Compression"); if (!n.NodeID.equals(mLocalNodeId)) { ret.add(n); } @@ -709,6 +711,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, n.put("NodeID", node.NodeID); n.put("Name", node.Name); n.put("Addresses", listToJson(node.Addresses.split(" "))); + n.put("Compression", node.Compression); requireRestart(activity); } catch (JSONException e) { Log.w(TAG, "Failed to read nodes", e); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 0f751d16..a9e35316 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -141,6 +141,9 @@ Current Address + Compression + + Delete Node diff --git a/src/main/res/xml/node_settings_create.xml b/src/main/res/xml/node_settings_create.xml index f8eb576b..476a86f9 100644 --- a/src/main/res/xml/node_settings_create.xml +++ b/src/main/res/xml/node_settings_create.xml @@ -15,4 +15,8 @@ android:key="addresses" android:title="@string/addresses" /> + + diff --git a/src/main/res/xml/node_settings_edit.xml b/src/main/res/xml/node_settings_edit.xml index f2a9433d..b6c15898 100644 --- a/src/main/res/xml/node_settings_edit.xml +++ b/src/main/res/xml/node_settings_edit.xml @@ -14,6 +14,10 @@ android:key="addresses" android:title="@string/addresses" /> + +