use of com.quran.labs.androidquran.dao.Bookmark 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.Bookmark 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.Bookmark 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;
}
use of com.quran.labs.androidquran.dao.Bookmark in project quran_android by quran.
the class AyahImageTrackerItem method onSetAyahBookmarks.
@Override
void onSetAyahBookmarks(@NonNull List<Bookmark> bookmarks) {
int highlighted = 0;
for (int i = 0, size = bookmarks.size(); i < size; i++) {
Bookmark bookmark = bookmarks.get(i);
if (bookmark.page == page) {
highlighted++;
ayahView.highlightAyah(bookmark.sura, bookmark.ayah, HighlightType.BOOKMARK);
}
}
if (highlighted > 0) {
ayahView.invalidate();
}
}
use of com.quran.labs.androidquran.dao.Bookmark in project quran_android by quran.
the class BookmarkModelTest method testBookmarkedAyahsOnPage.
@Test
public void testBookmarkedAyahsOnPage() {
List<Bookmark> bookmarks = new ArrayList<>(2);
bookmarks.add(new Bookmark(42, 46, 1, 502, System.currentTimeMillis(), Collections.singletonList(2L)));
bookmarks.add(new Bookmark(2, 2, 4, 2, System.currentTimeMillis() - 60000));
when(bookmarksAdapter.getBookmarkedAyahsOnPage(anyInt())).thenReturn(bookmarks);
Integer[][] inputs = new Integer[][] { new Integer[] { 42 }, new Integer[] { 42, 43 } };
int total = 0;
for (Integer[] input : inputs) {
TestObserver<List<Bookmark>> testObserver = new TestObserver<>();
model.getBookmarkedAyahsOnPageObservable(input).subscribe(testObserver);
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
testObserver.assertValueCount(input.length);
verify(bookmarksAdapter, times(input.length + total)).getBookmarkedAyahsOnPage(anyInt());
total += input.length;
}
}
Aggregations