From 2363d92f2259f5c4b81dee1d681c7afb9e6a30d0 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 24 Sep 2014 18:33:27 +0300 Subject: [PATCH] Added per-repo rescan interval setting. The default is 86400 (one day), because this shouldn't be needed with the previous addition of inotify. --- .../fragments/RepoSettingsFragment.java | 13 ++++++++++++- .../nutomic/syncthingandroid/syncthing/RestApi.java | 3 +++ src/main/res/values/strings.xml | 3 +++ src/main/res/xml/repo_settings_create.xml | 5 +++++ src/main/res/xml/repo_settings_edit.xml | 5 +++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java index 1c0e226a..353e3f85 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java @@ -54,6 +54,8 @@ public class RepoSettingsFragment extends PreferenceFragment private Preference mDirectory; + private EditTextPreference mRescanInterval; + private CheckBoxPreference mRepoMaster; private PreferenceScreen mNodes; @@ -83,6 +85,8 @@ public class RepoSettingsFragment extends PreferenceFragment mRepoId.setOnPreferenceChangeListener(this); mDirectory = findPreference("directory"); mDirectory.setOnPreferenceClickListener(this); + mRescanInterval = (EditTextPreference) findPreference("rescan_interval"); + mRescanInterval.setOnPreferenceChangeListener(this); mRepoMaster = (CheckBoxPreference) findPreference("repo_master"); mRepoMaster.setOnPreferenceChangeListener(this); mNodes = (PreferenceScreen) findPreference("nodes"); @@ -108,6 +112,7 @@ public class RepoSettingsFragment extends PreferenceFragment mRepo = new RestApi.Repo(); mRepo.ID = ""; mRepo.Directory = ""; + mRepo.RescanIntervalS = 86400; mRepo.NodeIds = new ArrayList<>(); mRepo.Versioning = new RestApi.Versioning(); } else { @@ -125,6 +130,8 @@ public class RepoSettingsFragment extends PreferenceFragment mRepoId.setText(mRepo.ID); mRepoId.setSummary(mRepo.ID); mDirectory.setSummary(mRepo.Directory); + mRescanInterval.setText(Integer.toString(mRepo.RescanIntervalS)); + mRescanInterval.setSummary(Integer.toString(mRepo.RescanIntervalS)); mRepoMaster.setChecked(mRepo.ReadOnly); List nodesList = mSyncthingService.getApi().getNodes(); for (RestApi.Node n : nodesList) { @@ -132,7 +139,6 @@ public class RepoSettingsFragment extends PreferenceFragment cbp.setTitle(n.Name); cbp.setKey(KEY_NODE_SHARED); cbp.setOnPreferenceChangeListener(RepoSettingsFragment.this); - // FIXME: something wrong here cbp.setChecked(false); for (String n2 : mRepo.NodeIds) { if (n2.equals(n.NodeID)) { @@ -221,6 +227,11 @@ public class RepoSettingsFragment extends PreferenceFragment mRepo.Directory = (String) o; repoUpdated(); return true; + } else if (preference.equals(mRescanInterval)) { + mRepo.RescanIntervalS = Integer.parseInt((String) o); + mRescanInterval.setSummary((String) o); + repoUpdated(); + return true; } else if (preference.equals(mRepoMaster)) { mRepo.ReadOnly = (Boolean) o; repoUpdated(); diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index 801f2528..39842110 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -82,6 +82,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, public String Invalid; public List NodeIds; public boolean ReadOnly; + public int RescanIntervalS; public Versioning Versioning; } @@ -478,6 +479,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, r.NodeIds.add(mLocalNodeId); r.ReadOnly = json.getBoolean("ReadOnly"); + r.RescanIntervalS = json.getInt("RescanIntervalS"); JSONObject versioning = json.getJSONObject("Versioning"); if (versioning.getString("Type").equals("simple")) { SimpleVersioning sv = new SimpleVersioning(); @@ -776,6 +778,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, for (String key : repo.Versioning.getParams().keySet()) { params.put(key, repo.Versioning.getParams().get(key)); } + r.put("RescanIntervalS", repo.RescanIntervalS); r.put("Versioning", versioning); requireRestart(activity); } catch (JSONException e) { diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 93ee934d..0f751d16 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -86,6 +86,9 @@ Directory + + Rescan Interval + Repository Master diff --git a/src/main/res/xml/repo_settings_create.xml b/src/main/res/xml/repo_settings_create.xml index d30f1504..dbf5f445 100644 --- a/src/main/res/xml/repo_settings_create.xml +++ b/src/main/res/xml/repo_settings_create.xml @@ -10,6 +10,11 @@ android:key="directory" android:title="@string/directory" /> + + diff --git a/src/main/res/xml/repo_settings_edit.xml b/src/main/res/xml/repo_settings_edit.xml index af636018..ccd22f05 100644 --- a/src/main/res/xml/repo_settings_edit.xml +++ b/src/main/res/xml/repo_settings_edit.xml @@ -14,6 +14,11 @@ android:enabled="false" style="?android:preferenceInformationStyle" /> + +