Search in sources :

Example 1 with JoursRemplaces

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();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces(ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces) JoursRemplaces(ca.etsmtl.applets.etsmobile.model.JoursRemplaces)

Example 2 with JoursRemplaces

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()));
        }
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) ArrayList(java.util.ArrayList) Event(ca.etsmtl.applets.etsmobile.model.Event) ca.etsmtl.applets.etsmobile.model.listeSeances(ca.etsmtl.applets.etsmobile.model.listeSeances) Seances(ca.etsmtl.applets.etsmobile.model.Seances) ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces(ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces) JoursRemplaces(ca.etsmtl.applets.etsmobile.model.JoursRemplaces) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)2 JoursRemplaces (ca.etsmtl.applets.etsmobile.model.JoursRemplaces)2 ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces (ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces)2 ArrayList (java.util.ArrayList)2 Event (ca.etsmtl.applets.etsmobile.model.Event)1 Seances (ca.etsmtl.applets.etsmobile.model.Seances)1 ca.etsmtl.applets.etsmobile.model.listeSeances (ca.etsmtl.applets.etsmobile.model.listeSeances)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1