mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 19:31:30 +00:00
Improve handling of nodes in a repository (fixes #89).
This commit is contained in:
parent
2c631eed1f
commit
d248017e24
3 changed files with 19 additions and 23 deletions
|
@ -25,6 +25,7 @@ import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
import com.nutomic.syncthingandroid.util.ExtendedCheckBoxPreference;
|
import com.nutomic.syncthingandroid.util.ExtendedCheckBoxPreference;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,7 +108,7 @@ public class RepoSettingsFragment extends PreferenceFragment
|
||||||
mRepo = new RestApi.Repo();
|
mRepo = new RestApi.Repo();
|
||||||
mRepo.ID = "";
|
mRepo.ID = "";
|
||||||
mRepo.Directory = "";
|
mRepo.Directory = "";
|
||||||
mRepo.Nodes = new ArrayList<>();
|
mRepo.NodeIds = new ArrayList<>();
|
||||||
mRepo.Versioning = new RestApi.Versioning();
|
mRepo.Versioning = new RestApi.Versioning();
|
||||||
} else {
|
} else {
|
||||||
getActivity().setTitle(R.string.edit_repo);
|
getActivity().setTitle(R.string.edit_repo);
|
||||||
|
@ -133,8 +134,8 @@ public class RepoSettingsFragment extends PreferenceFragment
|
||||||
cbp.setOnPreferenceChangeListener(RepoSettingsFragment.this);
|
cbp.setOnPreferenceChangeListener(RepoSettingsFragment.this);
|
||||||
// FIXME: something wrong here
|
// FIXME: something wrong here
|
||||||
cbp.setChecked(false);
|
cbp.setChecked(false);
|
||||||
for (RestApi.Node n2 : mRepo.Nodes) {
|
for (String n2 : mRepo.NodeIds) {
|
||||||
if (n2.NodeID.equals(n.NodeID)) {
|
if (n2.equals(n.NodeID)) {
|
||||||
cbp.setChecked(true);
|
cbp.setChecked(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,11 +229,13 @@ public class RepoSettingsFragment extends PreferenceFragment
|
||||||
ExtendedCheckBoxPreference pref = (ExtendedCheckBoxPreference) preference;
|
ExtendedCheckBoxPreference pref = (ExtendedCheckBoxPreference) preference;
|
||||||
RestApi.Node node = (RestApi.Node) pref.getObject();
|
RestApi.Node node = (RestApi.Node) pref.getObject();
|
||||||
if ((Boolean) o) {
|
if ((Boolean) o) {
|
||||||
mRepo.Nodes.add(node);
|
mRepo.NodeIds.add(node.NodeID);
|
||||||
} else {
|
} else {
|
||||||
for (RestApi.Node n : mRepo.Nodes) {
|
Iterator<String> it = mRepo.NodeIds.iterator();
|
||||||
if (n.NodeID.equals(node.NodeID)) {
|
while (it.hasNext()) {
|
||||||
mRepo.Nodes.remove(n);
|
String n = it.next();
|
||||||
|
if (n.equals(node.NodeID)) {
|
||||||
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
public String Directory;
|
public String Directory;
|
||||||
public String ID;
|
public String ID;
|
||||||
public String Invalid;
|
public String Invalid;
|
||||||
public List<Node> Nodes;
|
public List<String> NodeIds;
|
||||||
public boolean ReadOnly;
|
public boolean ReadOnly;
|
||||||
public Versioning Versioning;
|
public Versioning Versioning;
|
||||||
}
|
}
|
||||||
|
@ -459,7 +459,6 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
List<Repo> ret;
|
List<Repo> ret;
|
||||||
try {
|
try {
|
||||||
JSONArray repos = mConfig.getJSONArray("Repositories");
|
JSONArray repos = mConfig.getJSONArray("Repositories");
|
||||||
String x = repos.toString();
|
|
||||||
ret = new ArrayList<>(repos.length());
|
ret = new ArrayList<>(repos.length());
|
||||||
for (int i = 0; i < repos.length(); i++) {
|
for (int i = 0; i < repos.length(); i++) {
|
||||||
JSONObject json = repos.getJSONObject(i);
|
JSONObject json = repos.getJSONObject(i);
|
||||||
|
@ -467,17 +466,13 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
r.Directory = json.getString("Directory");
|
r.Directory = json.getString("Directory");
|
||||||
r.ID = json.getString("ID");
|
r.ID = json.getString("ID");
|
||||||
r.Invalid = json.getString("Invalid");
|
r.Invalid = json.getString("Invalid");
|
||||||
r.Nodes = new ArrayList<>();
|
r.NodeIds = new ArrayList<>();
|
||||||
JSONArray nodes = json.getJSONArray("Nodes");
|
JSONArray nodes = json.getJSONArray("Nodes");
|
||||||
for (int j = 0; j < nodes.length(); j++) {
|
for (int j = 0; j < nodes.length(); j++) {
|
||||||
JSONObject n = nodes.getJSONObject(j);
|
JSONObject n = nodes.getJSONObject(j);
|
||||||
String id = n.getString("NodeID");
|
r.NodeIds.add(n.getString("NodeID"));
|
||||||
for (Node n2 : getNodes()) {
|
|
||||||
if (n2.NodeID.equals(id)) {
|
|
||||||
r.Nodes.add(n2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
r.NodeIds.add(mLocalNodeId);
|
||||||
|
|
||||||
r.ReadOnly = json.getBoolean("ReadOnly");
|
r.ReadOnly = json.getBoolean("ReadOnly");
|
||||||
JSONObject versioning = json.getJSONObject("Versioning");
|
JSONObject versioning = json.getJSONObject("Versioning");
|
||||||
|
@ -602,8 +597,8 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
boolean isShared = false;
|
boolean isShared = false;
|
||||||
outerloop:
|
outerloop:
|
||||||
for (Repo r : getRepos()) {
|
for (Repo r : getRepos()) {
|
||||||
for (Node n : r.Nodes) {
|
for (String n : r.NodeIds) {
|
||||||
if (n.NodeID.equals(nodeId)) {
|
if (n.equals(nodeId)) {
|
||||||
isShared = true;
|
isShared = true;
|
||||||
break outerloop;
|
break outerloop;
|
||||||
}
|
}
|
||||||
|
@ -765,11 +760,9 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
r.put("IgnorePerms", true);
|
r.put("IgnorePerms", true);
|
||||||
r.put("ReadOnly", repo.ReadOnly);
|
r.put("ReadOnly", repo.ReadOnly);
|
||||||
JSONArray nodes = new JSONArray();
|
JSONArray nodes = new JSONArray();
|
||||||
for (Node n : repo.Nodes) {
|
for (String n : repo.NodeIds) {
|
||||||
JSONObject element = new JSONObject();
|
JSONObject element = new JSONObject();
|
||||||
element.put("Addresses", listToJson(n.Addresses.split(" ")));
|
element.put("NodeID", n);
|
||||||
element.put("Name", n.Name);
|
|
||||||
element.put("NodeID", n.NodeID);
|
|
||||||
nodes.put(element);
|
nodes.put(element);
|
||||||
}
|
}
|
||||||
r.put("Nodes", nodes);
|
r.put("Nodes", nodes);
|
||||||
|
|
|
@ -27,7 +27,7 @@ import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides direct access to the config.xml file in the file system.
|
* Provides direct access to the config.xml file in the file system.
|
||||||
* <p/>
|
*
|
||||||
* This class should only be used if the syncthing API is not available (usually during startup).
|
* This class should only be used if the syncthing API is not available (usually during startup).
|
||||||
*/
|
*/
|
||||||
public class ConfigXml {
|
public class ConfigXml {
|
||||||
|
|
Loading…
Reference in a new issue