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();
}
}
Aggregations