1
0
Fork 0
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:
Felix Ableitner 2016-10-30 16:34:12 +09:00
parent 4b0ec8b092
commit f60e591a90
5 changed files with 35 additions and 16 deletions

View file

@ -50,6 +50,9 @@ public class DeviceListFragment extends ListFragment implements SyncthingService
mTimer.schedule(new TimerTask() {
@Override
public void run() {
if (getActivity() == null)
return;
getActivity().runOnUiThread(DeviceListFragment.this::updateList);
}
@ -72,8 +75,7 @@ public class DeviceListFragment extends ListFragment implements SyncthingService
*/
private void updateList() {
SyncthingActivity activity = (SyncthingActivity) getActivity();
if (activity == null || activity.getApi() == null || getView() == null ||
activity.isFinishing())
if (activity.getApi() == null || getView() == null || activity.isFinishing())
return;
if (mAdapter == null) {

View file

@ -24,6 +24,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.nutomic.syncthingandroid.R;
@ -272,7 +273,7 @@ public class FolderFragment extends Fragment
mLabelView.setText(mFolder.label);
mIdView.setText(mFolder.id);
mPathView.setText(mFolder.path);
mFolderMasterView.setChecked(mFolder.type.equals("readonly"));
mFolderMasterView.setChecked(Objects.equal(mFolder.type, "readonly"));
List<Device> devicesList = mSyncthingService.getApi().getDevices(false);
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;
if (versioningEnabled) {
versions = Integer.valueOf(mFolder.versioning.params.get("keep"));
@ -360,9 +361,7 @@ public class FolderFragment extends Fragment
mFolder = new Folder();
mFolder.id = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_ID);
mFolder.label = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_LABEL);
mFolder.path = "";
mFolder.rescanIntervalS = 259200; // Scan every 3 days (in case inotify dropped some changes)
mFolder.setDevices(new ArrayList<>());
mFolder.versioning = new Folder.Versioning();
String deviceId = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
if (deviceId != null) {

View file

@ -58,6 +58,9 @@ public class FolderListFragment extends ListFragment implements SyncthingService
mTimer.schedule(new TimerTask() {
@Override
public void run() {
if (getActivity() == null)
return;
getActivity().runOnUiThread(FolderListFragment.this::updateList);
}
@ -81,8 +84,7 @@ public class FolderListFragment extends ListFragment implements SyncthingService
*/
private void updateList() {
SyncthingActivity activity = (SyncthingActivity) getActivity();
if (activity == null || activity.getApi() == null || getView() == null ||
activity.isFinishing())
if (activity.getApi() == null || getView() == null || activity.isFinishing())
return;
if (mAdapter == null) {

View file

@ -12,7 +12,7 @@ public class Folder {
public String label;
public String path;
public String type;
private transient List<Map<String, String>> devices;
private transient List<Map<String, String>> devices = new ArrayList<>();
public int rescanIntervalS;
public boolean ignorePerms;
public boolean autoNormalize;
@ -47,9 +47,9 @@ public class Folder {
return devicesList;
}
public void setDevices(List<String> newDvices) {
public void setDevices(List<String> newDevices) {
devices.clear();
for (String d : newDvices) {
for (String d : newDevices) {
Map<String, String> map = new HashMap<>();
map.put("deviceID", d);
devices.add(map);

View file

@ -174,14 +174,18 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
*/
public void requireRestart(Activity activity) {
if (mRestartPostponed) {
new PostTask(mUrl, PostTask.URI_CONFIG, mHttpsCertPath, mApiKey, null)
.execute(mConfig.toString());
sendConfig();
} else {
activity.startActivity(new Intent(mContext, RestartActivity.class));
}
mOnConfigChangedListener.onConfigChanged();
}
private void sendConfig() {
new PostTask(mUrl, PostTask.URI_CONFIG, mHttpsCertPath, mApiKey, null)
.execute(new Gson().toJson(mConfig));
}
/**
* Immediately restarts Syncthing, without confirmation.
*/
@ -190,7 +194,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
Intent intent = new Intent(mContext, SyncthingService.class)
.setAction(SyncthingService.ACTION_RESTART);
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) {
removeDeviceInternal(deviceId);
sendConfig();
}
private void removeDeviceInternal(String deviceId) {
Iterator<Device> it = mConfig.devices.iterator();
while (it.hasNext()) {
Device d = it.next();
@ -240,6 +249,11 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
}
public void removeFolder(String id) {
removeFolderInternal(id);
sendConfig();
}
private void removeFolderInternal(String id) {
Iterator<Folder> it = mConfig.folders.iterator();
while (it.hasNext()) {
Folder f = it.next();
@ -253,6 +267,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
normalizeDeviceId(device.deviceID, ((normalizedId, error) -> {
if (error == null) {
mConfig.devices.add(device);
sendConfig();
}
else {
listener.onDeviceIdNormalized(normalizedId, error);
@ -262,15 +277,16 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
public void addFolder(Folder folder) {
mConfig.folders.add(folder);
sendConfig();
}
public void editDevice(Device newDevice) {
removeDevice(newDevice.deviceID);
removeDeviceInternal(newDevice.deviceID);
addDevice(newDevice, null);
}
public void editFolder(Folder newFolder) {
removeFolder(newFolder.id);
removeFolderInternal(newFolder.id);
addFolder(newFolder);
}