Skip to content

Instantly share code, notes, and snippets.

@madhu314
Created January 15, 2017 16:44
Show Gist options
  • Save madhu314/cdbeb6b3881cfd9fd5c1533f9ab0ec6c to your computer and use it in GitHub Desktop.
Save madhu314/cdbeb6b3881cfd9fd5c1533f9ab0ec6c to your computer and use it in GitHub Desktop.
public void add(Article article) {
sortedList.beginBatchedUpdates();
sortedList.add(SectionArticle.createCategory(article));
sortedList.add(SectionArticle.createArticle(article));
sortedList.endBatchedUpdates();
}
public void remove(Article article) {
SectionArticle sectionArticle = SectionArticle.createArticle(article);
sortedList.beginBatchedUpdates();
sortedList.remove(sectionArticle);
int categoryCount = 0;
for (int i = 0; i < sortedList.size(); i++) {
SectionArticle sectionArticleTemp = itemAt(i);
if (sectionArticleTemp.isArticle() && sectionArticleTemp.article()
.category()
.equalsIgnoreCase(article.category())) {
categoryCount++;
}
}
if (categoryCount < 1) {
sortedList.remove(SectionArticle.createCategory(sectionArticle.article()));
}
sortedList.endBatchedUpdates();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment