use of com.nutomic.syncthingandroid.model.Device in project syncthing-android by syncthing.
the class DeviceListFragment method updateList.
/**
* Refreshes ListView by updating devices and info.
*
* Also creates adapter if it doesn't exist yet.
*/
private void updateList() {
SyncthingActivity activity = (SyncthingActivity) getActivity();
if (activity == null || getView() == null || activity.isFinishing()) {
return;
}
RestApi restApi = activity.getApi();
if (restApi == null || !restApi.isConfigLoaded()) {
return;
}
List<Device> devices = restApi.getDevices(false);
if (devices == null) {
return;
}
if (mAdapter == null) {
mAdapter = new DevicesAdapter(activity);
setListAdapter(mAdapter);
}
// Prevent scroll position reset due to list update from clear().
mAdapter.setNotifyOnChange(false);
mAdapter.clear();
Collections.sort(devices, DEVICES_COMPARATOR);
mAdapter.addAll(devices);
mAdapter.updateConnections(restApi);
mAdapter.notifyDataSetChanged();
setListShown(true);
}
use of com.nutomic.syncthingandroid.model.Device in project syncthing-android by syncthing.
the class DeviceActivity method initDevice.
private void initDevice() {
mDevice = new Device();
mDevice.name = getIntent().getStringExtra(EXTRA_DEVICE_NAME);
mDevice.deviceID = getIntent().getStringExtra(EXTRA_DEVICE_ID);
mDevice.addresses = DYNAMIC_ADDRESS;
mDevice.compression = METADATA.getValue(this);
mDevice.introducer = false;
mDevice.paused = false;
}
use of com.nutomic.syncthingandroid.model.Device in project syncthing-android by syncthing.
the class DeviceActivity method onServiceStateChange.
private void onServiceStateChange(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 getLocalDevice.
public Device getLocalDevice() {
List<Device> devices = getDevices(true);
if (devices.isEmpty()) {
throw new RuntimeException("RestApi.getLocalDevice: devices is empty.");
}
Log.v(TAG, "getLocalDevice: Looking for local device ID " + mLocalDeviceId);
for (Device d : devices) {
if (d.deviceID.equals(mLocalDeviceId)) {
return deepCopy(d, Device.class);
}
}
throw new RuntimeException("RestApi.getLocalDevice: Failed to get the local device crucial to continuing execution.");
}
use of com.nutomic.syncthingandroid.model.Device in project syncthing-android by syncthing.
the class EventProcessor method onPendingFoldersChanged.
private void onPendingFoldersChanged(Map<String, String> added) {
String deviceId = added.get("deviceID");
String folderId = added.get("folderID");
String folderLabel = added.get("folderLabel");
if (deviceId == null || folderId == null) {
return;
}
Log.d(TAG, "Device " + deviceId + " wants to share folder " + folderLabel + " (" + folderId + ")");
// Find the deviceName corresponding to the deviceId
String deviceName = null;
for (Device d : mApi.getDevices(false)) {
if (d.deviceID.equals(deviceId)) {
deviceName = d.getDisplayName();
break;
}
}
String title = mContext.getString(R.string.folder_rejected, deviceName, folderLabel.isEmpty() ? folderId : folderLabel + " (" + folderId + ")");
int notificationId = mNotificationHandler.getNotificationIdFromText(title);
// Prepare "accept" action.
boolean isNewFolder = Stream.of(mApi.getFolders()).noneMatch(f -> f.id.equals(folderId));
Intent intentAccept = new Intent(mContext, FolderActivity.class).putExtra(FolderActivity.EXTRA_NOTIFICATION_ID, notificationId).putExtra(FolderActivity.EXTRA_IS_CREATE, isNewFolder).putExtra(FolderActivity.EXTRA_DEVICE_ID, deviceId).putExtra(FolderActivity.EXTRA_FOLDER_ID, folderId).putExtra(FolderActivity.EXTRA_FOLDER_LABEL, folderLabel);
PendingIntent piAccept = PendingIntent.getActivity(mContext, notificationId, intentAccept, PendingIntent.FLAG_UPDATE_CURRENT);
// Prepare "ignore" action.
Intent intentIgnore = new Intent(mContext, SyncthingService.class).putExtra(SyncthingService.EXTRA_NOTIFICATION_ID, notificationId).putExtra(SyncthingService.EXTRA_DEVICE_ID, deviceId).putExtra(SyncthingService.EXTRA_FOLDER_ID, folderId).putExtra(SyncthingService.EXTRA_FOLDER_LABEL, folderLabel);
intentIgnore.setAction(SyncthingService.ACTION_IGNORE_FOLDER);
PendingIntent piIgnore = PendingIntent.getService(mContext, 0, intentIgnore, PendingIntent.FLAG_UPDATE_CURRENT);
// Show notification.
mNotificationHandler.showConsentNotification(notificationId, title, piAccept, piIgnore);
}
Aggregations