Search in sources :

Example 1 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class DeviceState method updateSingleDevice.

// returns the ID of the updated device.
public static synchronized String updateSingleDevice(Device updatedDevice, boolean save) {
    Device oldDevice = deviceMap.get(updatedDevice.id);
    Device.Builder toInsert = updatedDevice.toBuilder();
    // ensure we never have a device with a
    if (oldDevice != null) {
        toInsert.fillInFalseyValuesFromOther(oldDevice);
    }
    if (!truthy(toInsert.getColor())) {
        toInsert.setColor(getRandomCoreColor());
    }
    if (!truthy(toInsert.getName())) {
        // don't allow null or empty string names
        toInsert.setName(appContext.getString(R.string._unnamed_core_));
    }
    Device built = toInsert.build();
    deviceMap.put(built.id, built);
    if (save) {
        saveDevices();
    }
    return updatedDevice.id;
}
Also used : Device(io.spark.core.android.cloud.api.Device)

Example 2 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class DeviceState method updateAllKnownDevices.

public static synchronized void updateAllKnownDevices(List<Device> updatedDevices) {
    log.d("Updating known devices with: " + updatedDevices);
    Set<String> updatedDeviceIds = set();
    for (Device updatedDevice : updatedDevices) {
        String updatedDeviceId = updateSingleDevice(updatedDevice, false);
        updatedDeviceIds.add(updatedDeviceId);
    }
    // now remove the devices which weren't in the update.
    for (String missingDeviceId : set(deviceMap.keySet()).getDifference(updatedDeviceIds)) {
        log.d("Removing device from local device store: " + missingDeviceId);
        deviceMap.remove(missingDeviceId);
    }
    saveDevices();
}
Also used : Device(io.spark.core.android.cloud.api.Device)

Example 3 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class DeviceState method renameDevice.

public static synchronized void renameDevice(String coreId, String newName) {
    // Create a device with default values and let 'updateSingleDevice' do
    // the work. Kinda cheesy, but it works.
    Device device = deviceMap.get(coreId);
    if (device == null) {
        log.e("Cannot rename, no device found with ID: " + coreId);
        return;
    }
    updateSingleDevice(device.toBuilder().setName(newName).build(), true);
}
Also used : Device(io.spark.core.android.cloud.api.Device)

Example 4 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class CoreListFragment method onListItemClick.

@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    super.onListItemClick(listView, view, position, id);
    Device selectedDevice = deviceAdapter.getItem(position);
    // Notify the active callbacks interface (the activity, if the
    // fragment is attached to one) that an item has been selected.
    mCallbacks.onItemSelected(selectedDevice.id);
    mActivatedPosition = position;
}
Also used : Device(io.spark.core.android.cloud.api.Device)

Example 5 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class CoreListFragment method setActivatedItem.

public void setActivatedItem(String id) {
    Device device = DeviceState.getDeviceById(id);
    if (device == null) {
        log.w("Device was null when trying to set active list item??");
        return;
    }
    selectedDeviceId = device.id;
    mActivatedPosition = deviceAdapter.getPosition(device);
    setActiveCoreView();
}
Also used : Device(io.spark.core.android.cloud.api.Device)

Aggregations

Device (io.spark.core.android.cloud.api.Device)12 Fragment (android.app.Fragment)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 LayoutInflater (android.view.LayoutInflater)1 SmartConfigActivity (io.spark.core.android.ui.smartconfig.SmartConfigActivity)1 TinkerFragment (io.spark.core.android.ui.tinker.TinkerFragment)1 NamingHelper (io.spark.core.android.ui.util.NamingHelper)1 Type (java.lang.reflect.Type)1 List (java.util.List)1