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);
}
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));
}
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;
}
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;
}
Aggregations