Пример #1
0
  @Override
  public List<Word> getWords() {
    List<Word> wordList = new ArrayList<Word>();
    Db_Help dbhelper = new Db_Help(mContext);
    String query = "SELECT _id,vocab,pronunciation,meaning FROM tb_words;";
    ArrayList datatable = new ArrayList();
    try {
      datatable = dbhelper.getDataTable(query);

      int i = 0;
      while (datatable.size() > i) {
        HashMap tablerow = new HashMap();
        tablerow = (HashMap) datatable.get(i);
        Word obj =
            new Word(
                tablerow.get(tbWord.id).toString(),
                tablerow.get(tbWord.vocab).toString(),
                tablerow.get(tbWord.prounuciation).toString(),
                tablerow.get(tbWord.meaning).toString());

        wordList.add(obj);
        i++;
      }

    } catch (SQLiteException e) {
      Log.e("SQLITE_Exception", e.getMessage());
    }
    return wordList;
  }
Пример #2
0
 @Override
 public void updateWord(Word word) {
   Db_Help dbhelper = new Db_Help(mContext);
   String query =
       "UPDATE tb_words SET vocab='"
           + word.getVocab()
           + "'"
           + ",meaning='"
           + word.getMeaning()
           + "',pronunciation='"
           + word.getPronunciation()
           + "' WHERE _id='"
           + word.getId()
           + "'";
   Log.e("DB_QUERY", query);
   dbhelper.executeQuery(query);
 }
Пример #3
0
  @Override
  public void insertWord(Word word) {
    Db_Help dbhelper = new Db_Help(mContext);
    Common_helper common_helper = new Common_helper(mContext);

    String query =
        "INSERT INTO tb_words VALUES ('"
            + common_helper.getGUID()
            + "',"
            + "'"
            + word.getVocab()
            + "',"
            + "'"
            + word.getPronunciation()
            + "',"
            + "'"
            + word.getMeaning()
            + "');";
    Log.e("DB_QUERY", query);
    dbhelper.executeQuery(query);
  }
Пример #4
0
  @Override
  public List<Word> getShuffleWords() {
    Random rnd = new Random();
    List<Word> wordList = new ArrayList<Word>();
    Db_Help dbhelper = new Db_Help(mContext);
    String query = "SELECT _id,vocab,pronunciation,meaning FROM tb_words;";
    ArrayList datatable = new ArrayList();
    try {
      datatable = dbhelper.getDataTable(query);

      int i = 0;
      while (datatable.size() > i) {
        HashMap tablerow = new HashMap();
        tablerow = (HashMap) datatable.get(i);
        Word obj =
            new Word(
                tablerow.get(tbWord.id).toString(),
                tablerow.get(tbWord.vocab).toString(),
                tablerow.get(tbWord.prounuciation).toString(),
                tablerow.get(tbWord.meaning).toString());

        wordList.add(obj);
        i++;
      }

    } catch (SQLiteException e) {
      Log.e("SQLITE_Exception", e.getMessage());
    }

    for (int i = wordList.size() - 1; i > 0; i--) {
      int index = rnd.nextInt(i + 1);
      Log.e("Random", String.valueOf(index));
      Word w = wordList.get(index);
      wordList.set(index, wordList.get(i));
      wordList.set(i, w);
    }

    return wordList;
  }
Пример #5
0
  @Override
  public Word getWord(Word word) {
    Db_Help dbhelper = new Db_Help(mContext);
    String query =
        "SELECT _id,vocab,pronunciation,meaning FROM tb_words WHERE _id='" + word.getId() + "'";
    Word result = new Word();
    ArrayList datarow = new ArrayList();
    datarow = dbhelper.getDataRow(query);

    if (datarow.size() != 0) {
      HashMap tablerow = new HashMap();
      tablerow = (HashMap) datarow.get(0);
      result =
          new Word(
              tablerow.get(tbWord.id).toString(),
              tablerow.get(tbWord.vocab).toString(),
              tablerow.get(tbWord.prounuciation).toString(),
              tablerow.get(tbWord.meaning).toString());
    }

    return result;
  }
Пример #6
0
 @Override
 public void deleteAllWord() {
   Db_Help dbhelper = new Db_Help(mContext);
   String query = "DELETE FROM tb_words; ";
   dbhelper.executeQuery(query);
 }
Пример #7
0
 @Override
 public void deleteWord(Word word) {
   Db_Help dbhelper = new Db_Help(mContext);
   String query = "DELETE FROM tb_words where _id='" + word.getId() + "'";
   dbhelper.executeQuery(query);
 }