use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.
the class TagBookmarkPresenter method onRefreshedData.
void onRefreshedData(Pair<List<Tag>, List<Long>> data) {
List<Tag> tags1 = data.first;
int numberOfTags = tags1.size();
if (numberOfTags == 0 || tags1.get(numberOfTags - 1).getId() != -1) {
tags1.add(new Tag(-1, ""));
}
List<Long> bookmarkTags = data.second;
checkedTags.clear();
for (int i = 0, tagsSize = tags1.size(); i < tagsSize; i++) {
Tag tag = tags1.get(i);
if (bookmarkTags.contains(tag.getId())) {
checkedTags.add(tag.getId());
}
}
madeChanges = false;
TagBookmarkPresenter.this.tags = tags1;
shouldRefreshTags = false;
if (dialog != null) {
dialog.setData(TagBookmarkPresenter.this.tags, checkedTags);
}
}
use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.
the class QuranListAdapter method bindRow.
private void bindRow(HeaderHolder vh, int position) {
ViewHolder holder = (ViewHolder) vh;
final QuranRow item = elements[position];
bindHeader(vh, position);
holder.number.setText(QuranUtils.getLocalizedNumber(context, item.sura));
holder.metadata.setVisibility(View.VISIBLE);
holder.metadata.setText(item.metadata);
holder.tags.setVisibility(View.GONE);
if (item.juzType != null) {
holder.image.setImageDrawable(new JuzView(context, item.juzType, item.juzOverlayText));
holder.image.setVisibility(View.VISIBLE);
holder.number.setVisibility(View.GONE);
} else if (item.imageResource == null) {
holder.number.setVisibility(View.VISIBLE);
holder.image.setVisibility(View.GONE);
} else {
holder.image.setImageResource(item.imageResource);
if (item.imageFilterColor == null) {
holder.image.setColorFilter(null);
} else {
holder.image.setColorFilter(item.imageFilterColor, PorterDuff.Mode.SRC_ATOP);
}
holder.image.setVisibility(View.VISIBLE);
holder.number.setVisibility(View.GONE);
List<Tag> tags = new ArrayList<>();
Bookmark bookmark = item.bookmark;
if (bookmark != null && !bookmark.tags.isEmpty() && showTags) {
for (int i = 0, bookmarkTags = bookmark.tags.size(); i < bookmarkTags; i++) {
Long tagId = bookmark.tags.get(i);
Tag tag = tagMap.get(tagId);
if (tag != null) {
tags.add(tag);
}
}
}
if (tags.isEmpty()) {
holder.tags.setVisibility(View.GONE);
} else {
holder.tags.setTags(tags);
holder.tags.setVisibility(View.VISIBLE);
}
}
}
use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.
the class BookmarkPresenter method predictQuranListAfterDeletion.
private BookmarkResult predictQuranListAfterDeletion(List<QuranRow> remove) {
if (cachedData != null) {
List<QuranRow> placeholder = new ArrayList<>(cachedData.getRows().size() - remove.size());
List<QuranRow> rows = cachedData.getRows();
List<Long> removedTags = new ArrayList<>();
for (int i = 0, rowsSize = rows.size(); i < rowsSize; i++) {
QuranRow row = rows.get(i);
if (!remove.contains(row)) {
placeholder.add(row);
}
}
for (int i = 0, removedSize = remove.size(); i < removedSize; i++) {
QuranRow row = remove.get(i);
if (row.isHeader() && row.tagId > 0) {
removedTags.add(row.tagId);
}
}
Map<Long, Tag> tagMap;
if (removedTags.isEmpty()) {
tagMap = cachedData.getTagMap();
} else {
tagMap = new HashMap<>(cachedData.getTagMap());
for (int i = 0, removedTagsSize = removedTags.size(); i < removedTagsSize; i++) {
Long tagId = removedTags.get(i);
tagMap.remove(tagId);
}
}
return new BookmarkResult(placeholder, tagMap);
}
return null;
}
use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.
the class BookmarkPresenter method getBookmarkRows.
private List<QuranRow> getBookmarkRows(BookmarkData data, boolean groupByTags) {
List<QuranRow> rows;
List<Tag> tags = data.getTags();
List<Bookmark> bookmarks = data.getBookmarks();
if (groupByTags) {
rows = getRowsSortedByTags(tags, bookmarks);
} else {
rows = getSortedRows(bookmarks);
}
List<RecentPage> recentPages = data.getRecentPages();
int size = recentPages.size();
if (size > 0) {
if (!showRecents) {
// only show the last bookmark if show recents is off
size = 1;
}
rows.add(0, quranRowFactory.fromRecentPageHeader(appContext, size));
for (int i = 0; i < size; i++) {
int page = recentPages.get(i).getPage();
if (page < Constants.PAGES_FIRST || page > totalPages) {
page = 1;
}
rows.add(i + 1, quranRowFactory.fromCurrentPage(appContext, page));
}
}
return rows;
}
use of com.quran.labs.androidquran.dao.Tag in project quran_android by quran.
the class BookmarkPresenter method getRowsSortedByTags.
private List<QuranRow> getRowsSortedByTags(List<Tag> tags, List<Bookmark> bookmarks) {
List<QuranRow> rows = new ArrayList<>();
// sort by tags, alphabetical
Map<Long, List<Bookmark>> tagsMapping = generateTagsMapping(tags, bookmarks);
for (int i = 0, tagsSize = tags.size(); i < tagsSize; i++) {
Tag tag = tags.get(i);
rows.add(quranRowFactory.fromTag(tag));
List<Bookmark> tagBookmarks = tagsMapping.get(tag.getId());
for (int j = 0, tagBookmarksSize = tagBookmarks.size(); j < tagBookmarksSize; j++) {
rows.add(quranRowFactory.fromBookmark(appContext, tagBookmarks.get(j), tag.getId()));
}
}
// add untagged bookmarks
List<Bookmark> untagged = tagsMapping.get(BOOKMARKS_WITHOUT_TAGS_ID);
if (untagged.size() > 0) {
rows.add(quranRowFactory.fromNotTaggedHeader(appContext));
for (int i = 0, untaggedSize = untagged.size(); i < untaggedSize; i++) {
rows.add(quranRowFactory.fromBookmark(appContext, untagged.get(i)));
}
}
return rows;
}
Aggregations