mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Fixed adding/editing folders and devices
This commit is contained in:
parent
4b0ec8b092
commit
f60e591a90
5 changed files with 35 additions and 16 deletions
|
@ -50,6 +50,9 @@ public class DeviceListFragment extends ListFragment implements SyncthingService
|
||||||
mTimer.schedule(new TimerTask() {
|
mTimer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (getActivity() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
getActivity().runOnUiThread(DeviceListFragment.this::updateList);
|
getActivity().runOnUiThread(DeviceListFragment.this::updateList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +75,7 @@ public class DeviceListFragment extends ListFragment implements SyncthingService
|
||||||
*/
|
*/
|
||||||
private void updateList() {
|
private void updateList() {
|
||||||
SyncthingActivity activity = (SyncthingActivity) getActivity();
|
SyncthingActivity activity = (SyncthingActivity) getActivity();
|
||||||
if (activity == null || activity.getApi() == null || getView() == null ||
|
if (activity.getApi() == null || getView() == null || activity.isFinishing())
|
||||||
activity.isFinishing())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mAdapter == null) {
|
if (mAdapter == null) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
|
@ -272,7 +273,7 @@ public class FolderFragment extends Fragment
|
||||||
mLabelView.setText(mFolder.label);
|
mLabelView.setText(mFolder.label);
|
||||||
mIdView.setText(mFolder.id);
|
mIdView.setText(mFolder.id);
|
||||||
mPathView.setText(mFolder.path);
|
mPathView.setText(mFolder.path);
|
||||||
mFolderMasterView.setChecked(mFolder.type.equals("readonly"));
|
mFolderMasterView.setChecked(Objects.equal(mFolder.type, "readonly"));
|
||||||
List<Device> devicesList = mSyncthingService.getApi().getDevices(false);
|
List<Device> devicesList = mSyncthingService.getApi().getDevices(false);
|
||||||
|
|
||||||
mDevicesContainer.removeAllViews();
|
mDevicesContainer.removeAllViews();
|
||||||
|
@ -284,7 +285,7 @@ public class FolderFragment extends Fragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean versioningEnabled = mFolder.versioning.type.equals("simple");
|
boolean versioningEnabled = Objects.equal(mFolder.versioning.type, "simple");
|
||||||
int versions = 0;
|
int versions = 0;
|
||||||
if (versioningEnabled) {
|
if (versioningEnabled) {
|
||||||
versions = Integer.valueOf(mFolder.versioning.params.get("keep"));
|
versions = Integer.valueOf(mFolder.versioning.params.get("keep"));
|
||||||
|
@ -360,9 +361,7 @@ public class FolderFragment extends Fragment
|
||||||
mFolder = new Folder();
|
mFolder = new Folder();
|
||||||
mFolder.id = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_ID);
|
mFolder.id = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_ID);
|
||||||
mFolder.label = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_LABEL);
|
mFolder.label = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_LABEL);
|
||||||
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.setDevices(new ArrayList<>());
|
|
||||||
mFolder.versioning = new Folder.Versioning();
|
mFolder.versioning = new Folder.Versioning();
|
||||||
String deviceId = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
String deviceId = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
||||||
if (deviceId != null) {
|
if (deviceId != null) {
|
||||||
|
|
|
@ -58,6 +58,9 @@ public class FolderListFragment extends ListFragment implements SyncthingService
|
||||||
mTimer.schedule(new TimerTask() {
|
mTimer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (getActivity() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
getActivity().runOnUiThread(FolderListFragment.this::updateList);
|
getActivity().runOnUiThread(FolderListFragment.this::updateList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +84,7 @@ public class FolderListFragment extends ListFragment implements SyncthingService
|
||||||
*/
|
*/
|
||||||
private void updateList() {
|
private void updateList() {
|
||||||
SyncthingActivity activity = (SyncthingActivity) getActivity();
|
SyncthingActivity activity = (SyncthingActivity) getActivity();
|
||||||
if (activity == null || activity.getApi() == null || getView() == null ||
|
if (activity.getApi() == null || getView() == null || activity.isFinishing())
|
||||||
activity.isFinishing())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mAdapter == null) {
|
if (mAdapter == null) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class Folder {
|
||||||
public String label;
|
public String label;
|
||||||
public String path;
|
public String path;
|
||||||
public String type;
|
public String type;
|
||||||
private transient List<Map<String, String>> devices;
|
private transient List<Map<String, String>> devices = new ArrayList<>();
|
||||||
public int rescanIntervalS;
|
public int rescanIntervalS;
|
||||||
public boolean ignorePerms;
|
public boolean ignorePerms;
|
||||||
public boolean autoNormalize;
|
public boolean autoNormalize;
|
||||||
|
@ -47,9 +47,9 @@ public class Folder {
|
||||||
return devicesList;
|
return devicesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDevices(List<String> newDvices) {
|
public void setDevices(List<String> newDevices) {
|
||||||
devices.clear();
|
devices.clear();
|
||||||
for (String d : newDvices) {
|
for (String d : newDevices) {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("deviceID", d);
|
map.put("deviceID", d);
|
||||||
devices.add(map);
|
devices.add(map);
|
||||||
|
|
|
@ -174,14 +174,18 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
*/
|
*/
|
||||||
public void requireRestart(Activity activity) {
|
public void requireRestart(Activity activity) {
|
||||||
if (mRestartPostponed) {
|
if (mRestartPostponed) {
|
||||||
new PostTask(mUrl, PostTask.URI_CONFIG, mHttpsCertPath, mApiKey, null)
|
sendConfig();
|
||||||
.execute(mConfig.toString());
|
|
||||||
} else {
|
} else {
|
||||||
activity.startActivity(new Intent(mContext, RestartActivity.class));
|
activity.startActivity(new Intent(mContext, RestartActivity.class));
|
||||||
}
|
}
|
||||||
mOnConfigChangedListener.onConfigChanged();
|
mOnConfigChangedListener.onConfigChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendConfig() {
|
||||||
|
new PostTask(mUrl, PostTask.URI_CONFIG, mHttpsCertPath, mApiKey, null)
|
||||||
|
.execute(new Gson().toJson(mConfig));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immediately restarts Syncthing, without confirmation.
|
* Immediately restarts Syncthing, without confirmation.
|
||||||
*/
|
*/
|
||||||
|
@ -190,7 +194,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
Intent intent = new Intent(mContext, SyncthingService.class)
|
Intent intent = new Intent(mContext, SyncthingService.class)
|
||||||
.setAction(SyncthingService.ACTION_RESTART);
|
.setAction(SyncthingService.ACTION_RESTART);
|
||||||
mContext.startService(intent);
|
mContext.startService(intent);
|
||||||
}).execute(mConfig.toString());
|
}).execute(new Gson().toJson(mConfig));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,6 +234,11 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDevice(String deviceId) {
|
public void removeDevice(String deviceId) {
|
||||||
|
removeDeviceInternal(deviceId);
|
||||||
|
sendConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeDeviceInternal(String deviceId) {
|
||||||
Iterator<Device> it = mConfig.devices.iterator();
|
Iterator<Device> it = mConfig.devices.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Device d = it.next();
|
Device d = it.next();
|
||||||
|
@ -240,6 +249,11 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeFolder(String id) {
|
public void removeFolder(String id) {
|
||||||
|
removeFolderInternal(id);
|
||||||
|
sendConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeFolderInternal(String id) {
|
||||||
Iterator<Folder> it = mConfig.folders.iterator();
|
Iterator<Folder> it = mConfig.folders.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Folder f = it.next();
|
Folder f = it.next();
|
||||||
|
@ -253,6 +267,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
normalizeDeviceId(device.deviceID, ((normalizedId, error) -> {
|
normalizeDeviceId(device.deviceID, ((normalizedId, error) -> {
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
mConfig.devices.add(device);
|
mConfig.devices.add(device);
|
||||||
|
sendConfig();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
listener.onDeviceIdNormalized(normalizedId, error);
|
listener.onDeviceIdNormalized(normalizedId, error);
|
||||||
|
@ -262,15 +277,16 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
|
|
||||||
public void addFolder(Folder folder) {
|
public void addFolder(Folder folder) {
|
||||||
mConfig.folders.add(folder);
|
mConfig.folders.add(folder);
|
||||||
|
sendConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editDevice(Device newDevice) {
|
public void editDevice(Device newDevice) {
|
||||||
removeDevice(newDevice.deviceID);
|
removeDeviceInternal(newDevice.deviceID);
|
||||||
addDevice(newDevice, null);
|
addDevice(newDevice, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editFolder(Folder newFolder) {
|
public void editFolder(Folder newFolder) {
|
||||||
removeFolder(newFolder.id);
|
removeFolderInternal(newFolder.id);
|
||||||
addFolder(newFolder);
|
addFolder(newFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue