Search in sources :

Example 6 with Device

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);
}
Also used : SyncthingActivity(com.nutomic.syncthingandroid.activities.SyncthingActivity) RestApi(com.nutomic.syncthingandroid.service.RestApi) Device(com.nutomic.syncthingandroid.model.Device) DevicesAdapter(com.nutomic.syncthingandroid.views.DevicesAdapter)

Example 7 with Device

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;
}
Also used : Device(com.nutomic.syncthingandroid.model.Device)

Example 8 with Device

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();
}
Also used : Device(com.nutomic.syncthingandroid.model.Device)

Example 9 with Device

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.");
}
Also used : RemoteIgnoredDevice(com.nutomic.syncthingandroid.model.RemoteIgnoredDevice) Device(com.nutomic.syncthingandroid.model.Device)

Example 10 with Device

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);
}
Also used : Device(com.nutomic.syncthingandroid.model.Device) FolderActivity(com.nutomic.syncthingandroid.activities.FolderActivity) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

Device (com.nutomic.syncthingandroid.model.Device)10 RemoteIgnoredDevice (com.nutomic.syncthingandroid.model.RemoteIgnoredDevice)4 Intent (android.content.Intent)2 Gson (com.google.gson.Gson)2 IgnoredFolder (com.nutomic.syncthingandroid.model.IgnoredFolder)2 Date (java.util.Date)2 List (java.util.List)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 PreferenceManager (android.preference.PreferenceManager)1 Log (android.util.Log)1 Objects (com.google.common.base.Objects)1 Optional (com.google.common.base.Optional)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 TypeToken (com.google.common.reflect.TypeToken)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1