Search in sources :

Example 1 with Seances

use of ca.etsmtl.applets.etsmobile.model.Seances in project ETSMobile-Android2 by ApplETS.

the class HoraireFragment method fillSeancesList.

public void fillSeancesList(Date date) {
    SimpleDateFormat seancesFormatter = new SimpleDateFormat("yyyy-MM-dd", getResources().getConfiguration().locale);
    String today = seancesFormatter.format(date).toString();
    try {
        List<Seances> seances = databaseHelper.getDao(Seances.class).queryBuilder().where().like("dateDebut", today + "%").query();
        List<Event> events = databaseHelper.getDao(Event.class).queryBuilder().where().like("startDate", today + "%").query();
        seanceAdapter.setItemList(seances, events);
    } catch (SQLException e) {
        e.printStackTrace();
    }
    seanceAdapter.notifyDataSetChanged();
}
Also used : SQLException(java.sql.SQLException) Event(ca.etsmtl.applets.etsmobile.model.Event) Seances(ca.etsmtl.applets.etsmobile.model.Seances) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Seances

use of ca.etsmtl.applets.etsmobile.model.Seances in project ETSMobile-Android2 by ApplETS.

the class HoraireFragment method setDaysList.

public void setDaysList() {
    courseDays = new ArrayList<>();
    finalExamDays = new ArrayList<>();
    eventDays = new ArrayList<>();
    try {
        ArrayList<Seances> seancesList = (ArrayList<Seances>) databaseHelper.getDao(Seances.class).queryForAll();
        for (Seances seance : seancesList) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            Date seanceDay = formatter.parse(seance.dateDebut.substring(0, 10), new ParsePosition(0));
            if (seance.descriptionActivite.contains("final"))
                finalExamDays.add(CalendarDay.from(seanceDay));
            else
                courseDays.add(CalendarDay.from(seanceDay));
        }
        ArrayList<Event> eventList = (ArrayList<Event>) databaseHelper.getDao(Event.class).queryForAll();
        for (Event event : eventList) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            Date eventDay = formatter.parse(event.getDateDebut().substring(0, 10), new ParsePosition(0));
            eventDays.add(CalendarDay.from(eventDay));
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Event(ca.etsmtl.applets.etsmobile.model.Event) Seances(ca.etsmtl.applets.etsmobile.model.Seances) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 3 with Seances

use of ca.etsmtl.applets.etsmobile.model.Seances in project ETSMobile-Android2 by ApplETS.

the class SeanceAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    int viewType = getItemViewType(position);
    if (convertView == null) {
        if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_TITLE_SEANCE.getValue()) {
            convertView = LayoutInflater.from(context).inflate(R.layout.row_today_title, parent, false);
            ViewSeancesTitleHolder titleHolder = new ViewSeancesTitleHolder();
            titleHolder.tvTitle = (TextView) convertView.findViewById(R.id.todays_title);
            convertView.setTag(titleHolder);
        } else if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_SEANCE.getValue()) {
            convertView = LayoutInflater.from(context).inflate(R.layout.row_today_courses, parent, false);
            ViewSeancesHolder seancesHolder = new ViewSeancesHolder();
            seancesHolder.tvHeureDebut = (TextView) convertView.findViewById(R.id.tv_today_heure_debut);
            seancesHolder.tvHeureFin = (TextView) convertView.findViewById(R.id.tv_today_heure_fin);
            seancesHolder.tvCoursGroupe = (TextView) convertView.findViewById(R.id.tv_today_cours_groupe);
            seancesHolder.tvNomActivite = (TextView) convertView.findViewById(R.id.tv_today_nom_activite);
            seancesHolder.tvLibelleCours = (TextView) convertView.findViewById(R.id.tv_today_libelle_cours);
            seancesHolder.tvLocal = (TextView) convertView.findViewById(R.id.tv_today_local);
            seancesHolder.tvSeparator = (TextView) convertView.findViewById(R.id.tv_vertical_separator);
            convertView.setTag(seancesHolder);
        } else if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_ETS_EVENT.getValue()) {
            convertView = LayoutInflater.from(context).inflate(R.layout.row_today_ets_event, parent, false);
            ViewEvenementETSHolder etsEventHolder = new ViewEvenementETSHolder();
            etsEventHolder.tvLibelleEvenementETS = (TextView) convertView.findViewById(R.id.tv_today_libelle_ets_evenement);
            convertView.setTag(etsEventHolder);
        }
    }
    if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_TITLE_SEANCE.getValue()) {
        ViewSeancesTitleHolder titleHolder = (ViewSeancesTitleHolder) convertView.getTag();
        titleHolder.tvTitle.setText((String) getItem(position));
    } else if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_SEANCE.getValue()) {
        Seances seance = (Seances) getItem(position);
        ViewSeancesHolder viewSeancesHolder = (ViewSeancesHolder) convertView.getTag();
        viewSeancesHolder.tvNomActivite.setText(seance.nomActivite);
        viewSeancesHolder.tvLibelleCours.setText(seance.libelleCours);
        viewSeancesHolder.tvCoursGroupe.setText(seance.coursGroupe);
        viewSeancesHolder.tvLocal.setText(seance.local);
        if (colors.containsKey(seance.coursGroupe)) {
            viewSeancesHolder.tvSeparator.setBackgroundColor(colors.get(seance.coursGroupe));
        } else {
            colors.put(seance.coursGroupe, rainbow[indexColor % rainbow.length]);
            viewSeancesHolder.tvSeparator.setBackgroundColor(rainbow[indexColor % rainbow.length]);
            indexColor++;
        }
        DateTime mDateDebut = DateTime.parse(seance.dateDebut);
        DateTime mDateFin = DateTime.parse(seance.dateFin);
        String dateDebut = String.format("%dh%02d", mDateDebut.getHourOfDay(), mDateDebut.getMinuteOfHour());
        String dateFin = String.format("%dh%02d", mDateFin.getHourOfDay(), mDateFin.getMinuteOfHour());
        viewSeancesHolder.tvHeureDebut.setText(dateDebut);
        viewSeancesHolder.tvHeureFin.setText(dateFin);
    } else if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_ETS_EVENT.getValue()) {
        Event event = (Event) getItem(position);
        ViewEvenementETSHolder viewSeancesHolder = (ViewEvenementETSHolder) convertView.getTag();
        viewSeancesHolder.tvLibelleEvenementETS.setText(event.getTitle());
    }
    return convertView;
}
Also used : Event(ca.etsmtl.applets.etsmobile.model.Event) TextView(android.widget.TextView) Seances(ca.etsmtl.applets.etsmobile.model.Seances) DateTime(org.joda.time.DateTime)

