Esempio n. 1
0
  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;
  }
Esempio n. 2
0
  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;
  }
Esempio n. 3
0
  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();
    }
  }
Esempio n. 4
0
  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();
    }
  }