I am fetching podcast feed from the DB and displaying it in the RecyclerView using LoaderManager.LoaderCallbacks. In my content provider:
- I register an 'Observer' in the content resolver query() method with:
cursor.setNotificationUri(getContext().getContentResolver(), uri);
- When I update/insert/delete in the content resolver, I notify Observer with:
getContext().getContentResolver().notifyChange(uri, null);
soonLoaderReset()
is triggered when needed
Then I have a service with the DownloadManager, that update a progress of my ongoing downloads to the database every second. The loader is constantly loading the data from the DB and I can see the changing progress of every downloading episode in the UI.
I think, this is a wrong approach of notifying a change and is very very slow, but I can't think of any better solution right now. Could you suggest any effective solution with RecyclerView and download progress?
My custom activity with RecyclerView
public class MyActivity
implements LoaderManager.LoaderCallbacks<Cursor> {
private RecyclerView mRecyclerView;
private MyCustomRecyclerViewAdapter mAdapter;
...
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new CursorLoader(this,
myDataUri, null, null, null, null
);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mAdapter.swapCursor(data);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.swapCursor(null);
}
...
}
My custom adapter
public class MyCustomRecyclerViewAdapter
extends RecyclerView.Adapter<EpisodeAdapter.AudioAdapterViewHolder> {
...
public void swapCursor(Cursor newCursor) {
mCursor = newCursor;
notifyDataSetChanged();
}
...
}