use of com.nutomic.syncthingandroid.model.Device in project syncthing-android by syncthing.
the class DeviceActivity method onApiChange.
private void onApiChange(SyncthingService.State currentState) {
if (currentState != ACTIVE) {
finish();
return;
}
if (!mIsCreateMode) {
List<Device> devices = getApi().getDevices(false);
mDevice = null;
for (Device device : devices) {
if (device.deviceID.equals(getIntent().getStringExtra(EXTRA_DEVICE_ID))) {
mDevice = device;
break;
}
}
if (mDevice == null) {
Log.w(TAG, "Device not found in API update, maybe it was deleted?");
finish();
return;
}
}
getApi().getConnections(this::onReceiveConnections);
updateViewsAndSetListeners();
}
use of com.nutomic.syncthingandroid.model.Device in project syncthing-android by syncthing.
the class RestApi method getConnections.
/**
* Returns connection info for the local device and all connected devices.
*/
public void getConnections(final OnResultListener1<Connections> listener) {
new GetRequest(mContext, mUrl, GetRequest.URI_CONNECTIONS, mApiKey, null, result -> {
Long now = System.currentTimeMillis();
Long msElapsed = now - mPreviousConnectionTime;
if (msElapsed < Constants.GUI_UPDATE_INTERVAL) {
listener.onResult(deepCopy(mPreviousConnections.get(), Connections.class));
return;
}
mPreviousConnectionTime = now;
Connections connections = new Gson().fromJson(result, Connections.class);
for (Map.Entry<String, Connections.Connection> e : connections.connections.entrySet()) {
e.getValue().completion = mCompletion.getDeviceCompletion(e.getKey());
Connections.Connection prev = (mPreviousConnections.isPresent() && mPreviousConnections.get().connections.containsKey(e.getKey())) ? mPreviousConnections.get().connections.get(e.getKey()) : new Connections.Connection();
e.getValue().setTransferRate(prev, msElapsed);
}
Connections.Connection prev = mPreviousConnections.transform(c -> c.total).or(new Connections.Connection());
connections.total.setTransferRate(prev, msElapsed);
mPreviousConnections = Optional.of(connections);
listener.onResult(deepCopy(connections, Connections.class));
});
}
use of com.nutomic.syncthingandroid.model.Device in project syncthing-android by syncthing.
the class RestApi method ignoreFolder.
/**
* Permanently ignore a folder share request.
* Ignored folders will not trigger the "FolderRejected" event
* in {@link EventProcessor#onEvent}.
*/
public void ignoreFolder(String deviceId, String folderId, String folderLabel) {
synchronized (mConfigLock) {
for (Device device : mConfig.devices) {
if (deviceId.equals(device.deviceID)) {
/**
* Check if the folder has already been ignored.
*/
for (IgnoredFolder ignoredFolder : device.ignoredFolders) {
if (folderId.equals(ignoredFolder.id)) {
// Folder already ignored.
Log.d(TAG, "Folder [" + folderId + "] already ignored on device [" + deviceId + "]");
return;
}
}
/**
* Ignore folder by moving its corresponding "pendingFolder" entry to
* a newly created "ignoredFolder" entry.
*/
IgnoredFolder ignoredFolder = new IgnoredFolder();
ignoredFolder.id = folderId;
ignoredFolder.label = folderLabel;
ignoredFolder.time = dateString(new Date());
device.ignoredFolders.add(ignoredFolder);
if (BuildConfig.DEBUG) {
Log.v(TAG, "device.ignoredFolders = " + new Gson().toJson(device.ignoredFolders));
}
sendConfig();
Log.d(TAG, "Ignored folder [" + folderId + "] announced by device [" + deviceId + "]");
// Given deviceId handled.
break;
}
}
}
}
use of com.nutomic.syncthingandroid.model.Device in project syncthing-android by syncthing.
the class RestApi method getDevices.
/**
* Returns a list of all existing devices.
*
* @param includeLocal True if the local device should be included in the result.
*/
public List<Device> getDevices(boolean includeLocal) {
List<Device> devices;
synchronized (mConfigLock) {
devices = deepCopy(mConfig.devices, new TypeToken<List<Device>>() {
}.getType());
}
Iterator<Device> it = devices.iterator();
while (it.hasNext()) {
Device device = it.next();
boolean isLocalDevice = Objects.equal(mLocalDeviceId, device.deviceID);
if (!includeLocal && isLocalDevice) {
it.remove();
break;
}
}
return devices;
}
use of com.nutomic.syncthingandroid.model.Device in project syncthing-android by syncthing.
the class FolderActivity method updateViewsAndSetListeners.
private void updateViewsAndSetListeners() {
mLabelView.removeTextChangedListener(mTextWatcher);
mIdView.removeTextChangedListener(mTextWatcher);
mFolderFileWatcher.setOnCheckedChangeListener(null);
mFolderPaused.setOnCheckedChangeListener(null);
// Update views
mLabelView.setText(mFolder.label);
mIdView.setText(mFolder.id);
updateFolderTypeDescription();
updatePullOrderDescription();
updateVersioningDescription();
mFolderFileWatcher.setChecked(mFolder.fsWatcherEnabled);
mFolderPaused.setChecked(mFolder.paused);
List<Device> devicesList = getApi().getDevices(false);
mDevicesContainer.removeAllViews();
if (devicesList.isEmpty()) {
addEmptyDeviceListView();
} else {
for (Device n : devicesList) {
addDeviceViewAndSetListener(n, getLayoutInflater());
}
}
// Keep state updated
mLabelView.addTextChangedListener(mTextWatcher);
mIdView.addTextChangedListener(mTextWatcher);
mFolderFileWatcher.setOnCheckedChangeListener(mCheckedListener);
mFolderPaused.setOnCheckedChangeListener(mCheckedListener);
}
Aggregations