コード例 #1
0
ファイル: PEpisode.java プロジェクト: jrafaelm/SeriesManager
  public Episode searchEpisode(Serie serie) {
    Cursor c = getCursor();

    Episode episode = new Episode();
    if (c.moveToFirst()) {

      int idxName = c.getColumnIndex(Episodes.NAME);
      int idxId = c.getColumnIndex(Episodes.PK_ID);
      int idxSeason = c.getColumnIndex(Episodes.SEASON);
      int idxEpisode = c.getColumnIndex(Episodes.NUMBER);
      int idxIdSerie = c.getColumnIndex(Episodes.ID_SERIE);

      do {
        if (serie.getId() == c.getLong(idxIdSerie)
            && serie.getSeason().intValue() == c.getInt(idxSeason)
            && serie.getEpisode().intValue() == c.getInt(idxEpisode)) {
          episode.setName(c.getString(idxName));
          episode.setId(c.getLong(idxId));
          episode.setSeason(c.getInt(idxSeason));
          episode.setNumber(c.getInt(idxEpisode));
          break;
        }
      } while (c.moveToNext());
    }
    c.close();
    super.close();
    return episode;
  }
コード例 #2
0
ファイル: PEpisode.java プロジェクト: jrafaelm/SeriesManager
  public ArrayList<Episode> listBySerieAndSeason(Serie serie) {
    Cursor c = getCursor();
    ArrayList<Episode> episodes = new ArrayList<Episode>();
    if (c.moveToFirst()) {

      int idxName = c.getColumnIndex(Episodes.NAME);
      int idxId = c.getColumnIndex(Episodes.PK_ID);
      int idxSeason = c.getColumnIndex(Episodes.SEASON);
      int idxEpisode = c.getColumnIndex(Episodes.NUMBER);
      int idxIdSerie = c.getColumnIndex(Episodes.ID_SERIE);

      do {
        if (serie.getId() == c.getLong(idxIdSerie)
            && serie.getSeason().intValue() == c.getInt(idxSeason)) {
          Episode episode = new Episode();
          episode.setName(c.getString(idxName));
          episode.setId(c.getLong(idxId));
          episode.setSeason(c.getInt(idxSeason));
          episode.setNumber(c.getInt(idxEpisode));
          episodes.add(episode);
        }
      } while (c.moveToNext());
    }
    c.close();
    super.close();
    return episodes;
  }
コード例 #3
0
ファイル: PEpisode.java プロジェクト: jrafaelm/SeriesManager
  public void addEpisodes(Serie serie) {
    try {
      super.open();
      if (serie.getEpisodes() != null) {
        for (Episode episode : serie.getEpisodes()) {
          ContentValues values = new ContentValues();

          values.put("id_serie", serie.getId());
          values.put("name", episode.getName());
          values.put("season", episode.getSeason());
          values.put("number", episode.getNumber());
          db.insert(TABLE_NAME, null, values);
        }
      }
    } catch (SQLException e) {
      Log.e("SeriesManager", "Error trying to include Episode:  " + e.toString());
    } finally {
      super.close();
    }
  }
コード例 #4
0
ファイル: PEpisode.java プロジェクト: jrafaelm/SeriesManager
  public void updateEpisodes(Serie serie) {
    try {
      super.open();
      for (Episode episode : serie.getEpisodes()) {

        String where = "pk_id = " + episode.getId();
        ContentValues values = new ContentValues();

        values.put("id_serie", serie.getId());
        values.put("name", episode.getName());
        values.put("season", episode.getSeason());
        values.put("number", episode.getNumber());
        if (episode.getId() == 0) {
          db.insert(TABLE_NAME, null, values);
        } else {
          db.update(TABLE_NAME, values, where, null);
        }
      }
    } catch (SQLException e) {
      Log.e("SeriesManager", "Error trying to update Episodes:  " + e.toString());
    } finally {
      super.close();
    }
  }