Search in sources :

Example 6 with Bookmark

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);
        }
    }
}
Also used : JuzView(com.quran.labs.androidquran.widgets.JuzView) Bookmark(com.quran.labs.androidquran.dao.Bookmark) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.quran.labs.androidquran.dao.Tag)

Example 7 with Bookmark

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;
}
Also used : Bookmark(com.quran.labs.androidquran.dao.Bookmark) QuranRow(com.quran.labs.androidquran.ui.helpers.QuranRow) RecentPage(com.quran.labs.androidquran.dao.RecentPage) Tag(com.quran.labs.androidquran.dao.Tag) SuppressLint(android.annotation.SuppressLint)

Example 8 with Bookmark

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;
}
Also used : Bookmark(com.quran.labs.androidquran.dao.Bookmark) QuranRow(com.quran.labs.androidquran.ui.helpers.QuranRow) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.quran.labs.androidquran.dao.Tag) SuppressLint(android.annotation.SuppressLint)

Example 9 with Bookmark

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();
    }
}
Also used : Bookmark(com.quran.labs.androidquran.dao.Bookmark)

Example 10 with Bookmark

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;
    }
}
Also used : Bookmark(com.quran.labs.androidquran.dao.Bookmark) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Aggregations

Bookmark (com.quran.labs.androidquran.dao.Bookmark)12 ArrayList (java.util.ArrayList)8 List (java.util.List)6 SuppressLint (android.annotation.SuppressLint)4 Tag (com.quran.labs.androidquran.dao.Tag)4 QuranRow (com.quran.labs.androidquran.ui.helpers.QuranRow)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 MadaniPageProvider (com.quran.data.page.provider.madani.MadaniPageProvider)2 QuranInfo (com.quran.labs.androidquran.data.QuranInfo)2 QuranFileUtils (com.quran.labs.androidquran.util.QuranFileUtils)2 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 NonNull (android.support.annotation.NonNull)1 RecentPage (com.quran.labs.androidquran.dao.RecentPage)1 JuzView (com.quran.labs.androidquran.widgets.JuzView)1 TestObserver (io.reactivex.observers.TestObserver)1 HashSet (java.util.HashSet)1