Search in sources :

Example 1 with AgendaObject

use of com.giua.objects.AgendaObject in project Giua-App by Giua-app.

the class AgendaFragment method showDateActivities.

// region Listeners
private void showDateActivities(Calendar selectedDate) {
    if (isFragmentDestroyed || offlineMode) {
        activity.runOnUiThread(() -> swipeRefreshLayout.setRefreshing(false));
        return;
    }
    // Conto quanti oggetti ci sono nel giorno cliccato
    List<AgendaObject> agendaObjectsOfTheDay = new Vector<>();
    String day = String.valueOf(selectedDate.get(Calendar.DAY_OF_MONTH));
    String month = String.valueOf(selectedDate.get(Calendar.MONTH) + 1);
    String year = String.valueOf(selectedDate.get(Calendar.YEAR));
    if (day.length() == 1)
        day = "0" + day;
    if (month.length() == 1)
        month = "0" + month;
    AgendaObject agendaObjectComparator = new AgendaObject(day, month, year, year + "-" + month + "-" + day);
    for (AgendaObject agendaObject : allAgendaObjects) if (agendaObject.date.equals(agendaObjectComparator.date))
        agendaObjectsOfTheDay.add(agendaObject);
    if (!agendaObjectsOfTheDay.isEmpty()) {
        activity.runOnUiThread(() -> {
            viewsLayout.removeViews(1, viewsLayout.getChildCount() - 1);
            tvNoElements.setVisibility(View.GONE);
            viewsLayout.scrollTo(0, 0);
        });
        for (AgendaObject agendaObject : agendaObjectsOfTheDay) {
            List<AgendaObject> objectsToShow = new Vector<>();
            try {
                if (agendaObject.getRepresentingClass() == Test.class)
                    objectsToShow.addAll(GlobalVariables.gS.getAgendaPage(false).getTests(agendaObject.date));
                else if (agendaObject.getRepresentingClass() == Homework.class)
                    objectsToShow.addAll(GlobalVariables.gS.getAgendaPage(false).getHomeworks(agendaObject.date));
                else if (agendaObject.getRepresentingClass() == com.giua.objects.Activity.class)
                    objectsToShow.addAll(GlobalVariables.gS.getAgendaPage(false).getActivities(agendaObject.date));
                else if (agendaObject.getRepresentingClass() == com.giua.objects.InterviewAgenda.class)
                    objectsToShow.addAll(GlobalVariables.gS.getAgendaPage(false).getInterviews(agendaObject.date));
            } catch (GiuaScraperExceptions.YourConnectionProblems e) {
                activity.runOnUiThread(() -> {
                    setErrorMessage(activity.getString(R.string.your_connection_error), root);
                    swipeRefreshLayout.setRefreshing(false);
                });
                return;
            } catch (GiuaScraperExceptions.SiteConnectionProblems e) {
                activity.runOnUiThread(() -> {
                    setErrorMessage(activity.getString(R.string.site_connection_error), root);
                    swipeRefreshLayout.setRefreshing(false);
                });
                return;
            } catch (GiuaScraperExceptions.MaintenanceIsActiveException e) {
                activity.runOnUiThread(() -> {
                    setErrorMessage(activity.getString(R.string.maintenance_is_active_error), root);
                    swipeRefreshLayout.setRefreshing(false);
                });
                return;
            }
            activity.runOnUiThread(() -> addViews(objectsToShow));
        }
        activity.runOnUiThread(() -> swipeRefreshLayout.setRefreshing(false));
        isLoadingData = false;
    } else {
        activity.runOnUiThread(() -> {
            tvNoElements.setText("Non ci sono compiti per questo giorno");
            tvNoElements.setVisibility(View.VISIBLE);
            isLoadingData = false;
            swipeRefreshLayout.setRefreshing(false);
            viewsLayout.removeViews(1, viewsLayout.getChildCount() - 1);
        });
    }
}
Also used : AgendaObject(com.giua.objects.AgendaObject) Vector(java.util.Vector) GiuaScraperExceptions(com.giua.webscraper.GiuaScraperExceptions) Homework(com.giua.objects.Homework)

Example 2 with AgendaObject

use of com.giua.objects.AgendaObject in project Giua-App by Giua-app.

the class AgendaFragment method refreshCalendarEvents.

private void refreshCalendarEvents() throws ParseException {
    calendarView.removeAllEvents();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ITALIAN);
    for (AgendaObject agendaObject : allAgendaObjects) {
        Event event;
        if (agendaObject.getRepresentingClass() == Homework.class) {
            event = new Event(ResourcesCompat.getColor(activity.getResources(), R.color.agenda_views_cyan, activity.getTheme()), simpleDateFormat.parse(agendaObject.date).getTime());
        } else if (agendaObject.getRepresentingClass() == Test.class) {
            event = new Event(ResourcesCompat.getColor(activity.getResources(), R.color.agenda_views_orange, activity.getTheme()), simpleDateFormat.parse(agendaObject.date).getTime());
        } else if (agendaObject.getRepresentingClass() == com.giua.objects.Activity.class) {
            event = new Event(ResourcesCompat.getColor(activity.getResources(), R.color.agenda_views_green, activity.getTheme()), simpleDateFormat.parse(agendaObject.date).getTime());
        } else {
            event = new Event(ResourcesCompat.getColor(activity.getResources(), R.color.agenda_views_purple, activity.getTheme()), simpleDateFormat.parse(agendaObject.date).getTime());
        }
        calendarView.addEvent(event);
    }
}
Also used : Test(com.giua.objects.Test) Event(com.github.sundeepk.compactcalendarview.domain.Event) AgendaObject(com.giua.objects.AgendaObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with AgendaObject

use of com.giua.objects.AgendaObject in project Giua-App by Giua-app.

the class AgendaFragment method addViews.

private void addViews(List<AgendaObject> objectsToShow) {
    loggerManager.d("Aggiungo views...");
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMargins(0, 50, 0, 0);
    for (AgendaObject agendaObject : objectsToShow) {
        AgendaView agendaView = new AgendaView(activity, null, agendaObject);
        agendaView.setLayoutParams(params);
        agendaView.setId(View.generateViewId());
        viewsLayout.addView(agendaView);
    }
}
Also used : AgendaObject(com.giua.objects.AgendaObject) LinearLayout(android.widget.LinearLayout)

Aggregations

AgendaObject (com.giua.objects.AgendaObject)3 LinearLayout (android.widget.LinearLayout)1 Event (com.github.sundeepk.compactcalendarview.domain.Event)1 Homework (com.giua.objects.Homework)1 Test (com.giua.objects.Test)1 GiuaScraperExceptions (com.giua.webscraper.GiuaScraperExceptions)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Vector (java.util.Vector)1