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