private void refreshList() { if (Utils.isOnline(getActivity())) { getActivity().getContentResolver().delete(Contract.Nodes.CONTENT_URI, null, null); currentBatch = 1; updateManager.startUpdating(UpdateManager.UpdateType.NODES, LOAD_LIMIT, 0); setRefreshIndicationState(true); // TODO: Load only unacknowledged alarms here. updateManager.startUpdating(UpdateManager.UpdateType.ALARMS, 0, 0); } else { Toast.makeText(getActivity(), getString(R.string.refresh_failed_offline), Toast.LENGTH_LONG) .show(); } }
@Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (updateManager.isUpdating(UpdateManager.UpdateType.NODES)) { return; } if (scrollState == SCROLL_STATE_IDLE) { if (getListView().getLastVisiblePosition() >= getListView().getCount() - SCROLL_THRESHOLD) { // TODO: Add search support updateManager.startUpdating( UpdateManager.UpdateType.NODES, LOAD_LIMIT, LOAD_LIMIT * currentBatch); currentBatch++; setRefreshIndicationState(true); } } }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { adapter.swapCursor(cursor); if (isDualPane) { if (cursor.moveToFirst()) { /** If list is not empty, trying to restore previously displayed details. */ restoreHandler.sendEmptyMessage(0); } else { /** If list became empty, removing previously displayed details */ removeDetailsHandler.sendEmptyMessage(0); } } /** If there is no sync going and list is empty, refreshing list. */ Account account = AccountService.getAccount(); if (account != null) { boolean syncActive = ContentResolver.isSyncActive(account, Contract.CONTENT_AUTHORITY); boolean syncPending = ContentResolver.isSyncPending(account, Contract.CONTENT_AUTHORITY); if (!cursor.moveToFirst() && firstLoad && !(syncActive || syncPending)) { refreshList(); } } firstLoad = false; setRefreshIndicationState(updateManager.isUpdating(UpdateManager.UpdateType.ALARMS)); }
@Override public void onPrepareOptionsMenu(Menu menu) { boolean isDrawerOpen = ((BaseActivity) getActivity()).isDrawerOpen(); MenuItem refreshItem = menu.findItem(R.id.menu_refresh); refreshItem.setVisible(!isDrawerOpen); setRefreshIndicationState(updateManager.isUpdating(UpdateManager.UpdateType.ALARMS)); }
private void refreshList() { if (Utils.isOnline(getActivity())) { getActivity().getContentResolver().delete(Contract.Alarms.CONTENT_URI, null, null); updateManager.startUpdating(UpdateManager.UpdateType.ALARMS, LOAD_LIMIT, 0); setRefreshIndicationState(true); } else { Toast.makeText(getActivity(), getString(R.string.refresh_failed_offline), Toast.LENGTH_LONG) .show(); } }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { adapter.swapCursor(cursor); if (cursor.moveToFirst()) { if (isDualPane) { /** If list is not empty, trying to restore previously displayed details. */ restoreHandler.sendEmptyMessage(0); } } else { /** If list is empty, refreshing it. */ if (firstLoad) { refreshList(); } } firstLoad = false; setRefreshIndicationState(updateManager.isUpdating(UpdateManager.UpdateType.NODES)); currentBatch = getListView().getCount() / LOAD_LIMIT; }
@Override public void onResume() { super.onResume(); setRefreshIndicationState(updateManager.isUpdating(UpdateManager.UpdateType.ALARMS)); }
@Override public void onResume() { super.onResume(); getActivity().getSupportLoaderManager().restartLoader(LOADER_ID, null, this); setRefreshIndicationState(updateManager.isUpdating(UpdateManager.UpdateType.NODES)); }