mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 11:21:29 +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 java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -107,7 +108,7 @@ public class RepoSettingsFragment extends PreferenceFragment
|
|||
mRepo = new RestApi.Repo();
|
||||
mRepo.ID = "";
|
||||
mRepo.Directory = "";
|
||||
mRepo.Nodes = new ArrayList<>();
|
||||
mRepo.NodeIds = new ArrayList<>();
|
||||
mRepo.Versioning = new RestApi.Versioning();
|
||||
} else {
|
||||
getActivity().setTitle(R.string.edit_repo);
|
||||
|
@ -133,8 +134,8 @@ public class RepoSettingsFragment extends PreferenceFragment
|
|||
cbp.setOnPreferenceChangeListener(RepoSettingsFragment.this);
|
||||
// FIXME: something wrong here
|
||||
cbp.setChecked(false);
|
||||
for (RestApi.Node n2 : mRepo.Nodes) {
|
||||
if (n2.NodeID.equals(n.NodeID)) {
|
||||
for (String n2 : mRepo.NodeIds) {
|
||||
if (n2.equals(n.NodeID)) {
|
||||
cbp.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
@ -228,11 +229,13 @@ public class RepoSettingsFragment extends PreferenceFragment
|
|||
ExtendedCheckBoxPreference pref = (ExtendedCheckBoxPreference) preference;
|
||||
RestApi.Node node = (RestApi.Node) pref.getObject();
|
||||
if ((Boolean) o) {
|
||||
mRepo.Nodes.add(node);
|
||||
mRepo.NodeIds.add(node.NodeID);
|
||||
} else {
|
||||
for (RestApi.Node n : mRepo.Nodes) {
|
||||
if (n.NodeID.equals(node.NodeID)) {
|
||||
mRepo.Nodes.remove(n);
|
||||
Iterator<String> it = mRepo.NodeIds.iterator();
|
||||
while (it.hasNext()) {
|
||||
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 ID;
|
||||
public String Invalid;
|
||||
public List<Node> Nodes;
|
||||
public List<String> NodeIds;
|
||||
public boolean ReadOnly;
|
||||
public Versioning Versioning;
|
||||
}
|
||||
|
@ -459,7 +459,6 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
|||
List<Repo> ret;
|
||||
try {
|
||||
JSONArray repos = mConfig.getJSONArray("Repositories");
|
||||
String x = repos.toString();
|
||||
ret = new ArrayList<>(repos.length());
|
||||
for (int i = 0; i < repos.length(); i++) {
|
||||
JSONObject json = repos.getJSONObject(i);
|
||||
|
@ -467,17 +466,13 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
|||
r.Directory = json.getString("Directory");
|
||||
r.ID = json.getString("ID");
|
||||
r.Invalid = json.getString("Invalid");
|
||||
r.Nodes = new ArrayList<>();
|
||||
r.NodeIds = new ArrayList<>();
|
||||
JSONArray nodes = json.getJSONArray("Nodes");
|
||||
for (int j = 0; j < nodes.length(); j++) {
|
||||
JSONObject n = nodes.getJSONObject(j);
|
||||
String id = n.getString("NodeID");
|
||||
for (Node n2 : getNodes()) {
|
||||
if (n2.NodeID.equals(id)) {
|
||||
r.Nodes.add(n2);
|
||||
}
|
||||
}
|
||||
r.NodeIds.add(n.getString("NodeID"));
|
||||
}
|
||||
r.NodeIds.add(mLocalNodeId);
|
||||
|
||||
r.ReadOnly = json.getBoolean("ReadOnly");
|
||||
JSONObject versioning = json.getJSONObject("Versioning");
|
||||
|
@ -602,8 +597,8 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
|||
boolean isShared = false;
|
||||
outerloop:
|
||||
for (Repo r : getRepos()) {
|
||||
for (Node n : r.Nodes) {
|
||||
if (n.NodeID.equals(nodeId)) {
|
||||
for (String n : r.NodeIds) {
|
||||
if (n.equals(nodeId)) {
|
||||
isShared = true;
|
||||
break outerloop;
|
||||
}
|
||||
|
@ -765,11 +760,9 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
|||
r.put("IgnorePerms", true);
|
||||
r.put("ReadOnly", repo.ReadOnly);
|
||||
JSONArray nodes = new JSONArray();
|
||||
for (Node n : repo.Nodes) {
|
||||
for (String n : repo.NodeIds) {
|
||||
JSONObject element = new JSONObject();
|
||||
element.put("Addresses", listToJson(n.Addresses.split(" ")));
|
||||
element.put("Name", n.Name);
|
||||
element.put("NodeID", n.NodeID);
|
||||
element.put("NodeID", n);
|
||||
nodes.put(element);
|
||||
}
|
||||
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.
|
||||
* <p/>
|
||||
*
|
||||
* This class should only be used if the syncthing API is not available (usually during startup).
|
||||
*/
|
||||
public class ConfigXml {
|
||||
|
|
Loading…
Reference in a new issue