Search in sources :

Example 1 with SeanceComparator

use of ca.etsmtl.applets.etsmobile.util.SeanceComparator 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 2 with SeanceComparator

use of ca.etsmtl.applets.etsmobile.util.SeanceComparator 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

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