use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class SponsorManager method getSponsorList.
public ArrayList<Sponsor> getSponsorList() {
DatabaseHelper dbHelper = new DatabaseHelper(context);
ArrayList<Sponsor> sponsorList = null;
try {
sponsorList = (ArrayList<Sponsor>) dbHelper.getDao(Sponsor.class).queryForAll();
} catch (SQLException e) {
Log.e("SQL Exception", e.getMessage());
}
return sponsorList;
}
use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class SponsorManager method deleteExpiredSponsor.
public void deleteExpiredSponsor(SponsorList sponsorList) {
DatabaseHelper dbHelper = new DatabaseHelper(context);
HashMap<String, Sponsor> sponsorHashMap = new HashMap<String, Sponsor>();
for (Sponsor sponsor : sponsorList) {
sponsorHashMap.put(sponsor.getName(), sponsor);
}
ArrayList<Sponsor> dbSponsor;
try {
dbSponsor = (ArrayList<Sponsor>) dbHelper.getDao(Sponsor.class).queryForAll();
for (Sponsor sponsorNew : dbSponsor) {
if (!sponsorHashMap.containsKey(sponsorNew.getName())) {
Dao<Sponsor, String> sponsorDao = dbHelper.getDao(Sponsor.class);
sponsorDao.deleteById(sponsorNew.getName());
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper 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.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class HoraireManager method deleteExpiredSeances.
/**
* Deletes entries in DB that doesn't exist on API
*
* @param listeSeances
*/
private void deleteExpiredSeances(listeSeances listeSeances) {
DatabaseHelper dbHelper = new DatabaseHelper(context);
HashMap<String, Seances> listeSeancesInAPI = new HashMap<String, Seances>();
// Building the list of entries in API
for (Seances SeancesInAPI : listeSeances.ListeDesSeances) {
SeancesInAPI.id = SeancesInAPI.coursGroupe + SeancesInAPI.dateDebut + SeancesInAPI.dateFin + SeancesInAPI.local;
listeSeancesInAPI.put(SeancesInAPI.id, SeancesInAPI);
}
ArrayList<Seances> listeSeancesInDB = new ArrayList<Seances>();
// Comparing entries on DB and API
try {
listeSeancesInDB = (ArrayList<Seances>) dbHelper.getDao(Seances.class).queryForAll();
for (Seances SeancesInDB : listeSeancesInDB) {
if (!listeSeancesInAPI.containsKey((String) SeancesInDB.id)) {
Dao<Seances, String> SeancesDao = dbHelper.getDao(Seances.class);
SeancesDao.deleteById(SeancesInDB.id);
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper 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