Ejemplo n.º 1
0
  private void uploadDB(String dbPath) throws Exception {
    final String dbName = AMUtil.getFilenameFromPath(dbPath);
    int cardId = addCardSet(dbName, "Import from AnyMemo");
    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(this, dbPath);
    CardDao cardDao = helper.getCardDao();
    List<Card> cards = cardDao.queryForAll();

    for (Card card : cards) {
      String question = card.getQuestion();
      String answer = card.getAnswer();
      addCard(cardId, question, answer);
    }
  }
Ejemplo n.º 2
0
 @Override
 public boolean equals(Object c) {
   Card card2 = (Card) c;
   return this.getId().equals(card2.getId());
 }
Ejemplo n.º 3
0
  public void convert(String src, String dest) throws Exception {
    new File(dest).delete();
    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(mContext, dest);
    try {
      final CardDao cardDao = helper.getCardDao();
      BufferedReader txtfile = new BufferedReader(new FileReader(src));
      String line;
      int count = 0;
      List<Card> cardList = new LinkedList<Card>();
      boolean isQ = false;
      StringBuffer qBuf = null;
      StringBuffer aBuf = null;
      while ((line = txtfile.readLine()) != null) {
        /* remove BOM */
        line = line.replace("\uFEFF", "");

        String head = "";
        if (line.length() >= 2) {
          head = line.substring(0, 2);
        }
        if (line.equals("")) {
          continue;
        } else if (head.equals("Q:")) {
          if (isQ == true) {
            /* next line */
            qBuf.append("<br />" + line.replaceAll("Q:\\s*", ""));
          } else {
            isQ = true;
            /* Save item when the Q is after A
             * because it is a new item */
            if (count != 0) {
              Card card = new Card();
              card.setQuestion(qBuf.toString());
              card.setAnswer(aBuf.toString());
              card.setOrdinal(count);
              card.setCategory(new Category());
              card.setLearningData(new LearningData());
              cardList.add(card);
            }
            count += 1;
            qBuf = new StringBuffer();
            qBuf.append(line.replaceAll("Q:\\s*", ""));
          }
        } else if (head.equals("A:")) {
          if (isQ == true) {
            isQ = false;
            aBuf = new StringBuffer();
            aBuf.append(line.replaceAll("A:\\s*", ""));
          } else {
            aBuf.append("<br />" + line.replaceAll("A:\\s*", ""));
          }
        } else {
          if (isQ) {
            qBuf.append("<br />" + line);
          } else {
            aBuf.append("<br />" + line);
          }
        }
      }
      /* Last item need to be added manually */
      count += 1;
      Card card = new Card();
      card.setQuestion(qBuf.toString());
      card.setAnswer(aBuf.toString());
      card.setOrdinal(count);
      card.setCategory(new Category());
      card.setLearningData(new LearningData());
      cardList.add(card);

      txtfile.close();
      cardDao.createCards(cardList);
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }