@Test public void testRunsQuery() throws Throwable { int offset = 0; int limit = 10; ContentCallback dummyContentCallback = new ContentCallback() { @Override public void onCursorReady(Query query, Cursor cursor) { } }; final Query query = new Query( UNPAGED_URI, null, createArgs(offset, limit), null, dummyContentCallback); mCallback.reset(1); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { mRunner.query(query, mCallback); } }); mCallback.waitFor(10); mCallback.assertQueried(query.getId()); mCallback.assertReceivedContent(UNPAGED_URI, query.getId()); }
@Override @SuppressWarnings("unchecked") public void query(final @NonNull Query query, @NonNull final Callback callback) { if (DEBUG) Log.d(TAG, "Handling query: " + query); LoaderCallbacks callbacks = new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { if (DEBUG) Log.i(TAG, "Loading results for query: " + query); checkArgument(id == query.getId(), "Id doesn't match query id."); return new android.content.CursorLoader(mContext) { @Override public Cursor loadInBackground() { return callback.runQueryInBackground(query); } }; } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (DEBUG) Log.i(TAG, "Finished loading: " + query); mLoaderMgr.destroyLoader(query.getId()); callback.onQueryFinished(query, cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { if (DEBUG) Log.w(TAG, "Ignoring loader reset for query: " + query); } }; mLoaderMgr.restartLoader(query.getId(), null, callbacks); }
LoaderQueryRunner implements ContentPager.QueryRunner { @Override @SuppressWarnings("unchecked") public void query(final @NonNull Query query, @NonNull final Callback callback) { if (DEBUG) Log.d(TAG, "Handling query: " + query); LoaderCallbacks callbacks = new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { if (DEBUG) Log.i(TAG, "Loading results for query: " + query); checkArgument(id == query.getId(), "Id doesn't match query id."); return new android.content.CursorLoader(mContext) { @Override public Cursor loadInBackground() { return callback.runQueryInBackground(query); } }; } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (DEBUG) Log.i(TAG, "Finished loading: " + query); mLoaderMgr.destroyLoader(query.getId()); callback.onQueryFinished(query, cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { if (DEBUG) Log.w(TAG, "Ignoring loader reset for query: " + query); } }; mLoaderMgr.restartLoader(query.getId(), null, callbacks); } }
LoaderQueryRunner implements ContentPager.QueryRunner { @Override @SuppressWarnings("unchecked") public void query(final @NonNull Query query, @NonNull final Callback callback) { if (DEBUG) Log.d(TAG, "Handling query: " + query); LoaderCallbacks callbacks = new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { if (DEBUG) Log.i(TAG, "Loading results for query: " + query); checkArgument(id == query.getId(), "Id doesn't match query id."); return new android.content.CursorLoader(mContext) { @Override public Cursor loadInBackground() { return callback.runQueryInBackground(query); } }; } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (DEBUG) Log.i(TAG, "Finished loading: " + query); mLoaderMgr.destroyLoader(query.getId()); callback.onQueryFinished(query, cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { if (DEBUG) Log.w(TAG, "Ignoring loader reset for query: " + query); } }; mLoaderMgr.restartLoader(query.getId(), null, callbacks); } LoaderQueryRunner(@NonNull Context context, @NonNull LoaderManager loaderMgr); }
LoaderQueryRunner implements ContentPager.QueryRunner { @Override @SuppressWarnings("unchecked") public void query(final @NonNull Query query, @NonNull final Callback callback) { if (DEBUG) Log.d(TAG, "Handling query: " + query); LoaderCallbacks callbacks = new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { if (DEBUG) Log.i(TAG, "Loading results for query: " + query); checkArgument(id == query.getId(), "Id doesn't match query id."); return new android.content.CursorLoader(mContext) { @Override public Cursor loadInBackground() { return callback.runQueryInBackground(query); } }; } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (DEBUG) Log.i(TAG, "Finished loading: " + query); mLoaderMgr.destroyLoader(query.getId()); callback.onQueryFinished(query, cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { if (DEBUG) Log.w(TAG, "Ignoring loader reset for query: " + query); } }; mLoaderMgr.restartLoader(query.getId(), null, callbacks); } LoaderQueryRunner(@NonNull Context context, @NonNull LoaderManager loaderMgr); @Override @SuppressWarnings("unchecked") // feels spurious. But can't commit line :80 w/o this. void query(final @NonNull Query query, @NonNull final Callback callback); @Override boolean isRunning(@NonNull Query query); @Override void cancel(@NonNull Query query); }
LoaderQueryRunner implements ContentPager.QueryRunner { @Override @SuppressWarnings("unchecked") public void query(final @NonNull Query query, @NonNull final Callback callback) { if (DEBUG) Log.d(TAG, "Handling query: " + query); LoaderCallbacks callbacks = new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { if (DEBUG) Log.i(TAG, "Loading results for query: " + query); checkArgument(id == query.getId(), "Id doesn't match query id."); return new android.content.CursorLoader(mContext) { @Override public Cursor loadInBackground() { return callback.runQueryInBackground(query); } }; } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (DEBUG) Log.i(TAG, "Finished loading: " + query); mLoaderMgr.destroyLoader(query.getId()); callback.onQueryFinished(query, cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { if (DEBUG) Log.w(TAG, "Ignoring loader reset for query: " + query); } }; mLoaderMgr.restartLoader(query.getId(), null, callbacks); } LoaderQueryRunner(@NonNull Context context, @NonNull LoaderManager loaderMgr); @Override @SuppressWarnings("unchecked") // feels spurious. But can't commit line :80 w/o this. void query(final @NonNull Query query, @NonNull final Callback callback); @Override boolean isRunning(@NonNull Query query); @Override void cancel(@NonNull Query query);  }