Search in sources :

Example 6 with Seances

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

the class TodayFragment method updateUI.

@Override
void updateUI() {
    if (isAdded()) {
        dateTime = new DateTime();
        DateTime.Property pDoW = dateTime.dayOfWeek();
        DateTime.Property pDoM = dateTime.dayOfMonth();
        DateTime.Property pMoY = dateTime.monthOfYear();
        todaysTv.setText(getActivity().getString(R.string.horaire, pDoW.getAsText(getResources().getConfiguration().locale), pDoM.get(), pMoY.getAsText(getResources().getConfiguration().locale)));
        databaseHelper = new DatabaseHelper(getActivity());
        listSeances = new ArrayList<Seances>();
        events = new ArrayList<Event>();
        try {
            SimpleDateFormat seancesFormatter = new SimpleDateFormat("yyyy-MM-dd", getResources().getConfiguration().locale);
            listSeances = (ArrayList<Seances>) databaseHelper.getDao(Seances.class).queryBuilder().where().like("dateDebut", seancesFormatter.format(dateTime.toDate()).toString() + "%").query();
            Collections.sort(listSeances, new SeanceComparator());
            events = (ArrayList<Event>) databaseHelper.getDao(Event.class).queryBuilder().where().like("startDate", seancesFormatter.format(dateTime.toDate()).toString() + "%").query();
        } catch (Exception e) {
            e.printStackTrace();
        }
        ArrayList<TodayDataRowItem> dataRowItems = new ArrayList<TodayDataRowItem>();
        if (!events.isEmpty()) {
            dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_TITLE_EVENT));
            for (Event event : events) {
                dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_EVENT, event));
            }
        }
        dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_TITLE_SEANCE));
        if (listSeances.isEmpty()) {
            tvNoCourses.setVisibility(View.VISIBLE);
        } else {
            for (Seances seances : listSeances) {
                dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_SEANCE, seances));
            }
            tvNoCourses.setVisibility(View.GONE);
        }
        adapter = new TodayAdapter(getActivity(), dataRowItems);
        todaysList.setAdapter(adapter);
    }
}
Also used : ArrayList(java.util.ArrayList) TodayAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.TodayAdapter) DateTime(org.joda.time.DateTime) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) SeanceComparator(ca.etsmtl.applets.etsmobile.util.SeanceComparator) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) Event(ca.etsmtl.applets.etsmobile.model.Event) Seances(ca.etsmtl.applets.etsmobile.model.Seances) SimpleDateFormat(java.text.SimpleDateFormat) TodayDataRowItem(ca.etsmtl.applets.etsmobile.ui.adapter.TodayDataRowItem)

Example 7 with Seances

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

the class TodayAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    int viewType = getItemViewType(position);
    Object data = getItem(position);
    if (convertView == null) {
        if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_TITLE_EVENT.getValue()) {
            convertView = LayoutInflater.from(context).inflate(R.layout.row_today_title, parent, false);
            TextView textView = (TextView) convertView.findViewById(R.id.todays_title);
            textView.setText(context.getText(R.string.today_event));
        } else if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_EVENT.getValue()) {
            convertView = LayoutInflater.from(context).inflate(R.layout.row_event, parent, false);
            ViewEventHolder eventHolder = new ViewEventHolder();
            eventHolder.tvEvent = (TextView) convertView.findViewById(R.id.event_text);
            convertView.setTag(eventHolder);
        } else if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_TITLE_SEANCE.getValue()) {
            convertView = LayoutInflater.from(context).inflate(R.layout.row_today_title, parent, false);
            TextView textView = (TextView) convertView.findViewById(R.id.todays_title);
            textView.setText(context.getText(R.string.today_course));
        } 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);
            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);
            ViewEtsEventHolder etsEventHolder = new ViewEtsEventHolder();
            etsEventHolder.tvLibelleEvenementETS = (TextView) convertView.findViewById(R.id.tv_today_libelle_ets_evenement);
            convertView.setTag(etsEventHolder);
        }
    }
    if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_EVENT.getValue()) {
        Event event = (Event) data;
        ViewEventHolder viewEventHolder = (ViewEventHolder) convertView.getTag();
        viewEventHolder.tvEvent.setText(event.getTitle());
    } else if (viewType == TodayDataRowItem.viewType.VIEW_TYPE_SEANCE.getValue()) {
        Seances seance = (Seances) data;
        ViewSeancesHolder viewSeancesHolder = (ViewSeancesHolder) convertView.getTag();
        viewSeancesHolder.tvNomActivite.setText(seance.nomActivite);
        viewSeancesHolder.tvCoursGroupe.setText(seance.coursGroupe);
        viewSeancesHolder.tvLibelleCours.setText(seance.libelleCours);
        viewSeancesHolder.tvLocal.setText(seance.local);
        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);
    }
    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 8 with Seances

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

