예제 #1
0
  public ArrayList<Episode> listBySerie(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)) {
          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);
          if (serie.getSeasonEpisodes().containsKey(episode.getSeason())) {
            if (serie.getSeasonEpisodes().get(episode.getSeason()) < episode.getNumber()) {
              serie.getSeasonEpisodes().put(episode.getSeason(), episode.getNumber());
            }
          } else {
            serie.getSeasonEpisodes().put(episode.getSeason(), episode.getNumber());
          }
        }
      } while (c.moveToNext());
    }
    c.close();
    super.close();
    return episodes;
  }
예제 #2
0
 public void addEpisode(Episode episode, Serie serie) {
   try {
     super.open();
     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();
   }
 }
예제 #3
0
  public void updateEpisode(Episode episode, Serie serie) {
    try {
      String where = "pk_id = " + episode.getId();
      super.open();

      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.update(TABLE_NAME, values, where, null);
    } catch (SQLException e) {
      Log.e("SeriesManager", "Error trying to update Episode:  " + e.toString());
    } finally {
      super.close();
    }
  }