Esempio n. 1
0
  // Add Favourites
  public void addFavouriteVerse(MorningWatchBO verse, String param) {

    ContentValues values = new ContentValues();

    values.put("BibleVerse", verse.getTitle());
    values.put("Description", verse.getDescription());
    values.put("Url", verse.getLink());
    values.put("Entry_Date", verse.getDate());
    values.put("Favourites", param);

    if (doesVerseExists(getTodayDate())) {
      // Inserting Records
      db.updateWithOnConflict(
          tableName,
          values,
          " Entry_Date" + " = '" + verse.getDate() + "'",
          null,
          SQLiteDatabase.CONFLICT_REPLACE);
    } else {
      db.insert(tableName, null, values);
    }
    /*
    if(doesVerseExists(getTodayDate())){
    	db.delete(tableName, "Entry_Date = '"+verse.getDate()+"'", null);
    	db.insert(tableName, null, values);
    }*/

    db.close(); // Closing database connection
  }
Esempio n. 2
0
  // Gets Todays Verse
  public MorningWatchBO getTodayVerse() {
    SQLiteDatabase db = this.getReadableDatabase();
    // Gets the verse for today
    Cursor cursor =
        db.query(
            tableName,
            new String[] {"BibleVerse", "Description", "Url", "Entry_Date", "Favourites"},
            "Entry_Date" + "='" + getTodayDate() + "'",
            null,
            null,
            null,
            null,
            null);

    MorningWatchBO morningWatchBO = new MorningWatchBO();

    if (cursor != null) cursor.moveToFirst();

    System.err.println("CURSOR SIZE " + cursor.getCount());

    if (cursor.getCount() > 0) {

      morningWatchBO.setTitle(cursor.getString(0));
      morningWatchBO.setDescription(cursor.getString(1));
      morningWatchBO.setLink(cursor.getString(2));
      morningWatchBO.setDate(cursor.getString(3));
      morningWatchBO.setFavourite(cursor.getString(4));
    }
    return morningWatchBO;
  }
Esempio n. 3
0
  // Getting all verses
  public List<MorningWatchBO> getAllVersesForWeek() {
    List<MorningWatchBO> verses = new ArrayList<MorningWatchBO>();
    SQLiteDatabase db = this.getReadableDatabase();
    // Returns all verses for the week
    // String query = "Select * from " +tableName+" where Entry_Date >= (select
    // strftime('%Y-%m-%d',datetime('now','-1 day' ))) ORDER BY Entry_Date ASC";
    Cursor cursor =
        db.query(
            tableName,
            null,
            "Entry_Date >= (select strftime('%Y-%m-%d',datetime('now','-7 day' )))",
            null,
            null,
            null,
            "Entry_Date ASC");
    // Cursor  cursor = db.query(tableName, null, null, null, null, null, null);
    // Cursor  cursor = db.rawQuery(query,null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
      do {
        MorningWatchBO morningWatchBO = new MorningWatchBO();

        morningWatchBO.setTitle(cursor.getString(1));
        morningWatchBO.setDescription(cursor.getString(2));
        morningWatchBO.setLink(cursor.getString(3));
        morningWatchBO.setDate(cursor.getString(4));
        morningWatchBO.setFavourite(cursor.getString(5));

        // Adding verses to list
        verses.add(morningWatchBO);
      } while (cursor.moveToNext());
    }
    return verses;
  }
Esempio n. 4
0
  // Getting all favourite verses
  public List<MorningWatchBO> getFavouriteVerses() {
    List<MorningWatchBO> verses = new ArrayList<MorningWatchBO>();
    SQLiteDatabase db = this.getReadableDatabase();
    String query = "SELECT  * FROM " + tableName + " where Favourites = 'Y'";
    Cursor cursor = db.rawQuery(query, null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
      do {
        MorningWatchBO morningWatchBO = new MorningWatchBO();

        morningWatchBO.setTitle(cursor.getString(1));
        morningWatchBO.setDescription(cursor.getString(2));
        morningWatchBO.setLink(cursor.getString(3));
        morningWatchBO.setDate(cursor.getString(4));
        morningWatchBO.setFavourite(cursor.getString(5));

        // Adding verses to list
        verses.add(morningWatchBO);
      } while (cursor.moveToNext());
    }
    return verses;
  }