Search in sources :

Example 91 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class LearnQueueManager method refill.

private synchronized void refill() {
    final AnyMemoDBOpenHelper dbOpenHelper = AnyMemoDBOpenHelperManager.getHelper(context, dbPath);
    final CardDao cardDao = dbOpenHelper.getCardDao();
    dumpLearnQueue();
    List<Card> exclusionList = new ArrayList<Card>(learnQueue.size() + dirtyCache.size());
    exclusionList.addAll(learnQueue);
    exclusionList.addAll(dirtyCache);
    try {
        if (newCache.size() == 0) {
            List<Card> cs = cardDao.getNewCards(filterCategory, exclusionList, cacheSize);
            if (cs.size() > 0) {
                newCache.addAll(cs);
            }
        }
        if (reviewCache.size() == 0) {
            List<Card> cs = cardDao.getCardsForReview(filterCategory, exclusionList, cacheSize, reviewOrdering);
            if (cs.size() > 0) {
                reviewCache.addAll(cs);
            }
        }
        while (learnQueue.size() < learnQueueSize && !reviewCache.isEmpty()) {
            learnQueue.add(reviewCache.get(0));
            reviewCache.remove(0);
        }
        while (learnQueue.size() < learnQueueSize && !newCache.isEmpty()) {
            learnQueue.add(newCache.get(0));
            newCache.remove(0);
        }
    } finally {
        AnyMemoDBOpenHelperManager.releaseHelper(dbOpenHelper);
    }
    flushDirtyCache();
    dumpLearnQueue();
}
Also used : AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) ArrayList(java.util.ArrayList) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 92 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class LearnQueueManager method dumpLearnQueue.

private void dumpLearnQueue() {
    StringBuilder sb = new StringBuilder();
    sb.append("LearnQueue : card ids[");
    for (Card c : learnQueue) {
        sb.append("" + c.getId() + ", ");
    }
    sb.append("]\n");
    // sb.append("LearnQueue: card learning data[");
    // for (Card c : learnQueue) {
    // sb.append("" + c.getLearningData() + "\n ");
    // }
    // sb.append("]\n");
    sb.append("Dirty cache: card ids[");
    for (Card c : dirtyCache) {
        sb.append("" + c.getId() + ", ");
    }
    sb.append("]\n");
    // sb.append("Dirty cache: card learning data[");
    // for (Card c : dirtyCache) {
    // sb.append("" + c.getLearningData() + "\n ");
    // }
    // sb.append("]\n");
    Log.v(TAG, sb.toString());
}
Also used : Card(org.liberty.android.fantastischmemo.entity.Card)

Example 93 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class LearnQueueManager method dequeuePosition.

@Override
public synchronized Card dequeuePosition(int cardId) {
    position(cardId);
    if (!learnQueue.isEmpty()) {
        Card c = learnQueue.get(0);
        Log.d(TAG, "Dequeue card: " + c.getId());
        return c;
    } else {
        return null;
    }
}
Also used : Card(org.liberty.android.fantastischmemo.entity.Card)

Example 94 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class ShareScreen method onClick.

@Override
public void onClick(View v) {
    try {
        String dbpath = dbnameView.getText().toString();
        Log.v(TAG, dbpath);
        if (v == saveButton || v == savePrevButton) {
            AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(this, dbpath);
            CardDao cardDao = helper.getCardDao();
            try {
                Card card = new Card();
                card.setQuestion(questionView.getText().toString());
                card.setAnswer(answerView.getText().toString());
                card.setNote(noteView.getText().toString());
                card.setCategory(new Category());
                card.setLearningData(new LearningData());
                cardDao.createCard(card);
                if (v == savePrevButton) {
                    Intent myIntent = new Intent(this, PreviewEditActivity.class);
                    /* This should be the newly created id */
                    myIntent.putExtra("id", card.getId());
                    myIntent.putExtra(PreviewEditActivity.EXTRA_DBPATH, dbpath);
                    startActivity(myIntent);
                }
                finish();
            } finally {
                AnyMemoDBOpenHelperManager.releaseHelper(helper);
            }
        } else if (v == cancelButton) {
            finish();
        } else if (v == dbnameView) {
            Intent myIntent = new Intent(this, FileBrowserActivity.class);
            myIntent.putExtra(FileBrowserActivity.EXTRA_FILE_EXTENSIONS, ".db");
            startActivityForResult(myIntent, ACTIVITY_FB);
        }
    } catch (Exception e) {
        AMGUIUtility.displayError(this, getString(R.string.error_text), "", e);
    }
}
Also used : AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) Category(org.liberty.android.fantastischmemo.entity.Category) Intent(android.content.Intent) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 95 with Card

use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.

the class CardWrapperListLoader method dbLoadInBackground.

@Override
protected List<CardWrapper> dbLoadInBackground() {
    CardDao cardDao = dbOpenHelper.getCardDao();
    List<CardWrapper> cardWrappers = new ArrayList<CardWrapper>((int) cardDao.countOf());
    for (Card card : cardDao.getAllCards(null)) {
        cardWrappers.add(new CardWrapper(card, initialAnswerVisible));
    }
    return cardWrappers;
}
Also used : ArrayList(java.util.ArrayList) CardWrapper(org.liberty.android.fantastischmemo.ui.CardListActivity.CardWrapper) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card)

Aggregations

Card (org.liberty.android.fantastischmemo.entity.Card)95 CardDao (org.liberty.android.fantastischmemo.dao.CardDao)61 SmallTest (android.support.test.filters.SmallTest)43 Test (org.junit.Test)43 AbstractExistingDBTest (org.liberty.android.fantastischmemo.test.AbstractExistingDBTest)41 Category (org.liberty.android.fantastischmemo.entity.Category)30 AnyMemoDBOpenHelper (org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper)28 LearningData (org.liberty.android.fantastischmemo.entity.LearningData)25 CategoryDao (org.liberty.android.fantastischmemo.dao.CategoryDao)20 LearningDataDao (org.liberty.android.fantastischmemo.dao.LearningDataDao)13 File (java.io.File)12 ArrayList (java.util.ArrayList)11 SQLException (java.sql.SQLException)9 QueueManager (org.liberty.android.fantastischmemo.queue.QueueManager)9 IOException (java.io.IOException)6 Date (java.util.Date)6 LearnQueueManager (org.liberty.android.fantastischmemo.queue.LearnQueueManager)6 URL (java.net.URL)5 FileWriter (java.io.FileWriter)4 Scheduler (org.liberty.android.fantastischmemo.scheduler.Scheduler)4