public void attach(GraphObjectAdapter<T> adapter) { loader = (GraphObjectPagingLoader<T>) getLoaderManager() .initLoader( 0, null, new LoaderManager.LoaderCallbacks<SimpleGraphObjectCursor<T>>() { @Override public Loader<SimpleGraphObjectCursor<T>> onCreateLoader( int id, Bundle args) { return LoadingStrategy.this.onCreateLoader(); } @Override public void onLoadFinished( Loader<SimpleGraphObjectCursor<T>> loader, SimpleGraphObjectCursor<T> data) { if (loader != LoadingStrategy.this.loader) { throw new FacebookException("Received callback for unknown loader."); } LoadingStrategy.this.onLoadFinished( (GraphObjectPagingLoader<T>) loader, data); } @Override public void onLoaderReset(Loader<SimpleGraphObjectCursor<T>> loader) { if (loader != LoadingStrategy.this.loader) { throw new FacebookException("Received callback for unknown loader."); } LoadingStrategy.this.onLoadReset((GraphObjectPagingLoader<T>) loader); } }); loader.setOnErrorListener( new GraphObjectPagingLoader.OnErrorListener() { @Override public void onError(FacebookException error, GraphObjectPagingLoader<?> loader) { hideActivityCircle(); if (onErrorListener != null) { onErrorListener.onError(PickerFragment.this, error); } } }); this.adapter = adapter; // Tell the adapter about any data we might already have. this.adapter.changeCursor(loader.getCursor()); this.adapter.setOnErrorListener( new GraphObjectAdapter.OnErrorListener() { @Override public void onError(GraphObjectAdapter<?> adapter, FacebookException error) { if (onErrorListener != null) { onErrorListener.onError(PickerFragment.this, error); } } }); }
public void detach() { adapter.setDataNeededListener(null); adapter.setOnErrorListener(null); loader.setOnErrorListener(null); loader = null; adapter = null; }
@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); } }
public boolean isDataPresentOrLoading() { return !adapter.isEmpty() || loader.isLoading(); }
public void startLoading(Request request) { if (loader != null) { loader.startLoading(request, canSkipRoundTripIfCached()); onStartLoading(loader, request); } }
public void clearResults() { if (loader != null) { loader.clearResults(); } }