the class HoraireFragment method fillListView.

public void fillListView() {
    try {
        List<Seances> seances = databaseHelper.getDao(Seances.class).queryForAll();
        List<Event> events = databaseHelper.getDao(Event.class).queryForAll();
        allseanceAdapter.setItemList(seances, events);
        List<Seances> upcomingSeances = new ArrayList<>();
        List<Event> upcomingEvents = new ArrayList<>();
        DateTime now = new DateTime();
        for (Seances sc : seances) {
            DateTime scDate = DateTime.parse(sc.getDateDebut());
            if (DateTimeComparator.getDateOnlyInstance().compare(now, scDate) <= 0) {
                upcomingSeances.add(sc);
            }
        }
        for (Event ev : events) {
            DateTime evDate = DateTime.parse(ev.getDateDebut());
            if (DateTimeComparator.getDateOnlyInstance().compare(now, evDate) <= 0) {
                upcomingEvents.add(ev);
            }
        }
        upcomingseanceAdapter.setItemList(upcomingSeances, upcomingEvents);
    } catch (SQLException e) {
        e.printStackTrace();
    }
    allseanceAdapter.notifyDataSetChanged();
    upcomingseanceAdapter.notifyDataSetChanged();
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Event(ca.etsmtl.applets.etsmobile.model.Event) Seances(ca.etsmtl.applets.etsmobile.model.Seances) DateTime(org.joda.time.DateTime)

Example 9 with Seances

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

the class SeanceAdapter method setItemList.

public void setItemList(List<Seances> itemListSeance, List<Event> itemListEvent) {
    listSeances = new ArrayList<>();
    ArrayList<IHoraireRows> listRowItems = new ArrayList<IHoraireRows>();
    String tempDate = "";
    DateTime today = new DateTime();
    listRowItems.addAll(itemListEvent);
    listRowItems.addAll(itemListSeance);
    Collections.sort(listRowItems, new HoraireComparator());
    for (IHoraireRows rows : listRowItems) {
        DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
        DateTime seanceDay = formatter.parseDateTime(rows.getDateDebut().substring(0, 10));
        if (!rows.getDateDebut().substring(0, 10).equals(tempDate)) {
            tempDate = rows.getDateDebut().substring(0, 10);
            DateTime.Property pDoW = seanceDay.dayOfWeek();
            DateTime.Property pDoM = seanceDay.dayOfMonth();
            DateTime.Property pMoY = seanceDay.monthOfYear();
            this.listSeances.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_TITLE_SEANCE, context.getString(R.string.date_text, pDoW.getAsText(Locale.getDefault()), pDoM.get(), pMoY.getAsText(Locale.getDefault()))));
        }
        if (rows.getClass().equals(Event.class)) {
            this.listSeances.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_ETS_EVENT, rows));
        } else if (rows.getClass().equals(Seances.class)) {
            this.listSeances.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_SEANCE, rows));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Seances(ca.etsmtl.applets.etsmobile.model.Seances) IHoraireRows(ca.etsmtl.applets.etsmobile.model.IHoraireRows) HoraireComparator(ca.etsmtl.applets.etsmobile.util.HoraireComparator) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime)

Example 10 with Seances

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

the class WearService method onMessageReceived.

@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equals("/today_req")) {
        final String message = new String(messageEvent.getData());
        List<Seances> seances = new ArrayList<>();
        DatabaseHelper databaseHelper = new DatabaseHelper(this);
        SimpleDateFormat seancesFormatter = new SimpleDateFormat("yyyy-MM-dd", getResources().getConfiguration().locale);
        try {
            seances = databaseHelper.getDao(Seances.class).queryBuilder().where().like("dateDebut", seancesFormatter.format(DateTime.now().toDate()) + "%").query();
            Collections.sort(seances, new SeanceComparator());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        new SendToDataLayerThread("/today_req", seances, this).start();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Seances(ca.etsmtl.applets.etsmobile.model.Seances) SimpleDateFormat(java.text.SimpleDateFormat) SeanceComparator(ca.etsmtl.applets.etsmobile.util.SeanceComparator)

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