use of com.quran.labs.androidquran.dao.Bookmark in project quran_android by quran.
the class ArabicDatabaseUtilsTest method testHydrateAyahText.
@Test
public void testHydrateAyahText() {
ArabicDatabaseUtils arabicDatabaseUtils = new ArabicDatabaseUtils(context, new QuranInfo(new MadaniPageProvider()), mock(QuranFileUtils.class)) {
@Override
DatabaseHandler getArabicDatabaseHandler() {
return arabicHandler;
}
@Override
Map<Integer, String> getAyahTextForAyat(List<Integer> ayat) {
Map<Integer, String> result = new HashMap<>();
for (Integer ayahId : ayat) {
result.put(ayahId, "verse " + ayahId);
}
return result;
}
};
List<Bookmark> bookmarks = new ArrayList<>(3);
bookmarks.add(new Bookmark(1, 1, 1, 1));
bookmarks.add(new Bookmark(2, null, null, 3));
bookmarks.add(new Bookmark(3, 114, 6, 604));
List<Bookmark> result = arabicDatabaseUtils.hydrateAyahText(bookmarks);
assertThat(result).hasSize(3);
assertThat(result.get(0)).isInstanceOf(BookmarkWithAyahText.class);
assertThat(result.get(1)).isNotInstanceOf(BookmarkWithAyahText.class);
assertThat(result.get(2)).isInstanceOf(BookmarkWithAyahText.class);
assertThat(result.get(0).getAyahText()).isNotEmpty();
assertThat(result.get(1).getAyahText()).isNull();
assertThat(result.get(0).getAyahText()).isNotEmpty();
assertThat(result).isNotSameAs(bookmarks);
}
use of com.quran.labs.androidquran.dao.Bookmark in project quran_android by quran.
the class BookmarksDBAdapter method importBookmarks.
public boolean importBookmarks(BookmarkData data) {
boolean result = true;
mDb.beginTransaction();
try {
mDb.delete(BookmarksTable.TABLE_NAME, null, null);
mDb.delete(BookmarkTagTable.TABLE_NAME, null, null);
mDb.delete(TagsTable.TABLE_NAME, null, null);
ContentValues values = new ContentValues();
List<Tag> tags = data.getTags();
int tagSize = tags.size();
Timber.d("importing %d tags...", tagSize);
for (int i = 0; i < tagSize; i++) {
Tag tag = tags.get(i);
values.clear();
values.put(TagsTable.NAME, tag.getName());
values.put(TagsTable.ID, tag.getId());
mDb.insert(TagsTable.TABLE_NAME, null, values);
}
List<Bookmark> bookmarks = data.getBookmarks();
int bookmarkSize = bookmarks.size();
Timber.d("importing %d bookmarks...", bookmarkSize);
for (int i = 0; i < bookmarkSize; i++) {
Bookmark bookmark = bookmarks.get(i);
values.clear();
values.put(BookmarksTable.ID, bookmark.id);
values.put(BookmarksTable.SURA, bookmark.sura);
values.put(BookmarksTable.AYAH, bookmark.ayah);
values.put(BookmarksTable.PAGE, bookmark.page);
values.put(BookmarksTable.ADDED_DATE, bookmark.timestamp);
mDb.insert(BookmarksTable.TABLE_NAME, null, values);
List<Long> tagIds = bookmark.tags;
for (int t = 0; t < tagIds.size(); t++) {
values.clear();
values.put(BookmarkTagTable.BOOKMARK_ID, bookmark.id);
values.put(BookmarkTagTable.TAG_ID, tagIds.get(t));
mDb.insert(BookmarkTagTable.TABLE_NAME, null, values);
}
}
Timber.d("import successful!");
mDb.setTransactionSuccessful();
} catch (Exception e) {
Timber.e(e, "Failed to import data");
result = false;
} finally {
mDb.endTransaction();
}
return result;
}
Aggregations