use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.
the class RecentListFragment method loadRecentItemsWithDetails.
private List<RecentItem> loadRecentItemsWithDetails() {
final List<RecentItem> ril = loadRecentItemsWithName();
for (final RecentItem ri : ril) {
try {
Context context = getContext();
if (context == null) {
break;
}
AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), ri.dbPath);
CardDao dao = helper.getCardDao();
ri.dbInfo = context.getString(R.string.stat_total) + dao.getTotalCount(null) + " " + getContext().getString(R.string.stat_new) + dao.getNewCardCount(null) + " " + getContext().getString(R.string.stat_scheduled) + dao.getScheduledCardCount(null);
ril.set(ri.index, ri);
AnyMemoDBOpenHelperManager.releaseHelper(helper);
} catch (Exception e) {
Log.e(TAG, "Recent list throws exception (Usually can be safely ignored)", e);
}
}
return ril;
}
use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.
the class DatabaseUtil method mergeDatabases.
public void mergeDatabases(String destPath, String srcPath) throws Exception {
AnyMemoDBOpenHelper destHelper = AnyMemoDBOpenHelperManager.getHelper(mContext, destPath);
AnyMemoDBOpenHelper srcHelper = AnyMemoDBOpenHelperManager.getHelper(mContext, srcPath);
final CardDao cardDaoDest = destHelper.getCardDao();
final LearningDataDao learningDataDaoSrc = srcHelper.getLearningDataDao();
final CategoryDao categoryDaoSrc = srcHelper.getCategoryDao();
final CardDao cardDaoSrc = srcHelper.getCardDao();
final List<Card> srcCards = cardDaoSrc.queryForAll();
cardDaoSrc.callBatchTasks(new Callable<Void>() {
public Void call() throws Exception {
for (Card c : srcCards) {
// Make sure to create a new ordinal
c.setOrdinal(null);
learningDataDaoSrc.refresh(c.getLearningData());
categoryDaoSrc.refresh(c.getCategory());
}
return null;
}
});
cardDaoDest.createCards(srcCards);
System.out.println("DatabaseUtils release destPath");
AnyMemoDBOpenHelperManager.releaseHelper(destHelper);
System.out.println("DatabaseUtils release srcPath");
AnyMemoDBOpenHelperManager.releaseHelper(srcHelper);
}
use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.
the class CardDaoTest method testGetCardsByCategory.
@SmallTest
@Test
public void testGetCardsByCategory() throws Exception {
CardDao cardDao = helper.getCardDao();
CategoryDao categoryDao = helper.getCategoryDao();
setupThreeCategories();
Category filterCategory1 = categoryDao.createOrReturn("My category");
// If category specified is null, return all cards up to limit
List<Card> cards1 = cardDao.getCardsByCategory(null, false, 50);
assertEquals(28, cards1.size());
// No category specified but with limit
List<Card> cards2 = cardDao.getCardsByCategory(null, false, 10);
assertEquals(10, cards2.size());
// Get by category
List<Card> cards3 = cardDao.getCardsByCategory(filterCategory1, false, 50);
assertEquals(3, cards3.size());
// Get by category with limit
List<Card> cards4 = cardDao.getCardsByCategory(filterCategory1, false, 2);
assertEquals(2, cards4.size());
// Random cards shouldn't affect number of cards to get
List<Card> cards5 = cardDao.getCardsByCategory(filterCategory1, true, 50);
assertEquals(3, cards5.size());
}
use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.
the class CardDaoTest method testGetCardsByOrdinalAndSize.
@SmallTest
@Test
public void testGetCardsByOrdinalAndSize() throws Exception {
CardDao cardDao = helper.getCardDao();
// Card ordianl 1 to 10
List<Card> cards1 = cardDao.getCardsByOrdinalAndSize(1, 10);
assertEquals(10, (int) cards1.size());
assertEquals(1, (int) cards1.get(0).getOrdinal());
assertEquals(10, (int) cards1.get(9).getOrdinal());
// Card orgdinal 20 to 28
List<Card> cards2 = cardDao.getCardsByOrdinalAndSize(20, 10);
assertEquals(9, (int) cards2.size());
assertEquals(20, (int) cards2.get(0).getOrdinal());
assertEquals(28, (int) cards2.get(8).getOrdinal());
// Get nothing
List<Card> cards3 = cardDao.getCardsByOrdinalAndSize(31, 10);
assertEquals(9, (int) cards2.size());
assertEquals(0, (int) cards3.size());
}
use of org.liberty.android.fantastischmemo.dao.CardDao in project AnyMemo by helloworld1.
the class CardDaoTest method setupThreeCategories.
/*
* Card with "My Category" in ID 2, 5, 8
*/
private void setupThreeCategories() throws SQLException {
CardDao cardDao = helper.getCardDao();
CategoryDao categoryDao = helper.getCategoryDao();
Card c = cardDao.queryForId(2);
Category ct = new Category();
ct.setName("My category");
categoryDao.create(ct);
c.setCategory(ct);
cardDao.update(c);
c = cardDao.queryForId(5);
c.setCategory(ct);
cardDao.update(c);
c = cardDao.queryForId(8);
c.setCategory(ct);
cardDao.update(c);
}
Aggregations