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;
}
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();
}
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);
}
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;
}
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();
}
Aggregations