Search in sources :

Example 1 with TodayAdapter

use of ca.etsmtl.applets.etsmobile.ui.adapter.TodayAdapter 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)

Aggregations

DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)1 Event (ca.etsmtl.applets.etsmobile.model.Event)1 Seances (ca.etsmtl.applets.etsmobile.model.Seances)1 TodayAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.TodayAdapter)1 TodayDataRowItem (ca.etsmtl.applets.etsmobile.ui.adapter.TodayDataRowItem)1 SeanceComparator (ca.etsmtl.applets.etsmobile.util.SeanceComparator)1 SpiceException (com.octo.android.robospice.persistence.exception.SpiceException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1