Search in sources :

Example 1 with HoraireActivite

use of ca.etsmtl.applets.etsmobile.model.HoraireActivite in project ETSMobile-Android2 by ApplETS.

the class HoraireManager method deleteExpiredHoraireActivite.

/**
 * Deletes entries in DB that doesn't exist on API
 *
 * @param listeDesActivitesEtProf API list
 */
private void deleteExpiredHoraireActivite(listeDesActivitesEtProf listeDesActivitesEtProf) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, HoraireActivite> listeHoraireActiviteInAPI = new HashMap<String, HoraireActivite>();
    // Building the list of entries in API
    for (HoraireActivite horaireActiviteInAPI : listeDesActivitesEtProf.listeActivites) {
        horaireActiviteInAPI.id = "" + horaireActiviteInAPI.sigle + horaireActiviteInAPI.groupe + horaireActiviteInAPI.jour + horaireActiviteInAPI.heureDebut + horaireActiviteInAPI.heureFin;
        listeHoraireActiviteInAPI.put(horaireActiviteInAPI.id, horaireActiviteInAPI);
    }
    ArrayList<HoraireActivite> listeHoraireActiviteInDB = new ArrayList<HoraireActivite>();
    // Comparing entries on DB and API
    try {
        listeHoraireActiviteInDB = (ArrayList<HoraireActivite>) dbHelper.getDao(HoraireActivite.class).queryForAll();
        for (HoraireActivite horaireActiviteInDB : listeHoraireActiviteInDB) {
            if (!listeHoraireActiviteInAPI.containsKey((String) horaireActiviteInDB.id)) {
                Dao<HoraireActivite, String> horaireActiviteDao = dbHelper.getDao(HoraireActivite.class);
                horaireActiviteDao.deleteById(horaireActiviteInDB.id);
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : HoraireActivite(ca.etsmtl.applets.etsmobile.model.HoraireActivite) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList)

Aggregations

DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)1 HoraireActivite (ca.etsmtl.applets.etsmobile.model.HoraireActivite)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1