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:
parent
df92b179c7
commit
4146970e64
17 changed files with 254 additions and 254 deletions
|
@ -25,13 +25,13 @@ public class DevicesAdapterTest extends AndroidTestCase {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
mAdapter = new DevicesAdapter(getContext());
|
mAdapter = new DevicesAdapter(getContext());
|
||||||
mDevice.Addresses = "127.0.0.1:12345";
|
mDevice.addresses = "127.0.0.1:12345";
|
||||||
mDevice.Name = "the device";
|
mDevice.name = "the device";
|
||||||
mDevice.DeviceID = "123-456-789";
|
mDevice.deviceID = "123-456-789";
|
||||||
|
|
||||||
mConnection.Completion = 100;
|
mConnection.completion = 100;
|
||||||
mConnection.InBits = 1048576;
|
mConnection.inBits = 1048576;
|
||||||
mConnection.OutBits = 1073741824;
|
mConnection.outBits = 1073741824;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class DevicesAdapterTest extends AndroidTestCase {
|
||||||
mAdapter.add(Arrays.asList(mDevice));
|
mAdapter.add(Arrays.asList(mDevice));
|
||||||
View v = mAdapter.getView(0, null, null);
|
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),
|
assertEquals(getContext().getString(R.string.device_disconnected),
|
||||||
((TextView) v.findViewById(R.id.status)).getText().toString());
|
((TextView) v.findViewById(R.id.status)).getText().toString());
|
||||||
assertFalse(((TextView) v.findViewById(R.id.status)).getText().equals(""));
|
assertFalse(((TextView) v.findViewById(R.id.status)).getText().equals(""));
|
||||||
|
@ -52,7 +52,7 @@ public class DevicesAdapterTest extends AndroidTestCase {
|
||||||
public void testGetViewConnections() {
|
public void testGetViewConnections() {
|
||||||
mAdapter.add(Arrays.asList(mDevice));
|
mAdapter.add(Arrays.asList(mDevice));
|
||||||
mAdapter.onReceiveConnections(
|
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);
|
View v = mAdapter.getView(0, null, null);
|
||||||
|
|
||||||
assertEquals(getContext().getString(R.string.device_up_to_date),
|
assertEquals(getContext().getString(R.string.device_up_to_date),
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class FolderObserverTest extends AndroidTestCase
|
||||||
|
|
||||||
private RestApi.Folder createFolder(String id) {
|
private RestApi.Folder createFolder(String id) {
|
||||||
RestApi.Folder r = new RestApi.Folder();
|
RestApi.Folder r = new RestApi.Folder();
|
||||||
r.Path = mTestFolder.getAbsolutePath();
|
r.path = mTestFolder.getAbsolutePath();
|
||||||
r.ID = id;
|
r.id = id;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,12 @@ public class FoldersAdapterTest extends AndroidTestCase {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
mAdapter = new FoldersAdapter(getContext());
|
mAdapter = new FoldersAdapter(getContext());
|
||||||
mFolder.Path = "/my/dir/";
|
mFolder.path = "/my/dir/";
|
||||||
mFolder.ID = "id 123";
|
mFolder.id = "id 123";
|
||||||
mFolder.Invalid = "all good";
|
mFolder.invalid = "all good";
|
||||||
mFolder.DeviceIds = new ArrayList<>();
|
mFolder.deviceIds = new ArrayList<>();
|
||||||
mFolder.ReadOnly = false;
|
mFolder.readOnly = false;
|
||||||
mFolder.Versioning = new RestApi.Versioning();
|
mFolder.versioning = new RestApi.Versioning();
|
||||||
|
|
||||||
mModel.state = "idle";
|
mModel.state = "idle";
|
||||||
mModel.localFiles = 50;
|
mModel.localFiles = 50;
|
||||||
|
@ -43,15 +43,15 @@ public class FoldersAdapterTest extends AndroidTestCase {
|
||||||
public void testGetViewNoModel() {
|
public void testGetViewNoModel() {
|
||||||
mAdapter.add(Arrays.asList(mFolder));
|
mAdapter.add(Arrays.asList(mFolder));
|
||||||
View v = mAdapter.getView(0, null, null);
|
View v = mAdapter.getView(0, null, null);
|
||||||
assertEquals(mFolder.ID, ((TextView) v.findViewById(R.id.id)).getText());
|
assertEquals(mFolder.id, ((TextView) v.findViewById(R.id.id)).getText());
|
||||||
assertEquals(mFolder.Path, ((TextView) v.findViewById(R.id.directory)).getText());
|
assertEquals(mFolder.path, ((TextView) v.findViewById(R.id.directory)).getText());
|
||||||
assertEquals(mFolder.Invalid, ((TextView) v.findViewById(R.id.invalid)).getText());
|
assertEquals(mFolder.invalid, ((TextView) v.findViewById(R.id.invalid)).getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
public void testGetViewModel() {
|
public void testGetViewModel() {
|
||||||
mAdapter.add(Arrays.asList(mFolder));
|
mAdapter.add(Arrays.asList(mFolder));
|
||||||
mAdapter.onReceiveModel(mFolder.ID, mModel);
|
mAdapter.onReceiveModel(mFolder.id, mModel);
|
||||||
View v = mAdapter.getView(0, null, null);
|
View v = mAdapter.getView(0, null, null);
|
||||||
assertFalse(((TextView) v.findViewById(R.id.state)).getText().toString().equals(""));
|
assertFalse(((TextView) v.findViewById(R.id.state)).getText().toString().equals(""));
|
||||||
String items = ((TextView) v.findViewById(R.id.items)).getText().toString();
|
String items = ((TextView) v.findViewById(R.id.items)).getText().toString();
|
||||||
|
|
|
@ -99,12 +99,12 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
}
|
}
|
||||||
if (mDevice == null) {
|
if (mDevice == null) {
|
||||||
mDevice = new RestApi.Device();
|
mDevice = new RestApi.Device();
|
||||||
mDevice.Name = "";
|
mDevice.name = "";
|
||||||
mDevice.DeviceID = "";
|
mDevice.deviceID = "";
|
||||||
mDevice.Addresses = "dynamic";
|
mDevice.addresses = "dynamic";
|
||||||
mDevice.Compression = "always";
|
mDevice.compression = "always";
|
||||||
mDevice.Introducer = false;
|
mDevice.introducer = false;
|
||||||
((EditTextPreference) mDeviceId).setText(mDevice.DeviceID);
|
((EditTextPreference) mDeviceId).setText(mDevice.deviceID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
getActivity().setTitle(R.string.edit_device);
|
getActivity().setTitle(R.string.edit_device);
|
||||||
List<RestApi.Device> devices = mSyncthingService.getApi().getDevices(false);
|
List<RestApi.Device> devices = mSyncthingService.getApi().getDevices(false);
|
||||||
for (int i = 0; i < devices.size(); i++) {
|
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))) {
|
getActivity().getIntent().getStringExtra(EXTRA_NODE_ID))) {
|
||||||
device = devices.get(i);
|
device = devices.get(i);
|
||||||
break;
|
break;
|
||||||
|
@ -157,14 +157,14 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
|
|
||||||
mSyncthingService.getApi().getConnections(DeviceSettingsFragment.this);
|
mSyncthingService.getApi().getConnections(DeviceSettingsFragment.this);
|
||||||
|
|
||||||
mDeviceId.setSummary(mDevice.DeviceID);
|
mDeviceId.setSummary(mDevice.deviceID);
|
||||||
mName.setText((mDevice.Name));
|
mName.setText((mDevice.name));
|
||||||
mName.setSummary(mDevice.Name);
|
mName.setSummary(mDevice.name);
|
||||||
mAddresses.setText(mDevice.Addresses);
|
mAddresses.setText(mDevice.addresses);
|
||||||
mAddresses.setSummary(mDevice.Addresses);
|
mAddresses.setSummary(mDevice.addresses);
|
||||||
mCompression.setValue(mDevice.Compression);
|
mCompression.setValue(mDevice.compression);
|
||||||
mCompression.setSummary(mDevice.Compression);
|
mCompression.setSummary(mDevice.compression);
|
||||||
mIntroducer.setChecked(mDevice.Introducer);
|
mIntroducer.setChecked(mDevice.introducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -184,12 +184,12 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.create:
|
case R.id.create:
|
||||||
if (mDevice.DeviceID.equals("")) {
|
if (mDevice.deviceID.equals("")) {
|
||||||
Toast.makeText(getActivity(), R.string.device_id_required, Toast.LENGTH_LONG)
|
Toast.makeText(getActivity(), R.string.device_id_required, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (mDevice.Name.equals("")) {
|
if (mDevice.name.equals("")) {
|
||||||
Toast.makeText(getActivity(), R.string.device_name_required, Toast.LENGTH_LONG)
|
Toast.makeText(getActivity(), R.string.device_name_required, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
return true;
|
return true;
|
||||||
|
@ -197,7 +197,7 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
mSyncthingService.getApi().editDevice(mDevice, getActivity(), this);
|
mSyncthingService.getApi().editDevice(mDevice, getActivity(), this);
|
||||||
return true;
|
return true;
|
||||||
case R.id.share_device_id:
|
case R.id.share_device_id:
|
||||||
RestApi.shareDeviceId(getActivity(), mDevice.DeviceID);
|
RestApi.shareDeviceId(getActivity(), mDevice.deviceID);
|
||||||
return true;
|
return true;
|
||||||
case R.id.delete:
|
case R.id.delete:
|
||||||
new AlertDialog.Builder(getActivity())
|
new AlertDialog.Builder(getActivity())
|
||||||
|
@ -230,23 +230,23 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
pref.setSummary((String) o);
|
pref.setSummary((String) o);
|
||||||
}
|
}
|
||||||
if (preference.equals(mDeviceId)) {
|
if (preference.equals(mDeviceId)) {
|
||||||
mDevice.DeviceID = (String) o;
|
mDevice.deviceID = (String) o;
|
||||||
deviceUpdated();
|
deviceUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.equals(mName)) {
|
} else if (preference.equals(mName)) {
|
||||||
mDevice.Name = (String) o;
|
mDevice.name = (String) o;
|
||||||
deviceUpdated();
|
deviceUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.equals(mAddresses)) {
|
} else if (preference.equals(mAddresses)) {
|
||||||
mDevice.Addresses = (String) o;
|
mDevice.addresses = (String) o;
|
||||||
deviceUpdated();
|
deviceUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.equals(mCompression)) {
|
} else if (preference.equals(mCompression)) {
|
||||||
mDevice.Compression = (String) o;
|
mDevice.compression = (String) o;
|
||||||
deviceUpdated();
|
deviceUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.equals(mIntroducer)) {
|
} else if (preference.equals(mIntroducer)) {
|
||||||
mDevice.Introducer = (Boolean) o;
|
mDevice.introducer = (Boolean) o;
|
||||||
deviceUpdated();
|
deviceUpdated();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
if (preference.equals(mDeviceId)) {
|
if (preference.equals(mDeviceId)) {
|
||||||
mSyncthingService.getApi().copyDeviceId(mDevice.DeviceID);
|
mSyncthingService.getApi().copyDeviceId(mDevice.deviceID);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -272,9 +272,9 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
|
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
|
||||||
if (mVersion == null || mCurrentAddress == null)
|
if (mVersion == null || mCurrentAddress == null)
|
||||||
return;
|
return;
|
||||||
if (connections.containsKey(mDevice.DeviceID)) {
|
if (connections.containsKey(mDevice.deviceID)) {
|
||||||
mVersion.setSummary(connections.get(mDevice.DeviceID).ClientVersion);
|
mVersion.setSummary(connections.get(mDevice.deviceID).clientVersion);
|
||||||
mCurrentAddress.setSummary(connections.get(mDevice.DeviceID).Address);
|
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
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == SCAN_QR_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
if (requestCode == SCAN_QR_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
||||||
mDevice.DeviceID = data.getStringExtra("SCAN_RESULT");
|
mDevice.deviceID = data.getStringExtra("SCAN_RESULT");
|
||||||
((EditTextPreference) mDeviceId).setText(mDevice.DeviceID);
|
((EditTextPreference) mDeviceId).setText(mDevice.deviceID);
|
||||||
mDeviceId.setSummary(mDevice.DeviceID);
|
mDeviceId.setSummary(mDevice.deviceID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class DevicesFragment extends ListFragment implements SyncthingService.On
|
||||||
Intent intent = new Intent(getActivity(), SettingsActivity.class);
|
Intent intent = new Intent(getActivity(), SettingsActivity.class);
|
||||||
intent.setAction(SettingsActivity.ACTION_NODE_SETTINGS_FRAGMENT);
|
intent.setAction(SettingsActivity.ACTION_NODE_SETTINGS_FRAGMENT);
|
||||||
intent.putExtra(SettingsActivity.EXTRA_IS_CREATE, false);
|
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);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,9 +205,9 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
|
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
|
||||||
RestApi.Connection c = connections.get(RestApi.LOCAL_DEVICE_CONNECTIONS);
|
RestApi.Connection c = connections.get(RestApi.TOTAL_STATS);
|
||||||
mDownload.setText(RestApi.readableTransferRate(mActivity, c.InBits));
|
mDownload.setText(RestApi.readableTransferRate(mActivity, c.inBits));
|
||||||
mUpload.setText(RestApi.readableTransferRate(mActivity, c.OutBits));
|
mUpload.setText(RestApi.readableTransferRate(mActivity, c.outBits));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -101,11 +101,11 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
}
|
}
|
||||||
if (mFolder == null) {
|
if (mFolder == null) {
|
||||||
mFolder = new RestApi.Folder();
|
mFolder = new RestApi.Folder();
|
||||||
mFolder.ID = "";
|
mFolder.id = "";
|
||||||
mFolder.Path = "";
|
mFolder.path = "";
|
||||||
mFolder.RescanIntervalS = 259200; // Scan every 3 days (in case inotify dropped some changes)
|
mFolder.rescanIntervalS = 259200; // Scan every 3 days (in case inotify dropped some changes)
|
||||||
mFolder.DeviceIds = new ArrayList<>();
|
mFolder.deviceIds = new ArrayList<>();
|
||||||
mFolder.Versioning = new RestApi.Versioning();
|
mFolder.versioning = new RestApi.Versioning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
getActivity().setTitle(R.string.edit_folder);
|
getActivity().setTitle(R.string.edit_folder);
|
||||||
List<RestApi.Folder> folders = mSyncthingService.getApi().getFolders();
|
List<RestApi.Folder> folders = mSyncthingService.getApi().getFolders();
|
||||||
for (int i = 0; i < folders.size(); i++) {
|
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))) {
|
getActivity().getIntent().getStringExtra(EXTRA_REPO_ID))) {
|
||||||
folder = folders.get(i);
|
folder = folders.get(i);
|
||||||
break;
|
break;
|
||||||
|
@ -150,29 +150,29 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
mFolder = folder;
|
mFolder = folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
mFolderId.setText(mFolder.ID);
|
mFolderId.setText(mFolder.id);
|
||||||
mFolderId.setSummary(mFolder.ID);
|
mFolderId.setSummary(mFolder.id);
|
||||||
mDirectory.setSummary(mFolder.Path);
|
mDirectory.setSummary(mFolder.path);
|
||||||
mFolderMaster.setChecked(mFolder.ReadOnly);
|
mFolderMaster.setChecked(mFolder.readOnly);
|
||||||
List<RestApi.Device> devicesList = mSyncthingService.getApi().getDevices(false);
|
List<RestApi.Device> devicesList = mSyncthingService.getApi().getDevices(false);
|
||||||
for (RestApi.Device n : devicesList) {
|
for (RestApi.Device n : devicesList) {
|
||||||
ExtendedCheckBoxPreference cbp = new ExtendedCheckBoxPreference(getActivity(), n);
|
ExtendedCheckBoxPreference cbp = new ExtendedCheckBoxPreference(getActivity(), n);
|
||||||
// Calling addPreference later causes it to change the checked state.
|
// Calling addPreference later causes it to change the checked state.
|
||||||
mDevices.addPreference(cbp);
|
mDevices.addPreference(cbp);
|
||||||
cbp.setTitle(n.Name);
|
cbp.setTitle(n.name);
|
||||||
cbp.setKey(KEY_NODE_SHARED);
|
cbp.setKey(KEY_NODE_SHARED);
|
||||||
cbp.setOnPreferenceChangeListener(FolderSettingsFragment.this);
|
cbp.setOnPreferenceChangeListener(FolderSettingsFragment.this);
|
||||||
cbp.setChecked(false);
|
cbp.setChecked(false);
|
||||||
for (String n2 : mFolder.DeviceIds) {
|
for (String n2 : mFolder.deviceIds) {
|
||||||
if (n2.equals(n.DeviceID)) {
|
if (n2.equals(n.deviceID)) {
|
||||||
cbp.setChecked(true);
|
cbp.setChecked(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mVersioning.setChecked(mFolder.Versioning instanceof RestApi.SimpleVersioning);
|
mVersioning.setChecked(mFolder.versioning instanceof RestApi.SimpleVersioning);
|
||||||
if (mVersioning.isChecked()) {
|
if (mVersioning.isChecked()) {
|
||||||
mVersioningKeep.setText(mFolder.Versioning.getParams().get("keep"));
|
mVersioningKeep.setText(mFolder.versioning.getParams().get("keep"));
|
||||||
mVersioningKeep.setSummary(mFolder.Versioning.getParams().get("keep"));
|
mVersioningKeep.setSummary(mFolder.versioning.getParams().get("keep"));
|
||||||
mVersioningKeep.setEnabled(true);
|
mVersioningKeep.setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
mVersioningKeep.setEnabled(false);
|
mVersioningKeep.setEnabled(false);
|
||||||
|
@ -201,12 +201,12 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.create:
|
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)
|
Toast.makeText(getActivity(), R.string.folder_id_invalid, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (mFolder.Path.equals("")) {
|
if (mFolder.path.equals("")) {
|
||||||
Toast.makeText(getActivity(), R.string.folder_path_required, Toast.LENGTH_LONG)
|
Toast.makeText(getActivity(), R.string.folder_path_required, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
return true;
|
return true;
|
||||||
|
@ -249,27 +249,27 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preference.equals(mFolderId)) {
|
if (preference.equals(mFolderId)) {
|
||||||
mFolder.ID = (String) o;
|
mFolder.id = (String) o;
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.equals(mDirectory)) {
|
} else if (preference.equals(mDirectory)) {
|
||||||
mFolder.Path = (String) o;
|
mFolder.path = (String) o;
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.equals(mFolderMaster)) {
|
} else if (preference.equals(mFolderMaster)) {
|
||||||
mFolder.ReadOnly = (Boolean) o;
|
mFolder.readOnly = (Boolean) o;
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.getKey().equals(KEY_NODE_SHARED)) {
|
} else if (preference.getKey().equals(KEY_NODE_SHARED)) {
|
||||||
ExtendedCheckBoxPreference pref = (ExtendedCheckBoxPreference) preference;
|
ExtendedCheckBoxPreference pref = (ExtendedCheckBoxPreference) preference;
|
||||||
RestApi.Device device = (RestApi.Device) pref.getObject();
|
RestApi.Device device = (RestApi.Device) pref.getObject();
|
||||||
if ((Boolean) o) {
|
if ((Boolean) o) {
|
||||||
mFolder.DeviceIds.add(device.DeviceID);
|
mFolder.deviceIds.add(device.deviceID);
|
||||||
} else {
|
} else {
|
||||||
Iterator<String> it = mFolder.DeviceIds.iterator();
|
Iterator<String> it = mFolder.deviceIds.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
String n = it.next();
|
String n = it.next();
|
||||||
if (n.equals(device.DeviceID)) {
|
if (n.equals(device.deviceID)) {
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,23 +280,23 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
mVersioningKeep.setEnabled((Boolean) o);
|
mVersioningKeep.setEnabled((Boolean) o);
|
||||||
if ((Boolean) o) {
|
if ((Boolean) o) {
|
||||||
RestApi.SimpleVersioning v = new RestApi.SimpleVersioning();
|
RestApi.SimpleVersioning v = new RestApi.SimpleVersioning();
|
||||||
mFolder.Versioning = v;
|
mFolder.versioning = v;
|
||||||
v.setParams(5);
|
v.setParams(5);
|
||||||
mVersioningKeep.setText("5");
|
mVersioningKeep.setText("5");
|
||||||
mVersioningKeep.setSummary("5");
|
mVersioningKeep.setSummary("5");
|
||||||
} else {
|
} else {
|
||||||
mFolder.Versioning = new RestApi.Versioning();
|
mFolder.versioning = new RestApi.Versioning();
|
||||||
}
|
}
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference.equals(mVersioningKeep)) {
|
} else if (preference.equals(mVersioningKeep)) {
|
||||||
try {
|
try {
|
||||||
((RestApi.SimpleVersioning) mFolder.Versioning)
|
((RestApi.SimpleVersioning) mFolder.versioning)
|
||||||
.setParams(Integer.parseInt((String) o));
|
.setParams(Integer.parseInt((String) o));
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException e) {
|
} 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) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
if (preference.equals(mDirectory)) {
|
if (preference.equals(mDirectory)) {
|
||||||
Intent intent = new Intent(getActivity(), FolderPickerActivity.class);
|
Intent intent = new Intent(getActivity(), FolderPickerActivity.class);
|
||||||
if (mFolder.Path.length() > 0) {
|
if (mFolder.path.length() > 0) {
|
||||||
intent.putExtra(FolderPickerActivity.EXTRA_INITIAL_DIRECTORY, mFolder.Path);
|
intent.putExtra(FolderPickerActivity.EXTRA_INITIAL_DIRECTORY, mFolder.path);
|
||||||
}
|
}
|
||||||
startActivityForResult(intent, DIRECTORY_REQUEST_CODE);
|
startActivityForResult(intent, DIRECTORY_REQUEST_CODE);
|
||||||
} else if (preference.equals(mDevices) &&
|
} else if (preference.equals(mDevices) &&
|
||||||
|
@ -322,8 +322,8 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (resultCode == Activity.RESULT_OK && requestCode == DIRECTORY_REQUEST_CODE) {
|
if (resultCode == Activity.RESULT_OK && requestCode == DIRECTORY_REQUEST_CODE) {
|
||||||
mFolder.Path = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
|
mFolder.path = data.getStringExtra(FolderPickerActivity.EXTRA_RESULT_DIRECTORY);
|
||||||
mDirectory.setSummary(mFolder.Path);
|
mDirectory.setSummary(mFolder.path);
|
||||||
folderUpdated();
|
folderUpdated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class FoldersFragment extends ListFragment implements SyncthingService.On
|
||||||
Intent intent = new Intent(getActivity(), SettingsActivity.class)
|
Intent intent = new Intent(getActivity(), SettingsActivity.class)
|
||||||
.setAction(SettingsActivity.ACTION_REPO_SETTINGS_FRAGMENT)
|
.setAction(SettingsActivity.ACTION_REPO_SETTINGS_FRAGMENT)
|
||||||
.putExtra(SettingsActivity.EXTRA_IS_CREATE, false)
|
.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);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public class FoldersFragment extends ListFragment implements SyncthingService.On
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
|
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
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, "*/*");
|
intent.setDataAndType(uri, "*/*");
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -29,12 +29,11 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
|
|
||||||
private static final String SYNCTHING_OPTIONS_KEY = "syncthing_options";
|
private static final String SYNCTHING_OPTIONS_KEY = "syncthing_options";
|
||||||
private static final String SYNCTHING_GUI_KEY = "syncthing_gui";
|
private static final String SYNCTHING_GUI_KEY = "syncthing_gui";
|
||||||
private static final String DEVICE_NAME_KEY = "DeviceName";
|
private static final String DEVICE_NAME_KEY = "deviceName";
|
||||||
private static final String USAGE_REPORT_ACCEPTED = "URAccepted";
|
private static final String USAGE_REPORT_ACCEPTED = "urAccepted";
|
||||||
private static final String ADDRESS = "Address";
|
private static final String ADDRESS = "address";
|
||||||
private static final String GUI_USER = "gui_user";
|
private static final String GUI_USER = "gui_user";
|
||||||
private static final String GUI_PASSWORD = "gui_password";
|
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 EXPORT_CONFIG = "export_config";
|
||||||
private static final String IMPORT_CONFIG = "import_config";
|
private static final String IMPORT_CONFIG = "import_config";
|
||||||
private static final String STTRACE = "sttrace";
|
private static final String STTRACE = "sttrace";
|
||||||
|
@ -70,7 +69,7 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
String value;
|
String value;
|
||||||
switch (pref.getKey()) {
|
switch (pref.getKey()) {
|
||||||
case DEVICE_NAME_KEY:
|
case DEVICE_NAME_KEY:
|
||||||
value = api.getLocalDevice().Name;
|
value = api.getLocalDevice().name;
|
||||||
break;
|
break;
|
||||||
case USAGE_REPORT_ACCEPTED:
|
case USAGE_REPORT_ACCEPTED:
|
||||||
String v = api.getValue(RestApi.TYPE_OPTIONS, pref.getKey());
|
String v = api.getValue(RestApi.TYPE_OPTIONS, pref.getKey());
|
||||||
|
@ -84,9 +83,6 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
|
|
||||||
Preference address = mGuiScreen.findPreference(ADDRESS);
|
Preference address = mGuiScreen.findPreference(ADDRESS);
|
||||||
applyPreference(address, api.getValue(RestApi.TYPE_GUI, 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 = Integer.parseInt((String) o);
|
||||||
o = o.toString();
|
o = o.toString();
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.w(TAG, "Invalid number: " + o);
|
Log.w(TAG, "invalid number: " + o);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,21 +202,21 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
} else if (preference.getKey().equals(DEVICE_NAME_KEY)) {
|
} else if (preference.getKey().equals(DEVICE_NAME_KEY)) {
|
||||||
RestApi.Device old = mSyncthingService.getApi().getLocalDevice();
|
RestApi.Device old = mSyncthingService.getApi().getLocalDevice();
|
||||||
RestApi.Device updated = new RestApi.Device();
|
RestApi.Device updated = new RestApi.Device();
|
||||||
updated.Addresses = old.Addresses;
|
updated.addresses = old.addresses;
|
||||||
updated.Compression = old.Compression;
|
updated.compression = old.compression;
|
||||||
updated.DeviceID = old.DeviceID;
|
updated.deviceID = old.deviceID;
|
||||||
updated.Introducer = old.Introducer;
|
updated.introducer = old.introducer;
|
||||||
updated.Name = (String) o;
|
updated.name = (String) o;
|
||||||
mSyncthingService.getApi().editDevice(updated, getActivity(), null);
|
mSyncthingService.getApi().editDevice(updated, getActivity(), null);
|
||||||
} else if (preference.getKey().equals(USAGE_REPORT_ACCEPTED)) {
|
} else if (preference.getKey().equals(USAGE_REPORT_ACCEPTED)) {
|
||||||
mSyncthingService.getApi().setValue(RestApi.TYPE_OPTIONS, preference.getKey(),
|
mSyncthingService.getApi().setValue(RestApi.TYPE_OPTIONS, preference.getKey(),
|
||||||
((Boolean) o) ? 1 : 0, false, getActivity());
|
((Boolean) o) ? 1 : 0, false, getActivity());
|
||||||
} else if (mOptionsScreen.findPreference(preference.getKey()) != null) {
|
} else if (mOptionsScreen.findPreference(preference.getKey()) != null) {
|
||||||
boolean isArray = preference.getKey().equals("ListenAddress") ||
|
boolean isArray = preference.getKey().equals("listenAddress") ||
|
||||||
preference.getKey().equals("GlobalAnnServers");
|
preference.getKey().equals("globalAnnServers");
|
||||||
mSyncthingService.getApi().setValue(RestApi.TYPE_OPTIONS, preference.getKey(), o,
|
mSyncthingService.getApi().setValue(RestApi.TYPE_OPTIONS, preference.getKey(), o,
|
||||||
isArray, getActivity());
|
isArray, getActivity());
|
||||||
} else if (preference.getKey().equals(ADDRESS) || preference.getKey().equals(USER_TLS)) {
|
} else if (preference.getKey().equals(ADDRESS)) {
|
||||||
mSyncthingService.getApi().setValue(
|
mSyncthingService.getApi().setValue(
|
||||||
RestApi.TYPE_GUI, preference.getKey(), o, false, getActivity());
|
RestApi.TYPE_GUI, preference.getKey(), o, false, getActivity());
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,17 +29,17 @@ public class GetTask extends AsyncTask<String, Void, String> {
|
||||||
|
|
||||||
private static final String TAG = "GetTask";
|
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;
|
private String mHttpsCertPath;
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,9 @@ public class PostTask extends AsyncTask<String, Void, Boolean> {
|
||||||
|
|
||||||
private static final String TAG = "PostTask";
|
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;
|
private String mHttpsCertPath;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -32,9 +31,6 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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;
|
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.
|
* 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.
|
* 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.
|
* 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
|
* Key of the map element containing connection info for the local device, in the return
|
||||||
* value of {@link #getConnections}
|
* 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 static class Device implements Serializable {
|
||||||
public String Addresses;
|
public String addresses;
|
||||||
public String Name;
|
public String name;
|
||||||
public String DeviceID;
|
public String deviceID;
|
||||||
public String Compression;
|
public String compression;
|
||||||
public boolean Introducer;
|
public boolean introducer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SystemInfo {
|
public static class SystemInfo {
|
||||||
|
@ -85,13 +81,13 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Folder implements Serializable {
|
public static class Folder implements Serializable {
|
||||||
public String Path;
|
public String path;
|
||||||
public String ID;
|
public String id;
|
||||||
public String Invalid;
|
public String invalid;
|
||||||
public List<String> DeviceIds;
|
public List<String> deviceIds;
|
||||||
public boolean ReadOnly;
|
public boolean readOnly;
|
||||||
public int RescanIntervalS;
|
public int rescanIntervalS;
|
||||||
public Versioning Versioning;
|
public Versioning versioning;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Versioning implements Serializable {
|
public static class Versioning implements Serializable {
|
||||||
|
@ -118,14 +114,14 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Connection {
|
public static class Connection {
|
||||||
public String At;
|
public String at;
|
||||||
public long InBytesTotal;
|
public long inBytesTotal;
|
||||||
public long OutBytesTotal;
|
public long outBytesTotal;
|
||||||
public long InBits;
|
public long inBits;
|
||||||
public long OutBits;
|
public long outBits;
|
||||||
public String Address;
|
public String address;
|
||||||
public String ClientVersion;
|
public String clientVersion;
|
||||||
public int Completion;
|
public int completion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Model {
|
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},
|
* 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}.
|
* 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;
|
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
|
@Override
|
||||||
public void onWebGuiAvailable() {
|
public void onWebGuiAvailable() {
|
||||||
|
@ -407,17 +403,17 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONArray devices = mConfig.getJSONArray("Devices");
|
JSONArray devices = mConfig.getJSONArray("devices");
|
||||||
List<Device> ret = new ArrayList<>(devices.length());
|
List<Device> ret = new ArrayList<>(devices.length());
|
||||||
for (int i = 0; i < devices.length(); i++) {
|
for (int i = 0; i < devices.length(); i++) {
|
||||||
JSONObject json = devices.getJSONObject(i);
|
JSONObject json = devices.getJSONObject(i);
|
||||||
Device n = new Device();
|
Device n = new Device();
|
||||||
n.Addresses = json.optJSONArray("Addresses").join(" ").replace("\"", "");
|
n.addresses = json.optJSONArray("addresses").join(" ").replace("\"", "");
|
||||||
n.Name = json.getString("Name");
|
n.name = json.getString("name");
|
||||||
n.DeviceID = json.getString("DeviceID");
|
n.deviceID = json.getString("deviceID");
|
||||||
n.Compression = json.getString("Compression");
|
n.compression = json.getString("compression");
|
||||||
n.Introducer = json.getBoolean("Introducer");
|
n.introducer = json.getBoolean("introducer");
|
||||||
if (includeLocal || !mLocalDeviceId.equals(n.DeviceID)) {
|
if (includeLocal || !mLocalDeviceId.equals(n.deviceID)) {
|
||||||
ret.add(n);
|
ret.add(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -482,31 +478,31 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
|
|
||||||
List<Folder> ret;
|
List<Folder> ret;
|
||||||
try {
|
try {
|
||||||
JSONArray folders = mConfig.getJSONArray("Folders");
|
JSONArray folders = mConfig.getJSONArray("folders");
|
||||||
ret = new ArrayList<>(folders.length());
|
ret = new ArrayList<>(folders.length());
|
||||||
for (int i = 0; i < folders.length(); i++) {
|
for (int i = 0; i < folders.length(); i++) {
|
||||||
JSONObject json = folders.getJSONObject(i);
|
JSONObject json = folders.getJSONObject(i);
|
||||||
Folder r = new Folder();
|
Folder r = new Folder();
|
||||||
r.Path = json.getString("Path");
|
r.path = json.getString("path");
|
||||||
r.ID = json.getString("ID");
|
r.id = json.getString("id");
|
||||||
r.Invalid = json.getString("Invalid");
|
r.invalid = json.getString("invalid");
|
||||||
r.DeviceIds = new ArrayList<>();
|
r.deviceIds = new ArrayList<>();
|
||||||
JSONArray devices = json.getJSONArray("Devices");
|
JSONArray devices = json.getJSONArray("devices");
|
||||||
for (int j = 0; j < devices.length(); j++) {
|
for (int j = 0; j < devices.length(); j++) {
|
||||||
JSONObject n = devices.getJSONObject(j);
|
JSONObject n = devices.getJSONObject(j);
|
||||||
r.DeviceIds.add(n.getString("DeviceID"));
|
r.deviceIds.add(n.getString("deviceID"));
|
||||||
}
|
}
|
||||||
|
|
||||||
r.ReadOnly = json.getBoolean("ReadOnly");
|
r.readOnly = json.getBoolean("readOnly");
|
||||||
r.RescanIntervalS = json.getInt("RescanIntervalS");
|
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();
|
||||||
JSONObject params = versioning.getJSONObject("Params");
|
JSONObject params = versioning.getJSONObject("params");
|
||||||
sv.setParams(params.getInt("keep"));
|
sv.setParams(params.getInt("keep"));
|
||||||
r.Versioning = sv;
|
r.versioning = sv;
|
||||||
} else {
|
} else {
|
||||||
r.Versioning = new Versioning();
|
r.versioning = new Versioning();
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.add(r);
|
ret.add(r);
|
||||||
|
@ -546,7 +542,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
public interface OnReceiveConnectionsListener {
|
public interface OnReceiveConnectionsListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param connections Map from Device ID to {@link Connection}.
|
* @param connections Map from Device id to {@link Connection}.
|
||||||
* <p/>
|
* <p/>
|
||||||
* NOTE: The parameter connections is cached internally. Do not modify it or
|
* NOTE: The parameter connections is cached internally. Do not modify it or
|
||||||
* any of its contents.
|
* 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.
|
* Returns connection info for the local device and all connected devices.
|
||||||
* <p/>
|
* <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) {
|
public void getConnections(final OnReceiveConnectionsListener listener) {
|
||||||
new GetTask(mHttpsCertPath) {
|
new GetTask(mHttpsCertPath) {
|
||||||
|
@ -575,27 +571,35 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(s);
|
JSONObject json = new JSONObject(s);
|
||||||
String[] names = json.names().join(" ").replace("\"", "").split(" ");
|
Map<String, JSONObject> jsonConnections = new HashMap<>();
|
||||||
HashMap<String, Connection> connections = new HashMap<String, Connection>();
|
jsonConnections.put(TOTAL_STATS, json.getJSONObject(TOTAL_STATS));
|
||||||
for (String deviceId : names) {
|
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();
|
Connection c = new Connection();
|
||||||
JSONObject conn = json.getJSONObject(deviceId);
|
JSONObject conn = jsonConnections.get(deviceId);
|
||||||
c.Address = deviceId;
|
c.address = deviceId;
|
||||||
c.At = conn.getString("At");
|
c.at = conn.getString("at");
|
||||||
c.InBytesTotal = conn.getLong("InBytesTotal");
|
c.inBytesTotal = conn.getLong("inBytesTotal");
|
||||||
c.OutBytesTotal = conn.getLong("OutBytesTotal");
|
c.outBytesTotal = conn.getLong("outBytesTotal");
|
||||||
c.Address = conn.getString("Address");
|
c.address = conn.getString("address");
|
||||||
c.ClientVersion = conn.getString("ClientVersion");
|
c.clientVersion = conn.getString("clientVersion");
|
||||||
c.Completion = getDeviceCompletion(deviceId);
|
c.completion = getDeviceCompletion(deviceId);
|
||||||
|
|
||||||
Connection prev = (mPreviousConnections.containsKey(deviceId))
|
Connection prev = (mPreviousConnections.containsKey(deviceId))
|
||||||
? mPreviousConnections.get(deviceId)
|
? mPreviousConnections.get(deviceId)
|
||||||
: new Connection();
|
: new Connection();
|
||||||
mPreviousConnectionTime = now;
|
mPreviousConnectionTime = now;
|
||||||
c.InBits = Math.max(0, 8 *
|
c.inBits = Math.max(0, 8 *
|
||||||
(conn.getLong("InBytesTotal") - prev.InBytesTotal) / timeElapsed);
|
(conn.getLong("inBytesTotal") - prev.inBytesTotal) / timeElapsed);
|
||||||
c.OutBits = Math.max(0, 8 *
|
c.outBits = Math.max(0, 8 *
|
||||||
(conn.getLong("OutBytesTotal") - prev.OutBytesTotal) / timeElapsed);
|
(conn.getLong("outBytesTotal") - prev.outBytesTotal) / timeElapsed);
|
||||||
|
|
||||||
connections.put(deviceId, c);
|
connections.put(deviceId, c);
|
||||||
|
|
||||||
|
@ -619,7 +623,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
boolean isShared = false;
|
boolean isShared = false;
|
||||||
outerloop:
|
outerloop:
|
||||||
for (Folder r : getFolders()) {
|
for (Folder r : getFolders()) {
|
||||||
for (String n : r.DeviceIds) {
|
for (String n : r.deviceIds) {
|
||||||
if (n.equals(deviceId)) {
|
if (n.equals(deviceId)) {
|
||||||
isShared = true;
|
isShared = true;
|
||||||
break outerloop;
|
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) {
|
public void getModel(final String folderId, final OnReceiveModelListener listener) {
|
||||||
new GetTask(mHttpsCertPath) {
|
new GetTask(mHttpsCertPath) {
|
||||||
|
@ -711,7 +715,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
*/
|
*/
|
||||||
public void editDevice(final Device device, final Activity activity,
|
public void editDevice(final Device device, final Activity activity,
|
||||||
final OnDeviceIdNormalizedListener listener) {
|
final OnDeviceIdNormalizedListener listener) {
|
||||||
normalizeDeviceId(device.DeviceID,
|
normalizeDeviceId(device.deviceID,
|
||||||
new RestApi.OnDeviceIdNormalizedListener() {
|
new RestApi.OnDeviceIdNormalizedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDeviceIdNormalized(String normalizedId, String error) {
|
public void onDeviceIdNormalized(String normalizedId, String error) {
|
||||||
|
@ -719,17 +723,17 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
if (normalizedId == null)
|
if (normalizedId == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
device.DeviceID = normalizedId;
|
device.deviceID = normalizedId;
|
||||||
// If the device already exists, just update it.
|
// If the device already exists, just update it.
|
||||||
boolean create = true;
|
boolean create = true;
|
||||||
for (RestApi.Device n : getDevices(true)) {
|
for (RestApi.Device n : getDevices(true)) {
|
||||||
if (n.DeviceID.equals(device.DeviceID)) {
|
if (n.deviceID.equals(device.deviceID)) {
|
||||||
create = false;
|
create = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONArray devices = mConfig.getJSONArray("Devices");
|
JSONArray devices = mConfig.getJSONArray("devices");
|
||||||
JSONObject n = null;
|
JSONObject n = null;
|
||||||
if (create) {
|
if (create) {
|
||||||
n = new JSONObject();
|
n = new JSONObject();
|
||||||
|
@ -737,17 +741,17 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < devices.length(); i++) {
|
for (int i = 0; i < devices.length(); i++) {
|
||||||
JSONObject json = devices.getJSONObject(i);
|
JSONObject json = devices.getJSONObject(i);
|
||||||
if (device.DeviceID.equals(json.getString("DeviceID"))) {
|
if (device.deviceID.equals(json.getString("deviceID"))) {
|
||||||
n = devices.getJSONObject(i);
|
n = devices.getJSONObject(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n.put("DeviceID", device.DeviceID);
|
n.put("deviceID", device.deviceID);
|
||||||
n.put("Name", device.Name);
|
n.put("name", device.name);
|
||||||
n.put("Addresses", listToJson(device.Addresses.split(" ")));
|
n.put("addresses", listToJson(device.addresses.split(" ")));
|
||||||
n.put("Compression", device.Compression);
|
n.put("compression", device.compression);
|
||||||
n.put("Introducer", device.Introducer);
|
n.put("introducer", device.introducer);
|
||||||
requireRestart(activity);
|
requireRestart(activity);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.w(TAG, "Failed to read devices", 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) {
|
public boolean deleteDevice(Device device, Activity activity) {
|
||||||
try {
|
try {
|
||||||
JSONArray devices = mConfig.getJSONArray("Devices");
|
JSONArray devices = mConfig.getJSONArray("devices");
|
||||||
|
|
||||||
for (int i = 0; i < devices.length(); i++) {
|
for (int i = 0; i < devices.length(); i++) {
|
||||||
JSONObject json = devices.getJSONObject(i);
|
JSONObject json = devices.getJSONObject(i);
|
||||||
if (device.DeviceID.equals(json.getString("DeviceID"))) {
|
if (device.deviceID.equals(json.getString("deviceID"))) {
|
||||||
mConfig.remove("Devices");
|
mConfig.remove("devices");
|
||||||
mConfig.put("Devices", delete(devices, devices.getJSONObject(i)));
|
mConfig.put("devices", delete(devices, devices.getJSONObject(i)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -785,7 +789,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
*/
|
*/
|
||||||
public boolean editFolder(Folder folder, boolean create, Activity activity) {
|
public boolean editFolder(Folder folder, boolean create, Activity activity) {
|
||||||
try {
|
try {
|
||||||
JSONArray folders = mConfig.getJSONArray("Folders");
|
JSONArray folders = mConfig.getJSONArray("folders");
|
||||||
JSONObject r = null;
|
JSONObject r = null;
|
||||||
if (create) {
|
if (create) {
|
||||||
r = new JSONObject();
|
r = new JSONObject();
|
||||||
|
@ -793,35 +797,35 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < folders.length(); i++) {
|
for (int i = 0; i < folders.length(); i++) {
|
||||||
JSONObject json = folders.getJSONObject(i);
|
JSONObject json = folders.getJSONObject(i);
|
||||||
if (folder.ID.equals(json.getString("ID"))) {
|
if (folder.id.equals(json.getString("id"))) {
|
||||||
r = folders.getJSONObject(i);
|
r = folders.getJSONObject(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.put("Path", folder.Path);
|
r.put("path", folder.path);
|
||||||
r.put("ID", folder.ID);
|
r.put("id", folder.id);
|
||||||
r.put("IgnorePerms", true);
|
r.put("ignorePerms", true);
|
||||||
r.put("ReadOnly", folder.ReadOnly);
|
r.put("readOnly", folder.readOnly);
|
||||||
JSONArray devices = new JSONArray();
|
JSONArray devices = new JSONArray();
|
||||||
for (String n : folder.DeviceIds) {
|
for (String n : folder.deviceIds) {
|
||||||
JSONObject element = new JSONObject();
|
JSONObject element = new JSONObject();
|
||||||
element.put("DeviceID", n);
|
element.put("deviceID", n);
|
||||||
devices.put(element);
|
devices.put(element);
|
||||||
}
|
}
|
||||||
r.put("Devices", devices);
|
r.put("devices", devices);
|
||||||
JSONObject versioning = new JSONObject();
|
JSONObject versioning = new JSONObject();
|
||||||
versioning.put("Type", folder.Versioning.getType());
|
versioning.put("type", folder.versioning.getType());
|
||||||
JSONObject params = new JSONObject();
|
JSONObject params = new JSONObject();
|
||||||
versioning.put("Params", params);
|
versioning.put("params", params);
|
||||||
for (String key : folder.Versioning.getParams().keySet()) {
|
for (String key : folder.versioning.getParams().keySet()) {
|
||||||
params.put(key, folder.Versioning.getParams().get(key));
|
params.put(key, folder.versioning.getParams().get(key));
|
||||||
}
|
}
|
||||||
r.put("RescanIntervalS", folder.RescanIntervalS);
|
r.put("rescanIntervalS", folder.rescanIntervalS);
|
||||||
r.put("Versioning", versioning);
|
r.put("versioning", versioning);
|
||||||
requireRestart(activity);
|
requireRestart(activity);
|
||||||
} catch (JSONException e) {
|
} 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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -832,13 +836,13 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
*/
|
*/
|
||||||
public boolean deleteFolder(Folder folder, Activity activity) {
|
public boolean deleteFolder(Folder folder, Activity activity) {
|
||||||
try {
|
try {
|
||||||
JSONArray folders = mConfig.getJSONArray("Folders");
|
JSONArray folders = mConfig.getJSONArray("folders");
|
||||||
|
|
||||||
for (int i = 0; i < folders.length(); i++) {
|
for (int i = 0; i < folders.length(); i++) {
|
||||||
JSONObject json = folders.getJSONObject(i);
|
JSONObject json = folders.getJSONObject(i);
|
||||||
if (folder.ID.equals(json.getString("ID"))) {
|
if (folder.id.equals(json.getString("id"))) {
|
||||||
mConfig.remove("Folders");
|
mConfig.remove("folders");
|
||||||
mConfig.put("Folders", delete(folders, folders.getJSONObject(i)));
|
mConfig.put("folders", delete(folders, folders.getJSONObject(i)));
|
||||||
break;
|
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) {
|
public static void shareDeviceId(Context context, String id) {
|
||||||
Intent shareIntent = new Intent();
|
Intent shareIntent = new Intent();
|
||||||
|
@ -946,7 +950,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
*/
|
*/
|
||||||
public Device getLocalDevice() {
|
public Device getLocalDevice() {
|
||||||
for (Device d : getDevices(true)) {
|
for (Device d : getDevices(true)) {
|
||||||
if (d.DeviceID.equals(mLocalDeviceId)) {
|
if (d.deviceID.equals(mLocalDeviceId)) {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,17 +56,17 @@ public class SyncthingService extends Service {
|
||||||
public static final int GUI_UPDATE_INTERVAL = 1000;
|
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";
|
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";
|
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";
|
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");
|
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";
|
public static final String BINARY_NAME = "lib/libsyncthing.so";
|
||||||
|
|
||||||
|
|
|
@ -42,22 +42,22 @@ public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
|
||||||
TextView download = (TextView) convertView.findViewById(R.id.download);
|
TextView download = (TextView) convertView.findViewById(R.id.download);
|
||||||
TextView upload = (TextView) convertView.findViewById(R.id.upload);
|
TextView upload = (TextView) convertView.findViewById(R.id.upload);
|
||||||
|
|
||||||
String deviceId = getItem(position).DeviceID;
|
String deviceId = getItem(position).deviceID;
|
||||||
RestApi.Connection conn = mConnections.get(deviceId);
|
RestApi.Connection conn = mConnections.get(deviceId);
|
||||||
|
|
||||||
name.setText(getItem(position).Name);
|
name.setText(getItem(position).name);
|
||||||
Resources r = getContext().getResources();
|
Resources r = getContext().getResources();
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
if (conn.Completion == 100) {
|
if (conn.completion == 100) {
|
||||||
status.setText(r.getString(R.string.device_up_to_date));
|
status.setText(r.getString(R.string.device_up_to_date));
|
||||||
status.setTextColor(r.getColor(R.color.text_green));
|
status.setTextColor(r.getColor(R.color.text_green));
|
||||||
}
|
}
|
||||||
else {
|
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));
|
status.setTextColor(r.getColor(R.color.text_blue));
|
||||||
}
|
}
|
||||||
download.setText(RestApi.readableTransferRate(getContext(), conn.InBits));
|
download.setText(RestApi.readableTransferRate(getContext(), conn.inBits));
|
||||||
upload.setText(RestApi.readableTransferRate(getContext(), conn.OutBits));
|
upload.setText(RestApi.readableTransferRate(getContext(), conn.outBits));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
download.setText("0 " + r.getStringArray(R.array.transfer_rate_units)[0]);
|
download.setText("0 " + r.getStringArray(R.array.transfer_rate_units)[0]);
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class FolderObserver extends FileObserver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
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 listener The listener where changes should be sent to.
|
||||||
* @param folder The folder where this folder belongs 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) {
|
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 |
|
ATTRIB | CLOSE_WRITE | CREATE | DELETE | DELETE_SELF | MODIFY | MOVED_FROM |
|
||||||
MOVED_TO | MOVE_SELF);
|
MOVED_TO | MOVE_SELF);
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
mFolder = folder;
|
mFolder = folder;
|
||||||
mPath = path;
|
mPath = path;
|
||||||
Log.v(TAG, "observer created for " + path + " in " + folder.ID);
|
Log.v(TAG, "observer created for " + path + " in " + folder.id);
|
||||||
startWatching();
|
startWatching();
|
||||||
|
|
||||||
File currentFolder = new File(folder.Path, path);
|
File currentFolder = new File(folder.path, path);
|
||||||
if (!currentFolder.exists()) {
|
if (!currentFolder.exists()) {
|
||||||
throw new FolderNotExistingException(currentFolder.getAbsolutePath());
|
throw new FolderNotExistingException(currentFolder.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ public class FolderObserver extends FileObserver {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mListener.onFolderFileChange(mFolder.ID, fullPath.getPath());
|
mListener.onFolderFileChange(mFolder.id, fullPath.getPath());
|
||||||
break;
|
break;
|
||||||
case MOVED_TO:
|
case MOVED_TO:
|
||||||
// fall through
|
// fall through
|
||||||
|
@ -117,7 +117,7 @@ public class FolderObserver extends FileObserver {
|
||||||
}
|
}
|
||||||
// fall through
|
// fall through
|
||||||
default:
|
default:
|
||||||
mListener.onFolderFileChange(mFolder.ID, fullPath.getPath());
|
mListener.onFolderFileChange(mFolder.id, fullPath.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,10 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
|
||||||
TextView invalid = (TextView) convertView.findViewById(R.id.invalid);
|
TextView invalid = (TextView) convertView.findViewById(R.id.invalid);
|
||||||
|
|
||||||
RestApi.Folder folder = getItem(position);
|
RestApi.Folder folder = getItem(position);
|
||||||
RestApi.Model model = mModels.get(folder.ID);
|
RestApi.Model model = mModels.get(folder.id);
|
||||||
id.setText(folder.ID);
|
id.setText(folder.id);
|
||||||
state.setTextColor(getContext().getResources().getColor(R.color.text_green));
|
state.setTextColor(getContext().getResources().getColor(R.color.text_green));
|
||||||
directory.setText((folder.Path));
|
directory.setText((folder.path));
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
int percentage = (model.globalBytes != 0)
|
int percentage = (model.globalBytes != 0)
|
||||||
? (int) Math.floor(100 * model.inSyncBytes / model.globalBytes)
|
? (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));
|
.getString(R.string.files, model.inSyncFiles, model.globalFiles));
|
||||||
size.setText(RestApi.readableFileSize(getContext(), model.inSyncBytes) + " / " +
|
size.setText(RestApi.readableFileSize(getContext(), model.inSyncBytes) + " / " +
|
||||||
RestApi.readableFileSize(getContext(), model.globalBytes));
|
RestApi.readableFileSize(getContext(), model.globalBytes));
|
||||||
if (folder.Invalid.equals("")) {
|
if (folder.invalid.equals("")) {
|
||||||
invalid.setText(model.invalid);
|
invalid.setText(model.invalid);
|
||||||
invalid.setVisibility((model.invalid.equals("")) ? View.GONE : View.VISIBLE);
|
invalid.setVisibility((model.invalid.equals("")) ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
invalid.setText(folder.Invalid);
|
invalid.setText(folder.invalid);
|
||||||
invalid.setVisibility((folder.Invalid.equals("")) ? View.GONE : View.VISIBLE);
|
invalid.setVisibility((folder.invalid.equals("")) ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
|
@ -85,7 +85,7 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
|
||||||
for (int i = 0; i < getCount(); i++) {
|
for (int i = 0; i < getCount(); i++) {
|
||||||
if (i >= listView.getFirstVisiblePosition() &&
|
if (i >= listView.getFirstVisiblePosition() &&
|
||||||
i <= listView.getLastVisiblePosition()) {
|
i <= listView.getLastVisiblePosition()) {
|
||||||
api.getModel(getItem(i).ID, this);
|
api.getModel(getItem(i).id, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,49 +35,49 @@
|
||||||
android:title="@string/syncthing_options">
|
android:title="@string/syncthing_options">
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="DeviceName"
|
android:key="deviceName"
|
||||||
android:title="@string/device_name"
|
android:title="@string/device_name"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="ListenAddress"
|
android:key="listenAddress"
|
||||||
android:title="@string/listen_address"
|
android:title="@string/listen_address"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="MaxRecvKbps"
|
android:key="maxRecvKbps"
|
||||||
android:title="@string/max_recv_kbps"
|
android:title="@string/max_recv_kbps"
|
||||||
android:numeric="integer"
|
android:numeric="integer"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="MaxSendKbps"
|
android:key="maxSendKbps"
|
||||||
android:title="@string/max_send_kbps"
|
android:title="@string/max_send_kbps"
|
||||||
android:numeric="integer"
|
android:numeric="integer"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="GlobalAnnEnabled"
|
android:key="globalAnnounceEnabled"
|
||||||
android:title="@string/global_announce_enabled"
|
android:title="@string/global_announce_enabled"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="LocalAnnEnabled"
|
android:key="localAnnounceEnabled"
|
||||||
android:title="@string/local_announce_enabled"
|
android:title="@string/local_announce_enabled"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="UPnPEnabled"
|
android:key="upnpEnabled"
|
||||||
android:title="@string/upnp_enabled"
|
android:title="@string/upnp_enabled"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="GlobalAnnServers"
|
android:key="globalAnnounceServers"
|
||||||
android:title="@string/global_announce_server"
|
android:title="@string/global_announce_server"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="URAccepted"
|
android:key="urAccepted"
|
||||||
android:title="@string/usage_reporting"
|
android:title="@string/usage_reporting"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@
|
||||||
android:title="@string/syncthing_gui">
|
android:title="@string/syncthing_gui">
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="Address"
|
android:key="address"
|
||||||
android:title="@string/gui_address"
|
android:title="@string/gui_address"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue