Search in sources :

Example 26 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.

the class HoraireManager method deleteExpiredEvent.

/**
 * Deletes entries in DB that doesn't exist on API
 *
 * @param
 */
private void deleteExpiredEvent(EventList envEventList) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    ArrayList<Event> dbEvents = new ArrayList<Event>();
    try {
        dbEvents = (ArrayList<Event>) dbHelper.getDao(Event.class).queryForAll();
        for (Event eventsNew : dbEvents) {
            if (!dbEvents.contains(eventsNew.getId())) {
                Dao<Event, String> eventDao = dbHelper.getDao(Event.class);
                eventDao.deleteById(eventsNew.getId());
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Event(ca.etsmtl.applets.etsmobile.model.Event)

Example 27 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper 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)

Example 28 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.

the class HoraireManager method deleteExpiredExamensFinaux.

/**
 * Deletes entries in DB that doesn't exist on API
 *
 * @param listeHoraireExamensFinaux
 */
private void deleteExpiredExamensFinaux(listeHoraireExamensFinaux listeHoraireExamensFinaux) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, HoraireExamenFinal> listeHoraireExamenFinalInAPI = new HashMap<String, HoraireExamenFinal>();
    // Building the list of entries in API
    for (HoraireExamenFinal horaireExamenFinalInAPI : listeHoraireExamensFinaux.listeHoraire) {
        horaireExamenFinalInAPI.id = horaireExamenFinalInAPI.sigle + "-" + horaireExamenFinalInAPI.groupe + horaireExamenFinalInAPI.dateExamen + horaireExamenFinalInAPI.heureDebut + horaireExamenFinalInAPI.heureFin;
        listeHoraireExamenFinalInAPI.put(horaireExamenFinalInAPI.id, horaireExamenFinalInAPI);
    }
    ArrayList<HoraireExamenFinal> listeHoraireExamenFinalInDB = new ArrayList<HoraireExamenFinal>();
    // Comparing entries on DB and API
    try {
        listeHoraireExamenFinalInDB = (ArrayList<HoraireExamenFinal>) dbHelper.getDao(HoraireExamenFinal.class).queryForAll();
        for (HoraireExamenFinal horaireExamenFinalInDB : listeHoraireExamenFinalInDB) {
            if (!listeHoraireExamenFinalInAPI.containsKey((String) horaireExamenFinalInDB.id)) {
                Dao<HoraireExamenFinal, String> horaireExamenFinalDao = dbHelper.getDao(HoraireExamenFinal.class);
                horaireExamenFinalDao.deleteById(horaireExamenFinalInDB.id);
            }
        }
    } 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) HoraireExamenFinal(ca.etsmtl.applets.etsmobile.model.HoraireExamenFinal)

Example 29 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.

the class NotificationManager method updateDatabase.

/**
 * Updates the database with a given list of notifications
 *
 * @param notifications the list of notifications that have been fetched from MonÉTS's API
 */
private void updateDatabase(List<MonETSNotification> notifications) {
    DatabaseHelper databaseHelper = new DatabaseHelper(context);
    try {
        Dao<MonETSNotification, ?> dao = databaseHelper.getDao(MonETSNotification.class);
        for (MonETSNotification monETSNotification : notifications) {
            dao.createOrUpdate(monETSNotification);
        }
        listener.onRequestSuccess(notifications);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : MonETSNotification(ca.etsmtl.applets.etsmobile.model.MonETSNotification) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException)

Example 30 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.

the class HoraireFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.calendar_horaire_layout, container, false);
    ButterKnife.bind(this, v);
    databaseHelper = new DatabaseHelper(getActivity());
    seanceAdapter = new SeanceAdapter(getActivity());
    allseanceAdapter = new SeanceAdapter(getActivity());
    upcomingseanceAdapter = new SeanceAdapter(getActivity());
    fillSeancesList(dateTime.toDate());
    fillListView();
    setDaysList();
    calendar_listview.setAdapter(upcomingseanceAdapter);
    mCalendarView.setCurrentDate(new Date());
    mCalendarView.setSelectedDate(new Date());
    mCalendarView.setOnDateChangedListener(this);
    mCalendarView.addDecorators(new CourseDecorator(getActivity(), courseDays), new FinalExamDecorator(getActivity(), finalExamDays), new EventDecorator(eventDays, ContextCompat.getColor(getActivity(), R.color.black)), new TodayDecorator(getActivity()), new CourseTodayDecorator(getActivity(), courseDays));
    horaireManager = new HoraireManager(this, getActivity());
    horaireManager.addObserver(this);
    progressBarSyncHoraire = (ProgressBar) v.findViewById(R.id.progressBar_sync_horaire);
    progressBarSyncHoraire.setVisibility(ProgressBar.VISIBLE);
    // customProgressDialog = new CustomProgressDialog(getActivity(), R.drawable.loading_spinner, "Synchronisation en cours");
    // customProgressDialog.show();
    dataManager.getDataFromSignet(SignetsMethods.LIST_SESSION, ApplicationManager.userCredentials, this);
    dataManager.getDataFromSignet(SignetsMethods.LIST_SEANCES_CURRENT_AND_NEXT_SESSION, ApplicationManager.userCredentials, this);
    dataManager.getDataFromSignet(SignetsMethods.LIST_JOURSREMPLACES_CURRENT_AND_NEXT_SESSION, ApplicationManager.userCredentials, this);
    return v;
}
Also used : HoraireManager(ca.etsmtl.applets.etsmobile.util.HoraireManager) SeanceAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.SeanceAdapter) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) CourseDecorator(ca.etsmtl.applets.etsmobile.ui.calendar_decorator.CourseDecorator) FinalExamDecorator(ca.etsmtl.applets.etsmobile.ui.calendar_decorator.FinalExamDecorator) EventDecorator(ca.etsmtl.applets.etsmobile.ui.calendar_decorator.EventDecorator) BindView(butterknife.BindView) View(android.view.View) MaterialCalendarView(com.prolificinteractive.materialcalendarview.MaterialCalendarView) ListView(android.widget.ListView) CourseTodayDecorator(ca.etsmtl.applets.etsmobile.ui.calendar_decorator.CourseTodayDecorator) Date(java.util.Date) CourseTodayDecorator(ca.etsmtl.applets.etsmobile.ui.calendar_decorator.CourseTodayDecorator) TodayDecorator(ca.etsmtl.applets.etsmobile.ui.calendar_decorator.TodayDecorator)

Aggregations

DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)32 SQLException (java.sql.SQLException)27 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)9 ElementEvaluation (ca.etsmtl.applets.etsmobile.model.ElementEvaluation)4 FicheEmploye (ca.etsmtl.applets.etsmobile.model.FicheEmploye)4 ListeDesElementsEvaluation (ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation)4 Seances (ca.etsmtl.applets.etsmobile.model.Seances)4 Cours (ca.etsmtl.applets.etsmobile.model.Cours)3 Event (ca.etsmtl.applets.etsmobile.model.Event)3 ListeDeCours (ca.etsmtl.applets.etsmobile.model.ListeDeCours)3 Where (com.j256.ormlite.stmt.Where)3 JoursRemplaces (ca.etsmtl.applets.etsmobile.model.JoursRemplaces)2 MonETSNotification (ca.etsmtl.applets.etsmobile.model.MonETSNotification)2 Sponsor (ca.etsmtl.applets.etsmobile.model.Sponsor)2 Trimestre (ca.etsmtl.applets.etsmobile.model.Trimestre)2 ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces (ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces)2 ca.etsmtl.applets.etsmobile.model.listeSeances (ca.etsmtl.applets.etsmobile.model.listeSeances)2 ExpandableListAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter)2 SeanceComparator (ca.etsmtl.applets.etsmobile.util.SeanceComparator)2