mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 11:21:29 +00:00
Fixed problems with folder device selection (fixes #782)
This commit is contained in:
parent
dcdb6e1129
commit
df47050c18
3 changed files with 28 additions and 34 deletions
|
@ -22,7 +22,6 @@ 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;
|
||||
import com.nutomic.syncthingandroid.fragments.dialog.KeepVersionsDialogFragment;
|
||||
|
@ -96,14 +95,12 @@ public class FolderActivity extends SyncthingActivity
|
|||
mFolderNeedsToUpdate = true;
|
||||
break;
|
||||
case R.id.device_toggle:
|
||||
List<String> devicesList = mFolder.getDevices();
|
||||
Device device = (Device) view.getTag();
|
||||
if (isChecked) {
|
||||
devicesList.add(device.deviceID);
|
||||
mFolder.addDevice(device.deviceID);
|
||||
} else {
|
||||
devicesList.remove(device.deviceID);
|
||||
mFolder.removeDevice(device.deviceID);
|
||||
}
|
||||
mFolder.setDevices(devicesList);
|
||||
mFolderNeedsToUpdate = true;
|
||||
break;
|
||||
}
|
||||
|
@ -339,11 +336,7 @@ public class FolderActivity extends SyncthingActivity
|
|||
mFolder.versioning = new Folder.Versioning();
|
||||
String deviceId = getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
||||
if (deviceId != null) {
|
||||
List<String> devices = ImmutableList.<String>builder()
|
||||
.addAll(mFolder.getDevices())
|
||||
.add(deviceId)
|
||||
.build();
|
||||
mFolder.setDevices(devices);
|
||||
mFolder.addDevice(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,7 +363,7 @@ public class FolderActivity extends SyncthingActivity
|
|||
private void addDeviceViewAndSetListener(Device device, LayoutInflater inflater) {
|
||||
inflater.inflate(R.layout.item_device_form, mDevicesContainer);
|
||||
SwitchCompat deviceView = (SwitchCompat) mDevicesContainer.getChildAt(mDevicesContainer.getChildCount()-1);
|
||||
deviceView.setChecked(mFolder.getDevices().contains(device.deviceID));
|
||||
deviceView.setChecked(mFolder.getDevice(device.deviceID) != null);
|
||||
deviceView.setText(device.getDisplayName());
|
||||
deviceView.setTag(device);
|
||||
deviceView.setOnCheckedChangeListener(mCheckedListener);
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.nutomic.syncthingandroid.model;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -12,7 +12,7 @@ public class Folder {
|
|||
public String label;
|
||||
public String path;
|
||||
public String type;
|
||||
private transient List<Map<String, String>> devices = new ArrayList<>();
|
||||
public List<Device> devices = new ArrayList<>();
|
||||
public int rescanIntervalS;
|
||||
public boolean ignorePerms;
|
||||
public boolean autoNormalize;
|
||||
|
@ -36,23 +36,27 @@ public class Folder {
|
|||
public Map<String, String> params;
|
||||
}
|
||||
|
||||
public List<String> getDevices() {
|
||||
if (devices == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
List<String> devicesList = new ArrayList<>();
|
||||
for (Map<String, String> map : devices) {
|
||||
devicesList.addAll(map.values());
|
||||
}
|
||||
return devicesList;
|
||||
public void addDevice(String deviceId) {
|
||||
Device d = new Device();
|
||||
d.deviceID = deviceId;
|
||||
devices.add(d);
|
||||
}
|
||||
|
||||
public void setDevices(List<String> newDevices) {
|
||||
devices.clear();
|
||||
for (String d : newDevices) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("deviceID", d);
|
||||
devices.add(map);
|
||||
public Device getDevice(String deviceId) {
|
||||
for (Device d : devices) {
|
||||
if (d.deviceID.equals(deviceId)) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeDevice(String deviceId) {
|
||||
for (Iterator<Device> it = devices.iterator(); it.hasNext();) {
|
||||
String currentId = it.next().deviceID;
|
||||
if (currentId.equals(deviceId)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -371,13 +371,10 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
|||
int maxPercentage = 100;
|
||||
for (Map.Entry<String, Model> modelInfo : mCachedModelInfo.entrySet()) {
|
||||
boolean isShared = false;
|
||||
outerloop:
|
||||
for (Folder r : getFolders()) {
|
||||
for (String n : r.getDevices()) {
|
||||
if (n.equals(deviceId)) {
|
||||
isShared = true;
|
||||
break outerloop;
|
||||
}
|
||||
if (r.getDevice(deviceId) != null) {
|
||||
isShared = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isShared) {
|
||||
|
|
Loading…
Reference in a new issue