Example 4 with Seances

use of ca.etsmtl.applets.etsmobile.model.Seances 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();
    }
}
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.listeSeances(ca.etsmtl.applets.etsmobile.model.listeSeances) Seances(ca.etsmtl.applets.etsmobile.model.Seances)

Example 5 with Seances

use of ca.etsmtl.applets.etsmobile.model.Seances 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

Seances (ca.etsmtl.applets.etsmobile.model.Seances)10 Event (ca.etsmtl.applets.etsmobile.model.Event)7 ArrayList (java.util.ArrayList)7 SQLException (java.sql.SQLException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 DateTime (org.joda.time.DateTime)5 DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)4 TextView (android.widget.TextView)2 ca.etsmtl.applets.etsmobile.model.listeSeances (ca.etsmtl.applets.etsmobile.model.listeSeances)2 SeanceComparator (ca.etsmtl.applets.etsmobile.util.SeanceComparator)2 IHoraireRows (ca.etsmtl.applets.etsmobile.model.IHoraireRows)1 JoursRemplaces (ca.etsmtl.applets.etsmobile.model.JoursRemplaces)1 ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces (ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces)1 TodayAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.TodayAdapter)1 TodayDataRowItem (ca.etsmtl.applets.etsmobile.ui.adapter.TodayDataRowItem)1 HoraireComparator (ca.etsmtl.applets.etsmobile.util.HoraireComparator)1 SpiceException (com.octo.android.robospice.persistence.exception.SpiceException)1 ParsePosition (java.text.ParsePosition)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1