Search in sources :

Example 11 with Bookmark

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);
}
Also used : MadaniPageProvider(com.quran.data.page.provider.madani.MadaniPageProvider) Bookmark(com.quran.labs.androidquran.dao.Bookmark) HashMap(java.util.HashMap) QuranInfo(com.quran.labs.androidquran.data.QuranInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) QuranFileUtils(com.quran.labs.androidquran.util.QuranFileUtils) Test(org.junit.Test)

Example 12 with Bookmark

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

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