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 android.widget.Toast;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
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;
|
||||||
import com.nutomic.syncthingandroid.fragments.dialog.KeepVersionsDialogFragment;
|
import com.nutomic.syncthingandroid.fragments.dialog.KeepVersionsDialogFragment;
|
||||||
|
@ -96,14 +95,12 @@ public class FolderActivity extends SyncthingActivity
|
||||||
mFolderNeedsToUpdate = true;
|
mFolderNeedsToUpdate = true;
|
||||||
break;
|
break;
|
||||||
case R.id.device_toggle:
|
case R.id.device_toggle:
|
||||||
List<String> devicesList = mFolder.getDevices();
|
|
||||||
Device device = (Device) view.getTag();
|
Device device = (Device) view.getTag();
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
devicesList.add(device.deviceID);
|
mFolder.addDevice(device.deviceID);
|
||||||
} else {
|
} else {
|
||||||
devicesList.remove(device.deviceID);
|
mFolder.removeDevice(device.deviceID);
|
||||||
}
|
}
|
||||||
mFolder.setDevices(devicesList);
|
|
||||||
mFolderNeedsToUpdate = true;
|
mFolderNeedsToUpdate = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -339,11 +336,7 @@ public class FolderActivity extends SyncthingActivity
|
||||||
mFolder.versioning = new Folder.Versioning();
|
mFolder.versioning = new Folder.Versioning();
|
||||||
String deviceId = getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
String deviceId = getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
||||||
if (deviceId != null) {
|
if (deviceId != null) {
|
||||||
List<String> devices = ImmutableList.<String>builder()
|
mFolder.addDevice(deviceId);
|
||||||
.addAll(mFolder.getDevices())
|
|
||||||
.add(deviceId)
|
|
||||||
.build();
|
|
||||||
mFolder.setDevices(devices);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +363,7 @@ public class FolderActivity extends SyncthingActivity
|
||||||
private void addDeviceViewAndSetListener(Device device, LayoutInflater inflater) {
|
private void addDeviceViewAndSetListener(Device device, LayoutInflater inflater) {
|
||||||
inflater.inflate(R.layout.item_device_form, mDevicesContainer);
|
inflater.inflate(R.layout.item_device_form, mDevicesContainer);
|
||||||
SwitchCompat deviceView = (SwitchCompat) mDevicesContainer.getChildAt(mDevicesContainer.getChildCount()-1);
|
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.setText(device.getDisplayName());
|
||||||
deviceView.setTag(device);
|
deviceView.setTag(device);
|
||||||
deviceView.setOnCheckedChangeListener(mCheckedListener);
|
deviceView.setOnCheckedChangeListener(mCheckedListener);
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.nutomic.syncthingandroid.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -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 = new ArrayList<>();
|
public List<Device> devices = new ArrayList<>();
|
||||||
public int rescanIntervalS;
|
public int rescanIntervalS;
|
||||||
public boolean ignorePerms;
|
public boolean ignorePerms;
|
||||||
public boolean autoNormalize;
|
public boolean autoNormalize;
|
||||||
|
@ -36,23 +36,27 @@ public class Folder {
|
||||||
public Map<String, String> params;
|
public Map<String, String> params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getDevices() {
|
public void addDevice(String deviceId) {
|
||||||
if (devices == null)
|
Device d = new Device();
|
||||||
return new ArrayList<>();
|
d.deviceID = deviceId;
|
||||||
|
devices.add(d);
|
||||||
List<String> devicesList = new ArrayList<>();
|
|
||||||
for (Map<String, String> map : devices) {
|
|
||||||
devicesList.addAll(map.values());
|
|
||||||
}
|
|
||||||
return devicesList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDevices(List<String> newDevices) {
|
public Device getDevice(String deviceId) {
|
||||||
devices.clear();
|
for (Device d : devices) {
|
||||||
for (String d : newDevices) {
|
if (d.deviceID.equals(deviceId)) {
|
||||||
Map<String, String> map = new HashMap<>();
|
return d;
|
||||||
map.put("deviceID", d);
|
}
|
||||||
devices.add(map);
|
}
|
||||||
|
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;
|
int maxPercentage = 100;
|
||||||
for (Map.Entry<String, Model> modelInfo : mCachedModelInfo.entrySet()) {
|
for (Map.Entry<String, Model> modelInfo : mCachedModelInfo.entrySet()) {
|
||||||
boolean isShared = false;
|
boolean isShared = false;
|
||||||
outerloop:
|
|
||||||
for (Folder r : getFolders()) {
|
for (Folder r : getFolders()) {
|
||||||
for (String n : r.getDevices()) {
|
if (r.getDevice(deviceId) != null) {
|
||||||
if (n.equals(deviceId)) {
|
isShared = true;
|
||||||
isShared = true;
|
break;
|
||||||
break outerloop;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isShared) {
|
if (isShared) {
|
||||||
|
|
Loading…
Reference in a new issue