Skip to content

Instantly share code, notes, and snippets.

@robhinds
Last active December 15, 2015 04:19
Show Gist options
  • Save robhinds/5200181 to your computer and use it in GitHub Desktop.
Save robhinds/5200181 to your computer and use it in GitHub Desktop.
protected void onPostExecute(final List<Article> articles) {
Log.e("ASYNC", "POST EXECUTE");
articleListFrag.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
for (Article a : articles){
Log.d("DB", "Searching DB for GUID: " + a.getGuid());
DbAdapter dba = new DbAdapter(articleListFrag.getActivity());
dba.openToRead();
Article fetchedArticle = dba.getBlogListing(a.getGuid());
dba.close();
if (fetchedArticle == null){
Log.d("DB", "Found entry for first time: " + a.getTitle());
dba = new DbAdapter(articleListFrag.getActivity());
dba.openToWrite();
dba.insertBlogListing(a.getGuid());
dba.close();
}else{
a.setDbId(fetchedArticle.getDbId());
a.setOffline(fetchedArticle.isOffline());
a.setRead(fetchedArticle.isRead());
}
}
ArticleListAdapter adapter = new ArticleListAdapter(articleListFrag.getActivity(), articles);
articleListFrag.setListAdapter(adapter);
adapter.notifyDataSetChanged();
}
});
progress.dismiss();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment