diff --git a/src/main/java/com/nutomic/syncthingandroid/gui/LoadingListFragment.java b/src/main/java/com/nutomic/syncthingandroid/gui/LoadingListFragment.java index dccbb0f5..5fef25bb 100644 --- a/src/main/java/com/nutomic/syncthingandroid/gui/LoadingListFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/gui/LoadingListFragment.java @@ -28,7 +28,6 @@ import android.widget.ListView; import android.widget.TextView; import com.nutomic.syncthingandroid.R; -import com.nutomic.syncthingandroid.syncthing.RestApi; import com.nutomic.syncthingandroid.syncthing.SyncthingService; /** diff --git a/src/main/java/com/nutomic/syncthingandroid/gui/NodesFragment.java b/src/main/java/com/nutomic/syncthingandroid/gui/NodesFragment.java index be29edc4..967a39ff 100644 --- a/src/main/java/com/nutomic/syncthingandroid/gui/NodesFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/gui/NodesFragment.java @@ -6,9 +6,8 @@ import android.widget.AdapterView; import android.widget.ListView; import com.nutomic.syncthingandroid.R; -import com.nutomic.syncthingandroid.syncthing.RestApi; import com.nutomic.syncthingandroid.syncthing.SyncthingService; -import com.nutomic.syncthingandroid.util.NodeAdapter; +import com.nutomic.syncthingandroid.util.NodesAdapter; import java.util.Timer; import java.util.TimerTask; @@ -19,7 +18,7 @@ import java.util.TimerTask; public class NodesFragment extends LoadingListFragment implements SyncthingService.OnApiAvailableListener, ListView.OnItemClickListener { - private NodeAdapter mAdapter; + private NodesAdapter mAdapter; private Timer mTimer; @@ -27,7 +26,7 @@ public class NodesFragment extends LoadingListFragment implements @Override public void onInitAdapter(MainActivity activity) { - mAdapter = new NodeAdapter(activity); + mAdapter = new NodesAdapter(activity); mAdapter.add(activity.getApi().getNodes()); setListAdapter(mAdapter, R.string.nodes_list_empty); mInitialized = true; diff --git a/src/main/java/com/nutomic/syncthingandroid/gui/RepoSettingsActivity.java b/src/main/java/com/nutomic/syncthingandroid/gui/RepoSettingsActivity.java index ed86a237..e960d9e3 100644 --- a/src/main/java/com/nutomic/syncthingandroid/gui/RepoSettingsActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/gui/RepoSettingsActivity.java @@ -110,7 +110,7 @@ public class RepoSettingsActivity extends PreferenceActivity else if (getIntent().getAction().equals(ACTION_EDIT)) { setTitle(R.string.edit_repo); mRepositoryId.setEnabled(false); - List repos = mSyncthingService.getApi().getRepositories(); + List repos = mSyncthingService.getApi().getRepos(); for (int i = 0; i < repos.size(); i++) { if (repos.get(i).ID.equals(getIntent().getStringExtra(KEY_REPO_ID))) { mRepo = repos.get(i); @@ -174,7 +174,7 @@ public class RepoSettingsActivity extends PreferenceActivity Toast.makeText(this, R.string.repo_path_required, Toast.LENGTH_LONG).show(); return true; } - mSyncthingService.getApi().editRepository(mRepo, true); + mSyncthingService.getApi().editRepo(mRepo, true); finish(); return true; } @@ -258,7 +258,7 @@ public class RepoSettingsActivity extends PreferenceActivity .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - mSyncthingService.getApi().deleteRepository(mRepo); + mSyncthingService.getApi().deleteRepo(mRepo); finish(); } }) @@ -271,7 +271,7 @@ public class RepoSettingsActivity extends PreferenceActivity private void repositoryUpdated() { if (getIntent().getAction().equals(ACTION_EDIT)) { - mSyncthingService.getApi().editRepository(mRepo, false); + mSyncthingService.getApi().editRepo(mRepo, false); } } diff --git a/src/main/java/com/nutomic/syncthingandroid/gui/ReposFragment.java b/src/main/java/com/nutomic/syncthingandroid/gui/ReposFragment.java index 655c99d4..54e17d29 100644 --- a/src/main/java/com/nutomic/syncthingandroid/gui/ReposFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/gui/ReposFragment.java @@ -5,7 +5,6 @@ import android.view.View; import android.widget.AdapterView; import com.nutomic.syncthingandroid.R; -import com.nutomic.syncthingandroid.syncthing.RestApi; import com.nutomic.syncthingandroid.syncthing.SyncthingService; import com.nutomic.syncthingandroid.util.ReposAdapter; @@ -27,7 +26,7 @@ public class ReposFragment extends LoadingListFragment implements @Override public void onInitAdapter(MainActivity activity) { mAdapter = new ReposAdapter(activity); - mAdapter.add(activity.getApi().getRepositories()); + mAdapter.add(activity.getApi().getRepos()); setListAdapter(mAdapter, R.string.repositories_list_empty); mInitialized = true; } @@ -69,4 +68,5 @@ public class ReposFragment extends LoadingListFragment implements intent.putExtra(RepoSettingsActivity.KEY_REPO_ID, mAdapter.getItem(i).ID); startActivity(intent); } + } diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index d1e7c9c4..c364613d 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -14,11 +14,9 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.lang.ref.WeakReference; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -386,7 +384,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener { /** * Returns a list of all existing repositores. */ - public List getRepositories() { + public List getRepos() { if (mConfig == null) return new ArrayList(); @@ -610,7 +608,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener { /** * Updates or creates the given node. */ - public void editRepository(Repository repository, boolean create) { + public void editRepo(Repository repo, boolean create) { try { JSONArray repos = mConfig.getJSONArray("Repositories"); JSONObject r = null; @@ -621,18 +619,18 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener { else { for (int i = 0; i < repos.length(); i++) { JSONObject json = repos.getJSONObject(i); - if (repository.ID.equals(json.getString("ID"))) { + if (repo.ID.equals(json.getString("ID"))) { r = repos.getJSONObject(i); break; } } } - r.put("Directory", repository.Directory); - r.put("ID", repository.ID); + r.put("Directory", repo.Directory); + r.put("ID", repo.ID); r.put("IgnorePerms", true); - r.put("ReadOnly", repository.ReadOnly); + r.put("ReadOnly", repo.ReadOnly); JSONArray nodes = new JSONArray(); - for (Node n : repository.Nodes) { + for (Node n : repo.Nodes) { JSONObject element = new JSONObject(); element.put("Addresses", n.Addresses); element.put("Name", n.Name); @@ -641,30 +639,30 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener { } r.put("Nodes", nodes); JSONObject versioning = new JSONObject(); - versioning.put("Type", repository.Versioning.getType()); + versioning.put("Type", repo.Versioning.getType()); JSONObject params = new JSONObject(); versioning.put("Params", params); - for (String key : repository.Versioning.getParams().keySet()) { - params.put(key, repository.Versioning.getParams().get(key)); + for (String key : repo.Versioning.getParams().keySet()) { + params.put(key, repo.Versioning.getParams().get(key)); } r.put("Versioning", versioning); configUpdated(); } catch (JSONException e) { - Log.w(TAG, "Failed to edit repo " + repository.ID + " at " + repository.Directory, e); + Log.w(TAG, "Failed to edit repo " + repo.ID + " at " + repo.Directory, e); } } /** * Deletes the given repository from syncthing. */ - public void deleteRepository(Repository repository) { + public void deleteRepo(Repository repo) { try { JSONArray repos = mConfig.getJSONArray("Repositories"); for (int i = 0; i < repos.length(); i++) { JSONObject json = repos.getJSONObject(i); - if (repository.ID.equals(json.getString("ID"))) { + if (repo.ID.equals(json.getString("ID"))) { mConfig.remove("Repositories"); mConfig.put("Repositories", delete(repos, repos.getJSONObject(i))); break; diff --git a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java index 10d8cead..042561ca 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java @@ -1,9 +1,6 @@ package com.nutomic.syncthingandroid.util; import android.util.Log; -import android.util.Pair; - -import com.nutomic.syncthingandroid.syncthing.SyncthingService; import org.w3c.dom.Document; import org.w3c.dom.Element; diff --git a/src/main/java/com/nutomic/syncthingandroid/util/NodeAdapter.java b/src/main/java/com/nutomic/syncthingandroid/util/NodesAdapter.java similarity index 95% rename from src/main/java/com/nutomic/syncthingandroid/util/NodeAdapter.java rename to src/main/java/com/nutomic/syncthingandroid/util/NodesAdapter.java index d9c1766f..f9ac6ff7 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/NodeAdapter.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/NodesAdapter.java @@ -6,7 +6,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.ListView; import android.widget.TextView; @@ -20,13 +19,13 @@ import java.util.Map; /** * Generates item views for node items. */ -public class NodeAdapter extends ArrayAdapter +public class NodesAdapter extends ArrayAdapter implements RestApi.OnReceiveConnectionsListener { private Map mConnections = new HashMap(); - public NodeAdapter(Context context) { + public NodesAdapter(Context context) { super(context, R.layout.node_list_item); }