1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-24 11:51:30 +00:00

Added per-repo rescan interval setting.

The default is 86400 (one day), because this shouldn't be needed with the
previous addition of inotify.
This commit is contained in:
Felix Ableitner 2014-09-24 18:33:27 +03:00
parent 924be98aaa
commit 2363d92f22
5 changed files with 28 additions and 1 deletions

View file

@ -54,6 +54,8 @@ public class RepoSettingsFragment extends PreferenceFragment
private Preference mDirectory; private Preference mDirectory;
private EditTextPreference mRescanInterval;
private CheckBoxPreference mRepoMaster; private CheckBoxPreference mRepoMaster;
private PreferenceScreen mNodes; private PreferenceScreen mNodes;
@ -83,6 +85,8 @@ public class RepoSettingsFragment extends PreferenceFragment
mRepoId.setOnPreferenceChangeListener(this); mRepoId.setOnPreferenceChangeListener(this);
mDirectory = findPreference("directory"); mDirectory = findPreference("directory");
mDirectory.setOnPreferenceClickListener(this); mDirectory.setOnPreferenceClickListener(this);
mRescanInterval = (EditTextPreference) findPreference("rescan_interval");
mRescanInterval.setOnPreferenceChangeListener(this);
mRepoMaster = (CheckBoxPreference) findPreference("repo_master"); mRepoMaster = (CheckBoxPreference) findPreference("repo_master");
mRepoMaster.setOnPreferenceChangeListener(this); mRepoMaster.setOnPreferenceChangeListener(this);
mNodes = (PreferenceScreen) findPreference("nodes"); mNodes = (PreferenceScreen) findPreference("nodes");
@ -108,6 +112,7 @@ public class RepoSettingsFragment extends PreferenceFragment
mRepo = new RestApi.Repo(); mRepo = new RestApi.Repo();
mRepo.ID = ""; mRepo.ID = "";
mRepo.Directory = ""; mRepo.Directory = "";
mRepo.RescanIntervalS = 86400;
mRepo.NodeIds = new ArrayList<>(); mRepo.NodeIds = new ArrayList<>();
mRepo.Versioning = new RestApi.Versioning(); mRepo.Versioning = new RestApi.Versioning();
} else { } else {
@ -125,6 +130,8 @@ public class RepoSettingsFragment extends PreferenceFragment
mRepoId.setText(mRepo.ID); mRepoId.setText(mRepo.ID);
mRepoId.setSummary(mRepo.ID); mRepoId.setSummary(mRepo.ID);
mDirectory.setSummary(mRepo.Directory); mDirectory.setSummary(mRepo.Directory);
mRescanInterval.setText(Integer.toString(mRepo.RescanIntervalS));
mRescanInterval.setSummary(Integer.toString(mRepo.RescanIntervalS));
mRepoMaster.setChecked(mRepo.ReadOnly); mRepoMaster.setChecked(mRepo.ReadOnly);
List<RestApi.Node> nodesList = mSyncthingService.getApi().getNodes(); List<RestApi.Node> nodesList = mSyncthingService.getApi().getNodes();
for (RestApi.Node n : nodesList) { for (RestApi.Node n : nodesList) {
@ -132,7 +139,6 @@ public class RepoSettingsFragment extends PreferenceFragment
cbp.setTitle(n.Name); cbp.setTitle(n.Name);
cbp.setKey(KEY_NODE_SHARED); cbp.setKey(KEY_NODE_SHARED);
cbp.setOnPreferenceChangeListener(RepoSettingsFragment.this); cbp.setOnPreferenceChangeListener(RepoSettingsFragment.this);
// FIXME: something wrong here
cbp.setChecked(false); cbp.setChecked(false);
for (String n2 : mRepo.NodeIds) { for (String n2 : mRepo.NodeIds) {
if (n2.equals(n.NodeID)) { if (n2.equals(n.NodeID)) {
@ -221,6 +227,11 @@ public class RepoSettingsFragment extends PreferenceFragment
mRepo.Directory = (String) o; mRepo.Directory = (String) o;
repoUpdated(); repoUpdated();
return true; 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)) { } else if (preference.equals(mRepoMaster)) {
mRepo.ReadOnly = (Boolean) o; mRepo.ReadOnly = (Boolean) o;
repoUpdated(); repoUpdated();

View file

@ -82,6 +82,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
public String Invalid; public String Invalid;
public List<String> NodeIds; public List<String> NodeIds;
public boolean ReadOnly; public boolean ReadOnly;
public int RescanIntervalS;
public Versioning Versioning; public Versioning Versioning;
} }
@ -478,6 +479,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
r.NodeIds.add(mLocalNodeId); r.NodeIds.add(mLocalNodeId);
r.ReadOnly = json.getBoolean("ReadOnly"); r.ReadOnly = json.getBoolean("ReadOnly");
r.RescanIntervalS = json.getInt("RescanIntervalS");
JSONObject versioning = json.getJSONObject("Versioning"); JSONObject versioning = json.getJSONObject("Versioning");
if (versioning.getString("Type").equals("simple")) { if (versioning.getString("Type").equals("simple")) {
SimpleVersioning sv = new SimpleVersioning(); SimpleVersioning sv = new SimpleVersioning();
@ -776,6 +778,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
for (String key : repo.Versioning.getParams().keySet()) { for (String key : repo.Versioning.getParams().keySet()) {
params.put(key, repo.Versioning.getParams().get(key)); params.put(key, repo.Versioning.getParams().get(key));
} }
r.put("RescanIntervalS", repo.RescanIntervalS);
r.put("Versioning", versioning); r.put("Versioning", versioning);
requireRestart(activity); requireRestart(activity);
} catch (JSONException e) { } catch (JSONException e) {

View file

@ -86,6 +86,9 @@
<!-- Setting title --> <!-- Setting title -->
<string name="directory">Directory</string> <string name="directory">Directory</string>
<!-- Setting title -->
<string name="rescan_interval">Rescan Interval</string>
<!-- Setting title --> <!-- Setting title -->
<string name="repo_master">Repository Master</string> <string name="repo_master">Repository Master</string>

View file

@ -10,6 +10,11 @@
android:key="directory" android:key="directory"
android:title="@string/directory" /> android:title="@string/directory" />
<EditTextPreference
android:key="rescan_interval"
android:title="@string/rescan_interval"
android:inputType="numberDecimal" />
<CheckBoxPreference <CheckBoxPreference
android:key="repo_master" android:key="repo_master"
android:title="@string/repo_master" /> android:title="@string/repo_master" />

View file

@ -14,6 +14,11 @@
android:enabled="false" android:enabled="false"
style="?android:preferenceInformationStyle" /> style="?android:preferenceInformationStyle" />
<EditTextPreference
android:key="rescan_interval"
android:title="@string/rescan_interval"
android:inputType="numberDecimal" />
<CheckBoxPreference <CheckBoxPreference
android:key="repo_master" android:key="repo_master"
android:title="@string/repo_master" /> android:title="@string/repo_master" />