Search in sources :

Example 1 with FoldersAdapter

use of com.nutomic.syncthingandroid.views.FoldersAdapter in project syncthing-android by syncthing.

the class FolderListFragment method updateList.

/**
 * Refreshes ListView by updating folders 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<Folder> folders = restApi.getFolders();
    if (folders == null) {
        return;
    }
    if (mAdapter == null) {
        mAdapter = new FoldersAdapter(activity);
        setListAdapter(mAdapter);
    }
    // Prevent scroll position reset due to list update from clear().
    mAdapter.setNotifyOnChange(false);
    mAdapter.clear();
    mAdapter.addAll(folders);
    mAdapter.updateFolderStatus(restApi);
    mAdapter.notifyDataSetChanged();
    setListShown(true);
}
Also used : FoldersAdapter(com.nutomic.syncthingandroid.views.FoldersAdapter) SyncthingActivity(com.nutomic.syncthingandroid.activities.SyncthingActivity) RestApi(com.nutomic.syncthingandroid.service.RestApi) Folder(com.nutomic.syncthingandroid.model.Folder)

Aggregations

SyncthingActivity (com.nutomic.syncthingandroid.activities.SyncthingActivity)1 Folder (com.nutomic.syncthingandroid.model.Folder)1 RestApi (com.nutomic.syncthingandroid.service.RestApi)1 FoldersAdapter (com.nutomic.syncthingandroid.views.FoldersAdapter)1