Search in sources :

Example 1 with DevicesAdapter

use of com.nutomic.syncthingandroid.views.DevicesAdapter 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)

Aggregations

SyncthingActivity (com.nutomic.syncthingandroid.activities.SyncthingActivity)1 Device (com.nutomic.syncthingandroid.model.Device)1 RestApi (com.nutomic.syncthingandroid.service.RestApi)1 DevicesAdapter (com.nutomic.syncthingandroid.views.DevicesAdapter)1