1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Update Rest API to v0.11

Conflicts:
	src/main/java/com/nutomic/syncthingandroid/fragments/DeviceSettingsFragment.java
This commit is contained in:
Lode Hoste 2015-04-09 20:45:00 +02:00
parent df92b179c7
commit 4146970e64
17 changed files with 254 additions and 254 deletions

View file

@ -25,13 +25,13 @@ public class DevicesAdapterTest extends AndroidTestCase {
super.setUp();
mAdapter = new DevicesAdapter(getContext());
mDevice.Addresses = "127.0.0.1:12345";
mDevice.Name = "the device";
mDevice.DeviceID = "123-456-789";
mDevice.addresses = "127.0.0.1:12345";
mDevice.name = "the device";
mDevice.deviceID = "123-456-789";
mConnection.Completion = 100;
mConnection.InBits = 1048576;
mConnection.OutBits = 1073741824;
mConnection.completion = 100;
mConnection.inBits = 1048576;
mConnection.outBits = 1073741824;
}
@ -40,7 +40,7 @@ public class DevicesAdapterTest extends AndroidTestCase {
mAdapter.add(Arrays.asList(mDevice));
View v = mAdapter.getView(0, null, null);
assertEquals(mDevice.Name, ((TextView) v.findViewById(R.id.name)).getText());
assertEquals(mDevice.name, ((TextView) v.findViewById(R.id.name)).getText());
assertEquals(getContext().getString(R.string.device_disconnected),
((TextView) v.findViewById(R.id.status)).getText().toString());
assertFalse(((TextView) v.findViewById(R.id.status)).getText().equals(""));
@ -52,7 +52,7 @@ public class DevicesAdapterTest extends AndroidTestCase {
public void testGetViewConnections() {
mAdapter.add(Arrays.asList(mDevice));
mAdapter.onReceiveConnections(
new HashMap<String, RestApi.Connection>() {{ put(mDevice.DeviceID, mConnection); }});
new HashMap<String, RestApi.Connection>() {{ put(mDevice.deviceID, mConnection); }});
View v = mAdapter.getView(0, null, null);
assertEquals(getContext().getString(R.string.device_up_to_date),

View file

@ -44,8 +44,8 @@ public class FolderObserverTest extends AndroidTestCase
private RestApi.Folder createFolder(String id) {
RestApi.Folder r = new RestApi.Folder();
r.Path = mTestFolder.getAbsolutePath();
r.ID = id;
r.path = mTestFolder.getAbsolutePath();
r.id = id;
return r;
}

View file

@ -25,12 +25,12 @@ public class FoldersAdapterTest extends AndroidTestCase {
super.setUp();
mAdapter = new FoldersAdapter(getContext());
mFolder.Path = "/my/dir/";
mFolder.ID = "id 123";
mFolder.Invalid = "all good";
mFolder.DeviceIds = new ArrayList<>();
mFolder.ReadOnly = false;
mFolder.Versioning = new RestApi.Versioning();
mFolder.path = "/my/dir/";
mFolder.id = "id 123";
mFolder.invalid = "all good";
mFolder.deviceIds = new ArrayList<>();
mFolder.readOnly = false;
mFolder.versioning = new RestApi.Versioning();
mModel.state = "idle";
mModel.localFiles = 50;
@ -43,15 +43,15 @@ public class FoldersAdapterTest extends AndroidTestCase {
public void testGetViewNoModel() {
mAdapter.add(Arrays.asList(mFolder));
View v = mAdapter.getView(0, null, null);
assertEquals(mFolder.ID, ((TextView) v.findViewById(R.id.id)).getText());
assertEquals(mFolder.Path, ((TextView) v.findViewById(R.id.directory)).getText());
assertEquals(mFolder.Invalid, ((TextView) v.findViewById(R.id.invalid)).getText());
assertEquals(mFolder.id, ((TextView) v.findViewById(R.id.id)).getText());
assertEquals(mFolder.path, ((TextView) v.findViewById(R.id.directory)).getText());
assertEquals(mFolder.invalid, ((TextView) v.findViewById(R.id.invalid)).getText());
}
@MediumTest
public void testGetViewModel() {
mAdapter.add(Arrays.asList(mFolder));
mAdapter.onReceiveModel(mFolder.ID, mModel);
mAdapter.onReceiveModel(mFolder.id, mModel);
View v = mAdapter.getView(0, null, null);
assertFalse(((TextView) v.findViewById(R.id.state)).getText().toString().equals(""));
String items = ((TextView) v.findViewById(R.id.items)).getText().toString();

View file

@ -99,12 +99,12 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
}
if (mDevice == null) {
mDevice = new RestApi.Device();
mDevice.Name = "";
mDevice.DeviceID = "";
mDevice.Addresses = "dynamic";
mDevice.Compression = "always";
mDevice.Introducer = false;
((EditTextPreference) mDeviceId).setText(mDevice.DeviceID);
mDevice.name = "";
mDevice.deviceID = "";
mDevice.addresses = "dynamic";
mDevice.compression = "always";
mDevice.introducer = false;
((EditTextPreference) mDeviceId).setText(mDevice.deviceID);
}
}
}
@ -140,7 +140,7 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
getActivity().setTitle(R.string.edit_device);
List<RestApi.Device> devices = mSyncthingService.getApi().getDevices(false);
for (int i = 0; i < devices.size(); i++) {
if (devices.get(i).DeviceID.equals(
if (devices.get(i).deviceID.equals(
getActivity().getIntent().getStringExtra(EXTRA_NODE_ID))) {
device = devices.get(i);
break;
@ -157,14 +157,14 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
mSyncthingService.getApi().getConnections(DeviceSettingsFragment.this);
mDeviceId.setSummary(mDevice.DeviceID);
mName.setText((mDevice.Name));
mName.setSummary(mDevice.Name);
mAddresses.setText(mDevice.Addresses);
mAddresses.setSummary(mDevice.Addresses);
mCompression.setValue(mDevice.Compression);
mCompression.setSummary(mDevice.Compression);
mIntroducer.setChecked(mDevice.Introducer);
mDeviceId.setSummary(mDevice.deviceID);
mName.setText((mDevice.name));
mName.setSummary(mDevice.name);
mAddresses.setText(mDevice.addresses);
mAddresses.setSummary(mDevice.addresses);
mCompression.setValue(mDevice.compression);
mCompression.setSummary(mDevice.compression);
mIntroducer.setChecked(mDevice.introducer);
}
@Override
@ -184,12 +184,12 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.create:
if (mDevice.DeviceID.equals("")) {
if (mDevice.deviceID.equals("")) {
Toast.makeText(getActivity(), R.string.device_id_required, Toast.LENGTH_LONG)
.show();
return true;
}
if (mDevice.Name.equals("")) {
if (mDevice.name.equals("")) {
Toast.makeText(getActivity(), R.string.device_name_required, Toast.LENGTH_LONG)
.show();
return true;
@ -197,7 +197,7 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
mSyncthingService.getApi().editDevice(mDevice, getActivity(), this);
return true;
case R.id.share_device_id:
RestApi.shareDeviceId(getActivity(), mDevice.DeviceID);
RestApi.shareDeviceId(getActivity(), mDevice.deviceID);
return true;
case R.id.delete:
new AlertDialog.Builder(getActivity())
@ -230,23 +230,23 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
pref.setSummary((String) o);
}
if (preference.equals(mDeviceId)) {
mDevice.DeviceID = (String) o;
mDevice.deviceID = (String) o;
deviceUpdated();
return true;
} else if (preference.equals(mName)) {
mDevice.Name = (String) o;
mDevice.name = (String) o;
deviceUpdated();
return true;
} else if (preference.equals(mAddresses)) {
mDevice.Addresses = (String) o;
mDevice.addresses = (String) o;
deviceUpdated();
return true;
} else if (preference.equals(mCompression)) {
mDevice.Compression = (String) o;
mDevice.compression = (String) o;
deviceUpdated();
return true;
} else if (preference.equals(mIntroducer)) {
mDevice.Introducer = (Boolean) o;
mDevice.introducer = (Boolean) o;
deviceUpdated();
return true;
}
@ -256,7 +256,7 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.equals(mDeviceId)) {
mSyncthingService.getApi().copyDeviceId(mDevice.DeviceID);
mSyncthingService.getApi().copyDeviceId(mDevice.deviceID);
return true;
}
return false;
@ -272,9 +272,9 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
if (mVersion == null || mCurrentAddress == null)
return;
if (connections.containsKey(mDevice.DeviceID)) {
mVersion.setSummary(connections.get(mDevice.DeviceID).ClientVersion);
mCurrentAddress.setSummary(connections.get(mDevice.DeviceID).Address);
if (connections.containsKey(mDevice.deviceID)) {
mVersion.setSummary(connections.get(mDevice.deviceID).clientVersion);
mCurrentAddress.setSummary(connections.get(mDevice.deviceID).address);
}
}
@ -304,14 +304,14 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
}
/**
* Receives value of scanned QR code and sets it as device ID.
* Receives value of scanned QR code and sets it as device id.
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SCAN_QR_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
mDevice.DeviceID = data.getStringExtra("SCAN_RESULT");
((EditTextPreference) mDeviceId).setText(mDevice.DeviceID);
mDeviceId.setSummary(mDevice.DeviceID);
mDevice.deviceID = data.getStringExtra("SCAN_RESULT");
((EditTextPreference) mDeviceId).setText(mDevice.deviceID);
mDeviceId.setSummary(mDevice.deviceID);
}
}

View file

@ -96,7 +96,7 @@ public class DevicesFragment extends ListFragment implements SyncthingService.On
Intent intent = new Intent(getActivity(), SettingsActivity.class);
intent.setAction(SettingsActivity.ACTION_NODE_SETTINGS_FRAGMENT);
intent.putExtra(SettingsActivity.EXTRA_IS_CREATE, false);
intent.putExtra(DeviceSettingsFragment.EXTRA_NODE_ID, mAdapter.getItem(i).DeviceID);
intent.putExtra(DeviceSettingsFragment.EXTRA_NODE_ID, mAdapter.getItem(i).deviceID);
startActivity(intent);
}

View file

@ -205,9 +205,9 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
*/
@Override
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
RestApi.Connection c = connections.get(RestApi.LOCAL_DEVICE_CONNECTIONS);
mDownload.setText(RestApi.readableTransferRate(mActivity, c.InBits));
mUpload.setText(RestApi.readableTransferRate(mActivity, c.OutBits));
RestApi.Connection c = connections.get(RestApi.TOTAL_STATS);
mDownload.setText(RestApi.readableTransferRate(mActivity, c.inBits));
mUpload.setText(RestApi.readableTransferRate(mActivity, c.outBits));
}
/**

View file

@ -101,11 +101,11 @@ public class FolderSettingsFragment extends PreferenceFragment
}
if (mFolder == null) {
mFolder = new RestApi.Folder();
mFolder.ID = "";
mFolder.Path = "";
mFolder.RescanIntervalS = 259200; // Scan every 3 days (in case inotify dropped some changes)
mFolder.DeviceIds = new ArrayList<>();
mFolder.Versioning = new RestApi.Versioning();
mFolder.id = "";
mFolder.path = "";
mFolder.rescanIntervalS = 259200; // Scan every 3 days (in case inotify dropped some changes)
mFolder.deviceIds = new ArrayList<>();
mFolder.versioning = new RestApi.Versioning();
}
}
}
@ -136,7 +136,7 @@ public class FolderSettingsFragment extends PreferenceFragment
getActivity().setTitle(R.string.edit_folder);
List<RestApi.Folder> folders = mSyncthingService.getApi().getFolders();
for (int i = 0; i < folders.size(); i++) {
if (folders.get(i).ID.equals(
if (folders.get(i).id.equals(
getActivity().getIntent().getStringExtra(EXTRA_REPO_ID))) {
folder = folders.get(i);
break;
@ -150,29 +150,29 @@ public class FolderSettingsFragment extends PreferenceFragment
mFolder = folder;
}
mFolderId.setText(mFolder.ID);
mFolderId.setSummary(mFolder.ID);
mDirectory.setSummary(mFolder.Path);
mFolderMaster.setChecked(mFolder.ReadOnly);
mFolderId.setText(mFolder.id);
mFolderId.setSummary(mFolder.id);
mDirectory.setSummary(mFolder.path);
mFolderMaster.setChecked(mFolder.readOnly);
List<RestApi.Device> devicesList = mSyncthingService.getApi().getDevices(false);
for (RestApi.Device n : devicesList) {
ExtendedCheckBoxPreference cbp = new ExtendedCheckBoxPreference(getActivity(), n);
// Calling addPreference later causes it to change the checked state.
mDevices.addPreference(cbp);
cbp.setTitle(n.Name);
cbp.setTitle(n.name);
cbp.setKey(KEY_NODE_SHARED);
cbp.setOnPreferenceChangeListener(FolderSettingsFragment.this);
cbp.setChecked(false);
for (String n2 : mFolder.DeviceIds) {
if (n2.equals(n.DeviceID)) {
for (String n2 : mFolder.deviceIds) {
if (n2.equals(n.deviceID)) {
cbp.setChecked(true);
}
}
}
mVersioning.setChecked(mFolder.Versioning instanceof RestApi.SimpleVersioning);
mVersioning.setChecked(mFolder.versioning instanceof RestApi.SimpleVersioning);
if (mVersioning.isChecked()) {
mVersioningKeep.setText(mFolder.Versioning.getParams().get("keep"));
mVersioningKeep.setSummary(mFolder.Versioning.getParams().get("keep"));
mVersioningKeep.setText(mFolder.versioning.getParams().get("keep"));
mVersioningKeep.setSummary(mFolder.versioning.getParams().get("keep"));
mVersioningKeep.setEnabled(true);
} else {
mVersioningKeep.setEnabled(false);
@ -201,12 +201,12 @@ public class FolderSettingsFragment extends PreferenceFragment
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.create:
if (mFolder.ID.length() > 64 || !mFolder.ID.matches("[a-zA-Z0-9-_\\.]+")) {
if (mFolder.id.length() > 64 || !mFolder.id.matches("[a-zA-Z0-9-_\\.]+")) {
Toast.makeText(getActivity(), R.string.folder_id_invalid, Toast.LENGTH_LONG)
.show();
return true;
}
if (mFolder.Path.equals("")) {
if (mFolder.path.equals("")) {
Toast.makeText(getActivity(), R.string.folder_path_required, Toast.LENGTH_LONG)
.show();
return true;
@ -249,27 +249,27 @@ public class FolderSettingsFragment extends PreferenceFragment
}
if (preference.equals(mFolderId)) {
mFolder.ID = (String) o;
mFolder.id = (String) o;
folderUpdated();
return true;
} else if (preference.equals(mDirectory)) {
mFolder.Path = (String) o;
mFolder.path = (String) o;
folderUpdated();
return true;
} else if (preference.equals(mFolderMaster)) {
mFolder.ReadOnly = (Boolean) o;
mFolder.readOnly = (Boolean) o;
folderUpdated();
return true;
} else if (preference.getKey().equals(KEY_NODE_SHARED)) {
ExtendedCheckBoxPreference pref = (ExtendedCheckBoxPreference) preference;
RestApi.Device device = (RestApi.Device) pref.getObject();
if ((Boolean) o) {
mFolder.DeviceIds.add(device.DeviceID);
mFolder.deviceIds.add(device.deviceID);
} else {
Iterator<String> it = mFolder.DeviceIds.iterator();
Iterator<String> it = mFolder.deviceIds.iterator();
while (it.hasNext()) {
String n = it.next();
if (n.equals(device.DeviceID)) {
if (n.equals(device.deviceID)) {
it.remove();
}
}
@ -280,23 +280,23 @@ public class FolderSettingsFragment extends PreferenceFragment
mVersioningKeep.setEnabled((Boolean) o);
if ((Boolean) o) {
RestApi.SimpleVersioning v = new RestApi.SimpleVersioning();
mFolder.Versioning = v;
mFolder.versioning = v;
v.setParams(5);
mVersioningKeep.setText("5");
mVersioningKeep.setSummary("5");
} else {
mFolder.Versioning = new RestApi.Versioning();
mFolder.versioning = new RestApi.Versioning();
}
folderUpdated();
return true;
} else if (preference.equals(mVersioningKeep)) {
try {
((RestApi.SimpleVersioning) mFolder.Versioning)
((RestApi.SimpleVersioning) mFolder.versioning)
.setParams(Integer.parseInt((String) o));
folderUpdated();
return true;
} catch (NumberFormatException e) {
Log.w(TAG, "Invalid versioning option: "+ o);
Log.w(TAG, "invalid versioning option: "+ o);
}
}
@ -307,8 +307,8 @@ public class FolderSettingsFragment extends PreferenceFragment
public boolean onPreferenceClick(Preference preference) {
if (preference.equals(mDirectory)) {
Intent intent = new Intent(getActivity(), FolderPickerActivity.class);
if (mFolder.Path.length() > 0) {
intent.putExtra(FolderPickerActivity.EXTRA_INITIAL_DIRECTORY, mFolder.Path);
if (mFolder.path.length() > 0) {
intent.putExtra(FolderPickerActivity.EXTRA_INITIAL_DIRECTORY, mFolder.path);
}
startActivityForResult(intent, DIRECTORY_REQUEST_CODE);
} else if (preference.equals(mDevices) &&
@ -322,8 +322,8 @@ public class FolderSettingsFragment extends PreferenceFragment
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == DIRECTORY_REQUEST_CODE) {
mFolder.Path = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
mDirectory.setSummary(mFolder.Path);
mFolder.path = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
mDirectory.setSummary(mFolder.path);
folderUpdated();
}
}

View file

@ -96,7 +96,7 @@ public class FoldersFragment extends ListFragment implements SyncthingService.On
Intent intent = new Intent(getActivity(), SettingsActivity.class)
.setAction(SettingsActivity.ACTION_REPO_SETTINGS_FRAGMENT)
.putExtra(SettingsActivity.EXTRA_IS_CREATE, false)
.putExtra(FolderSettingsFragment.EXTRA_REPO_ID, mAdapter.getItem(i).ID);
.putExtra(FolderSettingsFragment.EXTRA_REPO_ID, mAdapter.getItem(i).id);
startActivity(intent);
}
@ -106,7 +106,7 @@ public class FoldersFragment extends ListFragment implements SyncthingService.On
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(mAdapter.getItem(i).Path);
Uri uri = Uri.parse(mAdapter.getItem(i).path);
intent.setDataAndType(uri, "*/*");
startActivity(intent);
return true;

View file

@ -29,12 +29,11 @@ public class SettingsFragment extends PreferenceFragment
private static final String SYNCTHING_OPTIONS_KEY = "syncthing_options";
private static final String SYNCTHING_GUI_KEY = "syncthing_gui";
private static final String DEVICE_NAME_KEY = "DeviceName";
private static final String USAGE_REPORT_ACCEPTED = "URAccepted";
private static final String ADDRESS = "Address";
private static final String DEVICE_NAME_KEY = "deviceName";
private static final String USAGE_REPORT_ACCEPTED = "urAccepted";
private static final String ADDRESS = "address";
private static final String GUI_USER = "gui_user";
private static final String GUI_PASSWORD = "gui_password";
private static final String USER_TLS = "UseTLS";
private static final String EXPORT_CONFIG = "export_config";
private static final String IMPORT_CONFIG = "import_config";
private static final String STTRACE = "sttrace";
@ -70,7 +69,7 @@ public class SettingsFragment extends PreferenceFragment
String value;
switch (pref.getKey()) {
case DEVICE_NAME_KEY:
value = api.getLocalDevice().Name;
value = api.getLocalDevice().name;
break;
case USAGE_REPORT_ACCEPTED:
String v = api.getValue(RestApi.TYPE_OPTIONS, pref.getKey());
@ -84,9 +83,6 @@ public class SettingsFragment extends PreferenceFragment
Preference address = mGuiScreen.findPreference(ADDRESS);
applyPreference(address, api.getValue(RestApi.TYPE_GUI, ADDRESS));
Preference tls = mGuiScreen.findPreference(USER_TLS);
applyPreference(tls, api.getValue(RestApi.TYPE_GUI, USER_TLS));
}
}
@ -188,7 +184,7 @@ public class SettingsFragment extends PreferenceFragment
o = Integer.parseInt((String) o);
o = o.toString();
} catch (NumberFormatException e) {
Log.w(TAG, "Invalid number: " + o);
Log.w(TAG, "invalid number: " + o);
return false;
}
}
@ -206,21 +202,21 @@ public class SettingsFragment extends PreferenceFragment
} else if (preference.getKey().equals(DEVICE_NAME_KEY)) {
RestApi.Device old = mSyncthingService.getApi().getLocalDevice();
RestApi.Device updated = new RestApi.Device();
updated.Addresses = old.Addresses;
updated.Compression = old.Compression;
updated.DeviceID = old.DeviceID;
updated.Introducer = old.Introducer;
updated.Name = (String) o;
updated.addresses = old.addresses;
updated.compression = old.compression;
updated.deviceID = old.deviceID;
updated.introducer = old.introducer;
updated.name = (String) o;
mSyncthingService.getApi().editDevice(updated, getActivity(), null);
} else if (preference.getKey().equals(USAGE_REPORT_ACCEPTED)) {
mSyncthingService.getApi().setValue(RestApi.TYPE_OPTIONS, preference.getKey(),
((Boolean) o) ? 1 : 0, false, getActivity());
} else if (mOptionsScreen.findPreference(preference.getKey()) != null) {
boolean isArray = preference.getKey().equals("ListenAddress") ||
preference.getKey().equals("GlobalAnnServers");
boolean isArray = preference.getKey().equals("listenAddress") ||
preference.getKey().equals("globalAnnServers");
mSyncthingService.getApi().setValue(RestApi.TYPE_OPTIONS, preference.getKey(), o,
isArray, getActivity());
} else if (preference.getKey().equals(ADDRESS) || preference.getKey().equals(USER_TLS)) {
} else if (preference.getKey().equals(ADDRESS)) {
mSyncthingService.getApi().setValue(
RestApi.TYPE_GUI, preference.getKey(), o, false, getActivity());
}

View file

@ -29,17 +29,17 @@ public class GetTask extends AsyncTask<String, Void, String> {
private static final String TAG = "GetTask";
public static final String URI_CONFIG = "/rest/config";
public static final String URI_CONFIG = "/rest/system/config";
public static final String URI_VERSION = "/rest/version";
public static final String URI_VERSION = "/rest/system/version";
public static final String URI_SYSTEM = "/rest/system";
public static final String URI_SYSTEM = "/rest/system/status";
public static final String URI_CONNECTIONS = "/rest/connections";
public static final String URI_CONNECTIONS = "/rest/system/connections";
public static final String URI_MODEL = "/rest/model";
public static final String URI_MODEL = "/rest/db/status";
public static final String URI_DEVICEID = "/rest/deviceid";
public static final String URI_DEVICEID = "/rest/svc/deviceid";
private String mHttpsCertPath;

View file

@ -20,9 +20,9 @@ public class PostTask extends AsyncTask<String, Void, Boolean> {
private static final String TAG = "PostTask";
public static final String URI_CONFIG = "/rest/config";
public static final String URI_CONFIG = "/rest/system/config";
public static final String URI_SCAN = "/rest/scan";
public static final String URI_SCAN = "/rest/db/scan";
private String mHttpsCertPath;

View file

@ -11,7 +11,6 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
@ -32,9 +31,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
/**
@ -48,12 +44,12 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
/**
* Parameter for {@link #getValue} or {@link #setValue} referring to "options" config item.
*/
public static final String TYPE_OPTIONS = "Options";
public static final String TYPE_OPTIONS = "options";
/**
* Parameter for {@link #getValue} or {@link #setValue} referring to "gui" config item.
*/
public static final String TYPE_GUI = "GUI";
public static final String TYPE_GUI = "gui";
/**
* The name of the HTTP header used for the syncthing API key.
@ -64,14 +60,14 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
* Key of the map element containing connection info for the local device, in the return
* value of {@link #getConnections}
*/
public static final String LOCAL_DEVICE_CONNECTIONS = "total";
public static final String TOTAL_STATS = "total";
public static class Device implements Serializable {
public String Addresses;
public String Name;
public String DeviceID;
public String Compression;
public boolean Introducer;
public String addresses;
public String name;
public String deviceID;
public String compression;
public boolean introducer;
}
public static class SystemInfo {
@ -85,13 +81,13 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
}
public static class Folder implements Serializable {
public String Path;
public String ID;
public String Invalid;
public List<String> DeviceIds;
public boolean ReadOnly;
public int RescanIntervalS;
public Versioning Versioning;
public String path;
public String id;
public String invalid;
public List<String> deviceIds;
public boolean readOnly;
public int rescanIntervalS;
public Versioning versioning;
}
public static class Versioning implements Serializable {
@ -118,14 +114,14 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
}
public static class Connection {
public String At;
public long InBytesTotal;
public long OutBytesTotal;
public long InBits;
public long OutBits;
public String Address;
public String ClientVersion;
public int Completion;
public String at;
public long inBytesTotal;
public long outBytesTotal;
public long inBits;
public long outBits;
public String address;
public String clientVersion;
public int completion;
}
public static class Model {
@ -163,9 +159,9 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
/**
* Stores the result of the last successful request to {@link GetTask#URI_CONNECTIONS},
* or an empty HashMap.
* or an empty Map.
*/
private HashMap<String, Connection> mPreviousConnections = new HashMap<>();
private Map<String, Connection> mPreviousConnections = new HashMap<>();
/**
* Stores the timestamp of the last successful request to {@link GetTask#URI_CONNECTIONS}.
@ -203,7 +199,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
private final OnApiAvailableListener mOnApiAvailableListener;
/**
* Gets local device id, syncthing version and config, then calls all OnApiAvailableListeners.
* Gets local device ID, syncthing version and config, then calls all OnApiAvailableListeners.
*/
@Override
public void onWebGuiAvailable() {
@ -407,17 +403,17 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
return new ArrayList<>();
try {
JSONArray devices = mConfig.getJSONArray("Devices");
JSONArray devices = mConfig.getJSONArray("devices");
List<Device> ret = new ArrayList<>(devices.length());
for (int i = 0; i < devices.length(); i++) {
JSONObject json = devices.getJSONObject(i);
Device n = new Device();
n.Addresses = json.optJSONArray("Addresses").join(" ").replace("\"", "");
n.Name = json.getString("Name");
n.DeviceID = json.getString("DeviceID");
n.Compression = json.getString("Compression");
n.Introducer = json.getBoolean("Introducer");
if (includeLocal || !mLocalDeviceId.equals(n.DeviceID)) {
n.addresses = json.optJSONArray("addresses").join(" ").replace("\"", "");
n.name = json.getString("name");
n.deviceID = json.getString("deviceID");
n.compression = json.getString("compression");
n.introducer = json.getBoolean("introducer");
if (includeLocal || !mLocalDeviceId.equals(n.deviceID)) {
ret.add(n);
}
}
@ -482,31 +478,31 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
List<Folder> ret;
try {
JSONArray folders = mConfig.getJSONArray("Folders");
JSONArray folders = mConfig.getJSONArray("folders");
ret = new ArrayList<>(folders.length());
for (int i = 0; i < folders.length(); i++) {
JSONObject json = folders.getJSONObject(i);
Folder r = new Folder();
r.Path = json.getString("Path");
r.ID = json.getString("ID");
r.Invalid = json.getString("Invalid");
r.DeviceIds = new ArrayList<>();
JSONArray devices = json.getJSONArray("Devices");
r.path = json.getString("path");
r.id = json.getString("id");
r.invalid = json.getString("invalid");
r.deviceIds = new ArrayList<>();
JSONArray devices = json.getJSONArray("devices");
for (int j = 0; j < devices.length(); j++) {
JSONObject n = devices.getJSONObject(j);
r.DeviceIds.add(n.getString("DeviceID"));
r.deviceIds.add(n.getString("deviceID"));
}
r.ReadOnly = json.getBoolean("ReadOnly");
r.RescanIntervalS = json.getInt("RescanIntervalS");
JSONObject versioning = json.getJSONObject("Versioning");
if (versioning.getString("Type").equals("simple")) {
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();
JSONObject params = versioning.getJSONObject("Params");
JSONObject params = versioning.getJSONObject("params");
sv.setParams(params.getInt("keep"));
r.Versioning = sv;
r.versioning = sv;
} else {
r.Versioning = new Versioning();
r.versioning = new Versioning();
}
ret.add(r);
@ -546,7 +542,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
public interface OnReceiveConnectionsListener {
/**
* @param connections Map from Device ID to {@link Connection}.
* @param connections Map from Device id to {@link Connection}.
* <p/>
* NOTE: The parameter connections is cached internally. Do not modify it or
* any of its contents.
@ -557,7 +553,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
/**
* Returns connection info for the local device and all connected devices.
* <p/>
* Use the key {@link #LOCAL_DEVICE_CONNECTIONS} to get connection info for the local device.
* Use the key {@link #TOTAL_STATS} to get connection info for the local device.
*/
public void getConnections(final OnReceiveConnectionsListener listener) {
new GetTask(mHttpsCertPath) {
@ -575,27 +571,35 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
try {
JSONObject json = new JSONObject(s);
String[] names = json.names().join(" ").replace("\"", "").split(" ");
HashMap<String, Connection> connections = new HashMap<String, Connection>();
for (String deviceId : names) {
Map<String, JSONObject> jsonConnections = new HashMap<>();
jsonConnections.put(TOTAL_STATS, json.getJSONObject(TOTAL_STATS));
JSONArray extConnections = json.getJSONObject("connections").names();
if (extConnections != null) {
for (int i = 0; i < extConnections.length(); i++) {
String deviceId = extConnections.get(i).toString();
jsonConnections.put(deviceId, json.getJSONObject("connections").getJSONObject(deviceId));
}
}
Map<String, Connection> connections = new HashMap<>();
for (String deviceId : jsonConnections.keySet()) {
Connection c = new Connection();
JSONObject conn = json.getJSONObject(deviceId);
c.Address = deviceId;
c.At = conn.getString("At");
c.InBytesTotal = conn.getLong("InBytesTotal");
c.OutBytesTotal = conn.getLong("OutBytesTotal");
c.Address = conn.getString("Address");
c.ClientVersion = conn.getString("ClientVersion");
c.Completion = getDeviceCompletion(deviceId);
JSONObject conn = jsonConnections.get(deviceId);
c.address = deviceId;
c.at = conn.getString("at");
c.inBytesTotal = conn.getLong("inBytesTotal");
c.outBytesTotal = conn.getLong("outBytesTotal");
c.address = conn.getString("address");
c.clientVersion = conn.getString("clientVersion");
c.completion = getDeviceCompletion(deviceId);
Connection prev = (mPreviousConnections.containsKey(deviceId))
? mPreviousConnections.get(deviceId)
: new Connection();
mPreviousConnectionTime = now;
c.InBits = Math.max(0, 8 *
(conn.getLong("InBytesTotal") - prev.InBytesTotal) / timeElapsed);
c.OutBits = Math.max(0, 8 *
(conn.getLong("OutBytesTotal") - prev.OutBytesTotal) / timeElapsed);
c.inBits = Math.max(0, 8 *
(conn.getLong("inBytesTotal") - prev.inBytesTotal) / timeElapsed);
c.outBits = Math.max(0, 8 *
(conn.getLong("outBytesTotal") - prev.outBytesTotal) / timeElapsed);
connections.put(deviceId, c);
@ -619,7 +623,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
boolean isShared = false;
outerloop:
for (Folder r : getFolders()) {
for (String n : r.DeviceIds) {
for (String n : r.deviceIds) {
if (n.equals(deviceId)) {
isShared = true;
break outerloop;
@ -650,7 +654,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
}
/**
* Returns status information about the folder with the given ID.
* Returns status information about the folder with the given id.
*/
public void getModel(final String folderId, final OnReceiveModelListener listener) {
new GetTask(mHttpsCertPath) {
@ -711,7 +715,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
*/
public void editDevice(final Device device, final Activity activity,
final OnDeviceIdNormalizedListener listener) {
normalizeDeviceId(device.DeviceID,
normalizeDeviceId(device.deviceID,
new RestApi.OnDeviceIdNormalizedListener() {
@Override
public void onDeviceIdNormalized(String normalizedId, String error) {
@ -719,17 +723,17 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
if (normalizedId == null)
return;
device.DeviceID = normalizedId;
device.deviceID = normalizedId;
// If the device already exists, just update it.
boolean create = true;
for (RestApi.Device n : getDevices(true)) {
if (n.DeviceID.equals(device.DeviceID)) {
if (n.deviceID.equals(device.deviceID)) {
create = false;
}
}
try {
JSONArray devices = mConfig.getJSONArray("Devices");
JSONArray devices = mConfig.getJSONArray("devices");
JSONObject n = null;
if (create) {
n = new JSONObject();
@ -737,17 +741,17 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
} else {
for (int i = 0; i < devices.length(); i++) {
JSONObject json = devices.getJSONObject(i);
if (device.DeviceID.equals(json.getString("DeviceID"))) {
if (device.deviceID.equals(json.getString("deviceID"))) {
n = devices.getJSONObject(i);
break;
}
}
}
n.put("DeviceID", device.DeviceID);
n.put("Name", device.Name);
n.put("Addresses", listToJson(device.Addresses.split(" ")));
n.put("Compression", device.Compression);
n.put("Introducer", device.Introducer);
n.put("deviceID", device.deviceID);
n.put("name", device.name);
n.put("addresses", listToJson(device.addresses.split(" ")));
n.put("compression", device.compression);
n.put("introducer", device.introducer);
requireRestart(activity);
} catch (JSONException e) {
Log.w(TAG, "Failed to read devices", e);
@ -762,13 +766,13 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
*/
public boolean deleteDevice(Device device, Activity activity) {
try {
JSONArray devices = mConfig.getJSONArray("Devices");
JSONArray devices = mConfig.getJSONArray("devices");
for (int i = 0; i < devices.length(); i++) {
JSONObject json = devices.getJSONObject(i);
if (device.DeviceID.equals(json.getString("DeviceID"))) {
mConfig.remove("Devices");
mConfig.put("Devices", delete(devices, devices.getJSONObject(i)));
if (device.deviceID.equals(json.getString("deviceID"))) {
mConfig.remove("devices");
mConfig.put("devices", delete(devices, devices.getJSONObject(i)));
break;
}
}
@ -785,7 +789,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
*/
public boolean editFolder(Folder folder, boolean create, Activity activity) {
try {
JSONArray folders = mConfig.getJSONArray("Folders");
JSONArray folders = mConfig.getJSONArray("folders");
JSONObject r = null;
if (create) {
r = new JSONObject();
@ -793,35 +797,35 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
} else {
for (int i = 0; i < folders.length(); i++) {
JSONObject json = folders.getJSONObject(i);
if (folder.ID.equals(json.getString("ID"))) {
if (folder.id.equals(json.getString("id"))) {
r = folders.getJSONObject(i);
break;
}
}
}
r.put("Path", folder.Path);
r.put("ID", folder.ID);
r.put("IgnorePerms", true);
r.put("ReadOnly", folder.ReadOnly);
r.put("path", folder.path);
r.put("id", folder.id);
r.put("ignorePerms", true);
r.put("readOnly", folder.readOnly);
JSONArray devices = new JSONArray();
for (String n : folder.DeviceIds) {
for (String n : folder.deviceIds) {
JSONObject element = new JSONObject();
element.put("DeviceID", n);
element.put("deviceID", n);
devices.put(element);
}
r.put("Devices", devices);
r.put("devices", devices);
JSONObject versioning = new JSONObject();
versioning.put("Type", folder.Versioning.getType());
versioning.put("type", folder.versioning.getType());
JSONObject params = new JSONObject();
versioning.put("Params", params);
for (String key : folder.Versioning.getParams().keySet()) {
params.put(key, folder.Versioning.getParams().get(key));
versioning.put("params", params);
for (String key : folder.versioning.getParams().keySet()) {
params.put(key, folder.versioning.getParams().get(key));
}
r.put("RescanIntervalS", folder.RescanIntervalS);
r.put("Versioning", versioning);
r.put("rescanIntervalS", folder.rescanIntervalS);
r.put("versioning", versioning);
requireRestart(activity);
} catch (JSONException e) {
Log.w(TAG, "Failed to edit folder " + folder.ID + " at " + folder.Path, e);
Log.w(TAG, "Failed to edit folder " + folder.id + " at " + folder.path, e);
return false;
}
return true;
@ -832,13 +836,13 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
*/
public boolean deleteFolder(Folder folder, Activity activity) {
try {
JSONArray folders = mConfig.getJSONArray("Folders");
JSONArray folders = mConfig.getJSONArray("folders");
for (int i = 0; i < folders.length(); i++) {
JSONObject json = folders.getJSONObject(i);
if (folder.ID.equals(json.getString("ID"))) {
mConfig.remove("Folders");
mConfig.put("Folders", delete(folders, folders.getJSONObject(i)));
if (folder.id.equals(json.getString("id"))) {
mConfig.remove("folders");
mConfig.put("folders", delete(folders, folders.getJSONObject(i)));
break;
}
}
@ -899,7 +903,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
}
/**
* Shares the given device id via Intent. Must be called from an Activity.
* Shares the given device ID via Intent. Must be called from an Activity.
*/
public static void shareDeviceId(Context context, String id) {
Intent shareIntent = new Intent();
@ -946,7 +950,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
*/
public Device getLocalDevice() {
for (Device d : getDevices(true)) {
if (d.DeviceID.equals(mLocalDeviceId)) {
if (d.deviceID.equals(mLocalDeviceId)) {
return d;
}
}

View file

@ -56,17 +56,17 @@ public class SyncthingService extends Service {
public static final int GUI_UPDATE_INTERVAL = 1000;
/**
* Name of the public key file in the data directory.
* name of the public key file in the data directory.
*/
public static final String PUBLIC_KEY_FILE = "cert.pem";
/**
* Name of the private key file in the data directory.
* name of the private key file in the data directory.
*/
public static final String PRIVATE_KEY_FILE = "key.pem";
/**
* Name of the public HTTPS CA file in the data directory.
* name of the public HTTPS CA file in the data directory.
*/
public static final String HTTPS_CERT_FILE = "https-cert.pem";
@ -77,7 +77,7 @@ public class SyncthingService extends Service {
new File(Environment.getExternalStorageDirectory(), "backups/syncthing");
/**
* Path to the native, integrated syncthing binary, relative to the data folder
* path to the native, integrated syncthing binary, relative to the data folder
*/
public static final String BINARY_NAME = "lib/libsyncthing.so";

View file

@ -42,22 +42,22 @@ public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
TextView download = (TextView) convertView.findViewById(R.id.download);
TextView upload = (TextView) convertView.findViewById(R.id.upload);
String deviceId = getItem(position).DeviceID;
String deviceId = getItem(position).deviceID;
RestApi.Connection conn = mConnections.get(deviceId);
name.setText(getItem(position).Name);
name.setText(getItem(position).name);
Resources r = getContext().getResources();
if (conn != null) {
if (conn.Completion == 100) {
if (conn.completion == 100) {
status.setText(r.getString(R.string.device_up_to_date));
status.setTextColor(r.getColor(R.color.text_green));
}
else {
status.setText(r.getString(R.string.device_syncing, conn.Completion));
status.setText(r.getString(R.string.device_syncing, conn.completion));
status.setTextColor(r.getColor(R.color.text_blue));
}
download.setText(RestApi.readableTransferRate(getContext(), conn.InBits));
upload.setText(RestApi.readableTransferRate(getContext(), conn.OutBits));
download.setText(RestApi.readableTransferRate(getContext(), conn.inBits));
upload.setText(RestApi.readableTransferRate(getContext(), conn.outBits));
}
else {
download.setText("0 " + r.getStringArray(R.array.transfer_rate_units)[0]);

View file

@ -42,7 +42,7 @@ public class FolderObserver extends FileObserver {
@Override
public String getMessage() {
return "Path " + mPath + " does not exist, aborting file observer";
return "path " + mPath + " does not exist, aborting file observer";
}
}
@ -51,19 +51,19 @@ public class FolderObserver extends FileObserver {
*
* @param listener The listener where changes should be sent to.
* @param folder The folder where this folder belongs to.
* @param path Path to the monitored folder, relative to folder root.
* @param path path to the monitored folder, relative to folder root.
*/
private FolderObserver(OnFolderFileChangeListener listener, RestApi.Folder folder, String path) {
super(folder.Path + "/" + path,
super(folder.path + "/" + path,
ATTRIB | CLOSE_WRITE | CREATE | DELETE | DELETE_SELF | MODIFY | MOVED_FROM |
MOVED_TO | MOVE_SELF);
mListener = listener;
mFolder = folder;
mPath = path;
Log.v(TAG, "observer created for " + path + " in " + folder.ID);
Log.v(TAG, "observer created for " + path + " in " + folder.id);
startWatching();
File currentFolder = new File(folder.Path, path);
File currentFolder = new File(folder.path, path);
if (!currentFolder.exists()) {
throw new FolderNotExistingException(currentFolder.getAbsolutePath());
}
@ -107,7 +107,7 @@ public class FolderObserver extends FileObserver {
break;
}
}
mListener.onFolderFileChange(mFolder.ID, fullPath.getPath());
mListener.onFolderFileChange(mFolder.id, fullPath.getPath());
break;
case MOVED_TO:
// fall through
@ -117,7 +117,7 @@ public class FolderObserver extends FileObserver {
}
// fall through
default:
mListener.onFolderFileChange(mFolder.ID, fullPath.getPath());
mListener.onFolderFileChange(mFolder.id, fullPath.getPath());
}
}

View file

@ -42,10 +42,10 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
TextView invalid = (TextView) convertView.findViewById(R.id.invalid);
RestApi.Folder folder = getItem(position);
RestApi.Model model = mModels.get(folder.ID);
id.setText(folder.ID);
RestApi.Model model = mModels.get(folder.id);
id.setText(folder.id);
state.setTextColor(getContext().getResources().getColor(R.color.text_green));
directory.setText((folder.Path));
directory.setText((folder.path));
if (model != null) {
int percentage = (model.globalBytes != 0)
? (int) Math.floor(100 * model.inSyncBytes / model.globalBytes)
@ -57,13 +57,13 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
.getString(R.string.files, model.inSyncFiles, model.globalFiles));
size.setText(RestApi.readableFileSize(getContext(), model.inSyncBytes) + " / " +
RestApi.readableFileSize(getContext(), model.globalBytes));
if (folder.Invalid.equals("")) {
if (folder.invalid.equals("")) {
invalid.setText(model.invalid);
invalid.setVisibility((model.invalid.equals("")) ? View.GONE : View.VISIBLE);
}
} else {
invalid.setText(folder.Invalid);
invalid.setVisibility((folder.Invalid.equals("")) ? View.GONE : View.VISIBLE);
invalid.setText(folder.invalid);
invalid.setVisibility((folder.invalid.equals("")) ? View.GONE : View.VISIBLE);
}
return convertView;
@ -85,7 +85,7 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
for (int i = 0; i < getCount(); i++) {
if (i >= listView.getFirstVisiblePosition() &&
i <= listView.getLastVisiblePosition()) {
api.getModel(getItem(i).ID, this);
api.getModel(getItem(i).id, this);
}
}
}

View file

@ -35,49 +35,49 @@
android:title="@string/syncthing_options">
<EditTextPreference
android:key="DeviceName"
android:key="deviceName"
android:title="@string/device_name"
android:persistent="false" />
<EditTextPreference
android:key="ListenAddress"
android:key="listenAddress"
android:title="@string/listen_address"
android:persistent="false" />
<EditTextPreference
android:key="MaxRecvKbps"
android:key="maxRecvKbps"
android:title="@string/max_recv_kbps"
android:numeric="integer"
android:persistent="false" />
<EditTextPreference
android:key="MaxSendKbps"
android:key="maxSendKbps"
android:title="@string/max_send_kbps"
android:numeric="integer"
android:persistent="false" />
<CheckBoxPreference
android:key="GlobalAnnEnabled"
android:key="globalAnnounceEnabled"
android:title="@string/global_announce_enabled"
android:persistent="false" />
<CheckBoxPreference
android:key="LocalAnnEnabled"
android:key="localAnnounceEnabled"
android:title="@string/local_announce_enabled"
android:persistent="false" />
<CheckBoxPreference
android:key="UPnPEnabled"
android:key="upnpEnabled"
android:title="@string/upnp_enabled"
android:persistent="false" />
<EditTextPreference
android:key="GlobalAnnServers"
android:key="globalAnnounceServers"
android:title="@string/global_announce_server"
android:persistent="false" />
<CheckBoxPreference
android:key="URAccepted"
android:key="urAccepted"
android:title="@string/usage_reporting"
android:persistent="false" />
@ -88,7 +88,7 @@
android:title="@string/syncthing_gui">
<EditTextPreference
android:key="Address"
android:key="address"
android:title="@string/gui_address"
android:persistent="false" />