Search in sources :

Example 1 with Device

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

Example 2 with Device

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));
    });
}
Also used : Connections(com.nutomic.syncthingandroid.model.Connections) Context(android.content.Context) JsonObject(com.google.gson.JsonObject) RemoteIgnoredDevice(com.nutomic.syncthingandroid.model.RemoteIgnoredDevice) URL(java.net.URL) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) Completion(com.nutomic.syncthingandroid.model.Completion) HashMap(java.util.HashMap) TypeToken(com.google.common.reflect.TypeToken) JsonParser(com.google.gson.JsonParser) Options(com.nutomic.syncthingandroid.model.Options) GsonBuilder(com.google.gson.GsonBuilder) IgnoredFolder(com.nutomic.syncthingandroid.model.IgnoredFolder) JsonElement(com.google.gson.JsonElement) ShareActivity(com.nutomic.syncthingandroid.activities.ShareActivity) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Folder(com.nutomic.syncthingandroid.model.Folder) Optional(com.google.common.base.Optional) Gson(com.google.gson.Gson) BuildConfig(com.nutomic.syncthingandroid.BuildConfig) Map(java.util.Map) SyncthingApp(com.nutomic.syncthingandroid.SyncthingApp) SystemInfo(com.nutomic.syncthingandroid.model.SystemInfo) FolderStatus(com.nutomic.syncthingandroid.model.FolderStatus) Connections(com.nutomic.syncthingandroid.model.Connections) PreferenceManager(android.preference.PreferenceManager) Objects(com.google.common.base.Objects) Config(com.nutomic.syncthingandroid.model.Config) Device(com.nutomic.syncthingandroid.model.Device) Log(android.util.Log) Event(com.nutomic.syncthingandroid.model.Event) CompletionInfo(com.nutomic.syncthingandroid.model.CompletionInfo) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) PostConfigRequest(com.nutomic.syncthingandroid.http.PostConfigRequest) Set(java.util.Set) PostRequest(com.nutomic.syncthingandroid.http.PostRequest) JsonArray(com.google.gson.JsonArray) List(java.util.List) Type(java.lang.reflect.Type) SystemVersion(com.nutomic.syncthingandroid.model.SystemVersion) GetRequest(com.nutomic.syncthingandroid.http.GetRequest) Comparator(java.util.Comparator) Collections(java.util.Collections) GetRequest(com.nutomic.syncthingandroid.http.GetRequest) Gson(com.google.gson.Gson) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with Device

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;
            }
        }
    }
}
Also used : IgnoredFolder(com.nutomic.syncthingandroid.model.IgnoredFolder) RemoteIgnoredDevice(com.nutomic.syncthingandroid.model.RemoteIgnoredDevice) Device(com.nutomic.syncthingandroid.model.Device) Gson(com.google.gson.Gson) Date(java.util.Date)

Example 4 with Device

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

Example 5 with Device

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

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