Search in sources :

Example 1 with BookmarkResult

use of com.quran.labs.androidquran.model.bookmark.BookmarkResult in project quran_android by quran.

the class BookmarkPresenterTest method testBookmarkObservableAyahBookmarksGroupedByTag.

@Test
public void testBookmarkObservableAyahBookmarksGroupedByTag() {
    BookmarkModel model = new BookmarkModel(bookmarksAdapter, recentPageModel) {

        @Override
        public Single<BookmarkData> getBookmarkDataObservable(int sortOrder) {
            return Single.zip(Single.just(TAG_LIST), Single.just(AYAH_BOOKMARKS_LIST), Single.just(new ArrayList<>()), (Function3<List<Tag>, List<Bookmark>, List<RecentPage>, BookmarkData>) BookmarkData::new);
        }
    };
    BookmarkPresenter presenter = makeBookmarkPresenter(model);
    BookmarkResult result = getBookmarkResultByDateAndValidate(presenter, true);
    assertThat(result.getTagMap()).hasSize(2);
    // number of tags (or 1) for each bookmark, plus number of tags (headers), plus unsorted
    assertThat(result.getRows()).hasSize(AYAH_BOOKMARKS_ROW_COUNT_WHEN_GROUPED_BY_TAG + TAG_LIST.size() + 1);
}
Also used : BookmarkData(com.quran.labs.androidquran.dao.BookmarkData) BookmarkResult(com.quran.labs.androidquran.model.bookmark.BookmarkResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BookmarkModel(com.quran.labs.androidquran.model.bookmark.BookmarkModel) Test(org.junit.Test)

Example 2 with BookmarkResult

use of com.quran.labs.androidquran.model.bookmark.BookmarkResult in project quran_android by quran.

the class BookmarkPresenterTest method testBookmarkObservableMixedBookmarksByDate.

@Test
public void testBookmarkObservableMixedBookmarksByDate() {
    BookmarkModel model = new BookmarkModel(bookmarksAdapter, recentPageModel) {

        @Override
        public Single<BookmarkData> getBookmarkDataObservable(int sortOrder) {
            return Single.zip(Single.just(new ArrayList<>()), Single.just(MIXED_BOOKMARKS_LIST), Single.just(new ArrayList<>()), (Function3<List<Tag>, List<Bookmark>, List<RecentPage>, BookmarkData>) BookmarkData::new);
        }
    };
    BookmarkPresenter presenter = makeBookmarkPresenter(model);
    BookmarkResult result = getBookmarkResultByDateAndValidate(presenter, false);
    assertThat(result.getTagMap()).isEmpty();
    // 1 for "page bookmarks" and 1 for "ayah bookmarks"
    assertThat(result.getRows()).hasSize(MIXED_BOOKMARKS_LIST.size() + 2);
}
Also used : BookmarkData(com.quran.labs.androidquran.dao.BookmarkData) BookmarkResult(com.quran.labs.androidquran.model.bookmark.BookmarkResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BookmarkModel(com.quran.labs.androidquran.model.bookmark.BookmarkModel) Test(org.junit.Test)

Example 3 with BookmarkResult

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

Example 4 with BookmarkResult

use of com.quran.labs.androidquran.model.bookmark.BookmarkResult in project quran_android by quran.

the class BookmarkPresenterTest method testBookmarkObservableAyahBookmarksByDate.

@Test
public void testBookmarkObservableAyahBookmarksByDate() {
    BookmarkModel model = new BookmarkModel(bookmarksAdapter, recentPageModel) {

        @Override
        public Single<BookmarkData> getBookmarkDataObservable(int sortOrder) {
            return Single.zip(Single.just(new ArrayList<>()), Single.just(AYAH_BOOKMARKS_LIST), Single.just(new ArrayList<>()), (Function3<List<Tag>, List<Bookmark>, List<RecentPage>, BookmarkData>) BookmarkData::new);
        }
    };
    BookmarkPresenter presenter = makeBookmarkPresenter(model);
    BookmarkResult result = getBookmarkResultByDateAndValidate(presenter, false);
    assertThat(result.getTagMap()).isEmpty();
    // 1 for the header, plus one row per item
    assertThat(result.getRows()).hasSize(AYAH_BOOKMARKS_LIST.size() + 1);
}
Also used : BookmarkData(com.quran.labs.androidquran.dao.BookmarkData) BookmarkResult(com.quran.labs.androidquran.model.bookmark.BookmarkResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BookmarkModel(com.quran.labs.androidquran.model.bookmark.BookmarkModel) Test(org.junit.Test)

Example 5 with BookmarkResult

use of com.quran.labs.androidquran.model.bookmark.BookmarkResult in project quran_android by quran.

the class BookmarkPresenterTest method testBookmarkObservableMixedBookmarksGroupedByTagWithRecentPage.

@Test
public void testBookmarkObservableMixedBookmarksGroupedByTagWithRecentPage() {
    BookmarkModel model = new BookmarkModel(bookmarksAdapter, recentPageModel) {

        @Override
        public Single<BookmarkData> getBookmarkDataObservable(int sortOrder) {
            return Single.zip(Single.just(TAG_LIST), Single.just(MIXED_BOOKMARKS_LIST), Single.just(RECENTS_LIST), BookmarkData::new);
        }
    };
    BookmarkPresenter presenter = makeBookmarkPresenter(model);
    BookmarkResult result = getBookmarkResultByDateAndValidate(presenter, true);
    assertThat(result.getTagMap()).hasSize(2);
    // number of tags (or 1) for each bookmark, plus number of tags (headers), plus unsorted, plus
    // current page header, plus current page
    assertThat(result.getRows()).hasSize(MIXED_BOOKMARKS_ROW_COUNT_WHEN_GROUPED_BY_TAG + TAG_LIST.size() + 1 + 2);
}
Also used : BookmarkData(com.quran.labs.androidquran.dao.BookmarkData) BookmarkResult(com.quran.labs.androidquran.model.bookmark.BookmarkResult) BookmarkModel(com.quran.labs.androidquran.model.bookmark.BookmarkModel) Test(org.junit.Test)

Aggregations

BookmarkResult (com.quran.labs.androidquran.model.bookmark.BookmarkResult)7 BookmarkData (com.quran.labs.androidquran.dao.BookmarkData)6 BookmarkModel (com.quran.labs.androidquran.model.bookmark.BookmarkModel)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 SuppressLint (android.annotation.SuppressLint)1 Tag (com.quran.labs.androidquran.dao.Tag)1 QuranRow (com.quran.labs.androidquran.ui.helpers.QuranRow)1