Search in sources :

Example 1 with RecentPage

use of com.quran.labs.androidquran.dao.RecentPage in project quran_android by quran.

the class RecentPageModelTest method testUpdateLatestPageWithSlowRecents.

@Test
public void testUpdateLatestPageWithSlowRecents() {
    final TestScheduler testScheduler = new TestScheduler();
    RecentPageModel recentPageModel = new RecentPageModel(bookmarksAdapter) {

        @Override
        Single<List<RecentPage>> getRecentPagesObservable() {
            // testScheduler simulates the passing of 5 seconds (the timer time).
            return Single.timer(5, TimeUnit.SECONDS, testScheduler).map(aLong -> SAMPLE_RECENT_PAGES).subscribeOn(Schedulers.trampoline());
        }
    };
    TestObserver<Integer> testObserver = new TestObserver<>();
    recentPageModel.getLatestPageObservable().take(2).subscribe(testObserver);
    // write before the mock data from getRecentPagesObservable comes back
    recentPageModel.updateLatestPage(51);
    // now let's pretend the recent page came back - we expect that this page should be ignored.
    testScheduler.advanceTimeBy(5, TimeUnit.SECONDS);
    // and that another page afterwards was written
    recentPageModel.updateLatestPage(23);
    testObserver.awaitTerminalEvent();
    testObserver.assertValues(51, 23);
}
Also used : BeforeClass(org.junit.BeforeClass) RxAndroidPlugins(io.reactivex.android.plugins.RxAndroidPlugins) Mock(org.mockito.Mock) Constants(com.quran.labs.androidquran.data.Constants) BookmarksDBAdapter(com.quran.labs.androidquran.database.BookmarksDBAdapter) Test(org.junit.Test) TestObserver(io.reactivex.observers.TestObserver) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Single(io.reactivex.Single) RecentPage(com.quran.labs.androidquran.dao.RecentPage) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) MockitoAnnotations(org.mockito.MockitoAnnotations) List(java.util.List) Matchers.anyInt(org.mockito.Matchers.anyInt) Schedulers(io.reactivex.schedulers.Schedulers) TestScheduler(io.reactivex.schedulers.TestScheduler) Before(org.junit.Before) ArrayList(java.util.ArrayList) List(java.util.List) TestScheduler(io.reactivex.schedulers.TestScheduler) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 2 with RecentPage

use of com.quran.labs.androidquran.dao.RecentPage in project quran_android by quran.

the class RecentPageModelTest method setup.

@BeforeClass
public static void setup() {
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.io());
    // sample recent pages
    long timestamp = System.currentTimeMillis();
    SAMPLE_RECENT_PAGES.add(new RecentPage(49, timestamp));
    SAMPLE_RECENT_PAGES.add(new RecentPage(100, timestamp - 10000));
}
Also used : RecentPage(com.quran.labs.androidquran.dao.RecentPage) BeforeClass(org.junit.BeforeClass)

Example 3 with RecentPage

use of com.quran.labs.androidquran.dao.RecentPage 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 4 with RecentPage

use of com.quran.labs.androidquran.dao.RecentPage in project quran_android by quran.

the class BookmarksDBAdapter method getRecentPages.

@NonNull
public List<RecentPage> getRecentPages() {
    List<RecentPage> recents = new ArrayList<>();
    Cursor cursor = null;
    try {
        cursor = mDb.query(LastPagesTable.TABLE_NAME, null, null, null, null, null, LastPagesTable.ADDED_DATE + " DESC");
        if (cursor != null) {
            while (cursor.moveToNext()) {
                recents.add(new RecentPage(cursor.getInt(1), cursor.getLong(2)));
            }
        }
    } finally {
        DatabaseUtils.closeCursor(cursor);
    }
    return recents;
}
Also used : RecentPage(com.quran.labs.androidquran.dao.RecentPage) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) NonNull(android.support.annotation.NonNull)

Aggregations

RecentPage (com.quran.labs.androidquran.dao.RecentPage)4 ArrayList (java.util.ArrayList)2 BeforeClass (org.junit.BeforeClass)2 SuppressLint (android.annotation.SuppressLint)1 Cursor (android.database.Cursor)1 NonNull (android.support.annotation.NonNull)1 Bookmark (com.quran.labs.androidquran.dao.Bookmark)1 Tag (com.quran.labs.androidquran.dao.Tag)1 Constants (com.quran.labs.androidquran.data.Constants)1 BookmarksDBAdapter (com.quran.labs.androidquran.database.BookmarksDBAdapter)1 QuranRow (com.quran.labs.androidquran.ui.helpers.QuranRow)1 Single (io.reactivex.Single)1 RxAndroidPlugins (io.reactivex.android.plugins.RxAndroidPlugins)1 TestObserver (io.reactivex.observers.TestObserver)1 Schedulers (io.reactivex.schedulers.Schedulers)1 TestScheduler (io.reactivex.schedulers.TestScheduler)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Before (org.junit.Before)1 Test (org.junit.Test)1