use of ca.etsmtl.applets.etsmobile.model.JoursRemplaces in project ETSMobile-Android2 by ApplETS.
the class HoraireManager method deleteExpiredJoursRemplaces.
/**
* Deletes entries in DB that doesn't exist on API
*
* @param listeJoursRemplaces
*/
private void deleteExpiredJoursRemplaces(listeJoursRemplaces listeJoursRemplaces) {
DatabaseHelper dbHelper = new DatabaseHelper(context);
HashMap<String, JoursRemplaces> listeJoursRemplacesInAPI = new HashMap<String, JoursRemplaces>();
//Building the list of entries in API
for (JoursRemplaces JoursRemplacesInAPI : listeJoursRemplaces.listeJours) {
listeJoursRemplacesInAPI.put(JoursRemplacesInAPI.dateOrigine, JoursRemplacesInAPI);
}
ArrayList<JoursRemplaces> listeJoursRemplacesInDB = new ArrayList<JoursRemplaces>();
//Comparing entries on DB and API
try {
listeJoursRemplacesInDB = (ArrayList<JoursRemplaces>) dbHelper.getDao(JoursRemplaces.class).queryForAll();
for (JoursRemplaces JoursRemplacesInDB : listeJoursRemplacesInDB) {
if (!listeJoursRemplacesInAPI.containsKey((String) JoursRemplacesInDB.dateOrigine)) {
Dao<JoursRemplaces, String> JoursRemplacesDao = dbHelper.getDao(JoursRemplaces.class);
JoursRemplacesDao.deleteById(JoursRemplacesInDB.dateOrigine);
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of ca.etsmtl.applets.etsmobile.model.JoursRemplaces in project ETSMobile-Android2 by ApplETS.
the class HoraireManager method updateCalendar.
/**
* Creates/Updates a new calendar on the user's device
*
* @param joursRemplacesSelected true if the "Jours remplacés" calendar was selected
* @param seancesSelected true if the "Séances" calendar was selected
* @param calPublicSelected true if the "Calendrier public ÉTS" was selected
* @throws Exception if there is an SQL when checking the replaced days (Jours remplacés)
*/
public void updateCalendar(boolean joursRemplacesSelected, boolean seancesSelected, boolean calPublicSelected) throws Exception {
DatabaseHelper dbHelper = new DatabaseHelper(context);
AndroidCalendarManager androidCalendarManager = new AndroidCalendarManager(context);
androidCalendarManager.deleteCalendar(calendarName);
androidCalendarManager.createCalendar(calendarName);
SimpleDateFormat joursRemplacesFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.CANADA_FRENCH);
if (joursRemplacesSelected) {
//Inserting JoursRemplaces in local calendar
ArrayList<JoursRemplaces> listeJoursRemplaces = (ArrayList<JoursRemplaces>) dbHelper.getDao(JoursRemplaces.class).queryForAll();
for (JoursRemplaces joursRemplaces : listeJoursRemplaces) {
androidCalendarManager.insertEventInCalendar(calendarName, joursRemplaces.description, joursRemplaces.description, "", joursRemplacesFormatter.parse(joursRemplaces.dateOrigine), joursRemplacesFormatter.parse(joursRemplaces.dateOrigine));
}
}
if (seancesSelected) {
//Inserting Seances in local calendar
SimpleDateFormat seancesFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.CANADA_FRENCH);
ArrayList<Seances> seances = (ArrayList<Seances>) dbHelper.getDao(Seances.class).queryForAll();
for (Seances seance : seances) {
androidCalendarManager.insertEventInCalendar(calendarName, seance.descriptionActivite.equals("Examen final") ? "Examen final " + seance.coursGroupe : seance.coursGroupe, seance.libelleCours + " - " + seance.descriptionActivite, seance.local, seancesFormatter.parse(seance.dateDebut), seancesFormatter.parse(seance.dateFin));
}
}
if (calPublicSelected) {
//Inserting public calendar ETS
ArrayList<Event> events = (ArrayList<Event>) dbHelper.getDao(Event.class).queryForAll();
for (Event event : events) {
androidCalendarManager.insertEventInCalendar(calendarName, event.getTitle(), "", "", joursRemplacesFormatter.parse(event.getDateDebut()), joursRemplacesFormatter.parse(event.getDateFin()));
}
}
}
Aggregations