private void loadDataSkippingRoundTripIfCached() { clearResults(); Request request = getRequestForLoadData(getSession()); if (request != null) { onLoadingData(); loadingStrategy.startLoading(request); } }
@Override public void onDetach() { super.onDetach(); listView.setOnScrollListener(null); listView.setAdapter(null); loadingStrategy.detach(); sessionTracker.stopTracking(); }
@Override public void attach(GraphObjectAdapter<GraphPlace> adapter) { super.attach(adapter); this.adapter.setDataNeededListener( new GraphObjectAdapter.DataNeededListener() { @Override public void onDataNeeded() { // Do nothing if we are currently loading data . We will get notified again when that // load finishes if the adapter still // needs more data. Otherwise, follow the next link. if (!loader.isLoading()) { loader.followNextLink(); } } }); }
private void clearResults() { if (adapter != null) { boolean wasSelection = !selectionStrategy.isEmpty(); boolean wasData = !adapter.isEmpty(); loadingStrategy.clearResults(); selectionStrategy.clear(); adapter.notifyDataSetChanged(); // Tell anyone who cares the data and selection has changed, if they have. if (wasData && onDataChangedListener != null) { onDataChangedListener.onDataChanged(PickerFragment.this); } if (wasSelection && onSelectionChangedListener != null) { onSelectionChangedListener.onSelectionChanged(PickerFragment.this); } } }
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); sessionTracker = new SessionTracker( getActivity(), new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { if (!session.isOpened()) { // When a session is closed, we want to clear out our data so it is not visible to // subsequent users clearResults(); } } }); setSettingsFromBundle(savedInstanceState); loadingStrategy = createLoadingStrategy(); loadingStrategy.attach(adapter); selectionStrategy = createSelectionStrategy(); selectionStrategy.readSelectionFromBundle(savedInstanceState, SELECTION_BUNDLE_KEY); // Should we display a title bar? (We need to do this after we've retrieved our bundle // settings.) if (showTitleBar) { inflateTitleBar((ViewGroup) getView()); } if (activityCircle != null && savedInstanceState != null) { boolean shown = savedInstanceState.getBoolean(ACTIVITY_CIRCLE_SHOW_KEY, false); if (shown) { displayActivityCircle(); } else { // Should be hidden already, but just to be sure. hideActivityCircle(); } } }
@Override protected void onLoadFinished( GraphObjectPagingLoader<GraphPlace> loader, SimpleGraphObjectCursor<GraphPlace> data) { super.onLoadFinished(loader, data); // We could be called in this state if we are clearing data or if we are being re-attached // in the middle of a query. if (data == null || loader.isLoading()) { return; } hideActivityCircle(); if (data.isFromCache()) { // Only the first page can be cached, since all subsequent pages will be round-tripped. // Force // a refresh of the first page before we allow paging to begin. If the first page produced // no data, launch the refresh immediately, otherwise schedule it for later. loader.refreshOriginalRequest( data.areMoreObjectsAvailable() ? CACHED_RESULT_REFRESH_DELAY : 0); } }
/** * Causes the picker to load data from the service and display it to the user. * * @param forceReload if true, data will be loaded even if there is already data being displayed * (or loading); if false, data will not be re-loaded if it is already displayed (or loading) */ public void loadData(boolean forceReload) { if (!forceReload && loadingStrategy.isDataPresentOrLoading()) { return; } loadDataSkippingRoundTripIfCached(); }