Search in sources :

Example 11 with Alert

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

the class AlertsFragment method alertViewOfflineOnClick.

private void alertViewOfflineOnClick(View view) {
    Alert alert = ((AlertView) view).alert;
    if (!alert.isDetailed) {
        setErrorMessage("Dettagli di questo avviso non scaricati!", root);
        return;
    }
    swipeRefreshLayout.setRefreshing(true);
    TextView alertDetailsTextView = root.findViewById(R.id.alert_details_text_view);
    alertDetailsTextView.setText(Html.fromHtml(alert.details, 0));
    ((TextView) root.findViewById(R.id.alert_creator_text_view)).setText(alert.creator);
    ((TextView) root.findViewById(R.id.alert_type_text_view)).setText(alert.type);
    // Parsing per url nel html
    Linkify.addLinks(alertDetailsTextView, Linkify.WEB_URLS);
    attachmentLayout.removeAllViews();
    int urlsListLength = alert.attachmentUrls.size();
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMargins(0, 20, 0, 0);
    for (int i = 0; i < urlsListLength; i++) {
        TextView tvUrl = new TextView(requireActivity());
        tvUrl.setText("Allegato " + (i + 1));
        tvUrl.setTypeface(tvNoElements.getTypeface(), Typeface.NORMAL);
        tvUrl.setBackground(ResourcesCompat.getDrawable(activity.getResources(), R.drawable.corner_radius_10dp, activity.getTheme()));
        tvUrl.setBackgroundTintList(activity.getResources().getColorStateList(R.color.main_color, activity.getTheme()));
        tvUrl.setPadding(20, 20, 20, 20);
        tvUrl.setLayoutParams(params);
        tvUrl.setTextColor(activity.getResources().getColorStateList(R.color.light_white_night_black, activity.getTheme()));
        int finalI = i;
        tvUrl.setOnClickListener((view2) -> downloadAndOpenFile(alert.attachmentUrls.get(finalI)));
        attachmentLayout.addView(tvUrl);
    }
    detailsLayout.startAnimation(AnimationUtils.loadAnimation(requireActivity(), R.anim.visualizer_show_effect));
    detailsLayout.setVisibility(View.VISIBLE);
    obscureLayoutView.show();
    swipeRefreshLayout.setRefreshing(false);
}
Also used : Alert(com.giua.objects.Alert) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 12 with Alert

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

the class NotificationsDBController method readAlerts.

public List<Alert> readAlerts() {
    Cursor cursor = db.rawQuery("SELECT * FROM " + ALERTS_TABLE, null);
    List<Alert> alerts = new Vector<>();
    if (cursor.moveToFirst()) {
        do {
            // 0 = false, 1 = true
            boolean isDetailed = cursor.getInt(DBAlert.IS_DETAILED_COL.ordinal()) != 0;
            if (isDetailed) {
                List<String> attachmentUrls = null;
                try {
                    attachmentUrls = Arrays.asList(cursor.getString(DBAlert.ATTACHMENT_URLS_COL.ordinal()).split(";"));
                } catch (NullPointerException ignored) {
                }
                alerts.add(new Alert(cursor.getString(DBAlert.STATUS_COL.ordinal()), cursor.getString(DBAlert.DATE_COL.ordinal()), cursor.getString(DBAlert.RECEIVERS_COL.ordinal()), cursor.getString(DBAlert.OBJECT_COL.ordinal()), cursor.getString(DBAlert.DETAILS_URL_COL.ordinal()), cursor.getInt(DBAlert.PAGE_COL.ordinal()), attachmentUrls, cursor.getString(DBAlert.DETAILS_COL.ordinal()), cursor.getString(DBAlert.CREATOR_COL.ordinal()), cursor.getString(DBAlert.TYPE_COL.ordinal())));
            } else {
                alerts.add(new Alert(cursor.getString(DBAlert.DATE_COL.ordinal()), cursor.getString(DBAlert.DATE_COL.ordinal()), cursor.getString(DBAlert.RECEIVERS_COL.ordinal()), cursor.getString(DBAlert.OBJECT_COL.ordinal()), cursor.getString(DBAlert.DETAILS_URL_COL.ordinal()), cursor.getInt(DBAlert.PAGE_COL.ordinal())));
            }
        } while (cursor.moveToNext());
    // muovi il cursore nella prossima riga
    }
    cursor.close();
    return alerts;
}
Also used : Alert(com.giua.objects.Alert) Cursor(android.database.Cursor) Vector(java.util.Vector)

Example 13 with Alert

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

the class AppNotifications method createTestsNotification.

private Notification createTestsNotification(List<Alert> allNewTests) {
    String title;
    String text = "Clicca per andare all'agenda";
    String bigText = "";
    int nNewTests = allNewTests.size();
    for (Alert alert : allNewTests) {
        String[] rawSubject = alert.object.split(" per la materia ");
        if (rawSubject.length > 1) {
            String subject = rawSubject[1];
            bigText += subject + " - " + alert.date + "\n";
        } else
            loggerManager.w("Non ho trovato la materia nell'avviso delle verifiche: " + alert);
    }
    if (nNewTests == 1)
        title = "Nuova verifica";
    else
        title = nNewTests + " nuove verifiche";
    return createNotificationWithBigText(title, text, bigText, AppNotificationsParams.AGENDA_NOTIFICATION_GOTO, AppNotificationsParams.TESTS_NOTIFICATION_REQUEST_CODE);
}
Also used : Alert(com.giua.objects.Alert)

Example 14 with Alert

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

the class AppNotifications method createHomeworksNotification.

private Notification createHomeworksNotification(List<Alert> allNewHomeworks) {
    String title;
    String text = "Clicca per andare all'agenda";
    String bigText = "";
    int nNewHomeworks = allNewHomeworks.size();
    for (Alert alert : allNewHomeworks) {
        String[] rawSubject = alert.object.split(" per la materia ");
        if (rawSubject.length > 1) {
            String subject = rawSubject[1];
            bigText += subject + " - " + alert.date + "\n";
        } else
            loggerManager.w("Non ho trovato la materia nell'avviso dei compiti: " + alert);
    }
    if (nNewHomeworks == 1)
        title = "Nuovo compito";
    else
        title = nNewHomeworks + " nuovi compiti";
    return createNotificationWithBigText(title, text, bigText, AppNotificationsParams.AGENDA_NOTIFICATION_GOTO, AppNotificationsParams.HOMEWORKS_NOTIFICATION_REQUEST_CODE);
}
Also used : Alert(com.giua.objects.Alert)

Example 15 with Alert

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

the class AppNotifications method checkNewsForAgenda.

// region Agenda
private void checkNewsForAgenda() {
    // Ci sono sia gli avvisi dei compiti sia delle verifiche
    List<Alert> allNewTestsHomeworks;
    try {
        allNewTestsHomeworks = gS.getAlertsPage(false).getAllAlertsWithFilters(false, "per la materia");
    } catch (Exception e) {
        loggerManager.w("Controllo delle VERIFICHE e dei COMPITI in background non riuscito: " + e + " " + e.getMessage());
        return;
    }
    NotificationsDBController notificationsDBController = new NotificationsDBController(context);
    List<Alert> allNewTests = new Vector<>(allNewTestsHomeworks.size());
    List<Alert> allNewHomeworks = new Vector<>(allNewTestsHomeworks.size());
    List<Alert> allOldTests = notificationsDBController.readAlertsTests();
    List<Alert> allOldHomeworks = notificationsDBController.readAlertsHomeworks();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.ITALY);
    Date today = new Date();
    for (Alert alert : allNewTestsHomeworks) {
        try {
            // Se il compito o la verifica era per un giorno prima di oggi non notificarla
            if (today.after(simpleDateFormat.parse(alert.date)))
                continue;
        } catch (ParseException e) {
            loggerManager.w("Controllando gli avvisi per i compiti e le verifiche ho trovato una data che non capisco: " + alert);
            continue;
        }
        if (alert.object.startsWith("C"))
            allNewHomeworks.add(alert);
        else if (alert.object.startsWith("V"))
            allNewTests.add(alert);
        else
            loggerManager.w("Durante il controllo dei nuovi avvisi per i compiti e le verifiche ho trovato un avviso che non รจ nessuno dei due: " + alert);
    }
    notificationsDBController.replaceAlertsTests(allNewTests);
    notificationsDBController.replaceAlertsHomeworks(allNewHomeworks);
    if (canSendNotificationsHomeworks && allOldHomeworks.size() > 0 && allOldHomeworks.get(0).page != -2) {
        for (Alert alert : allOldHomeworks) allNewHomeworks.remove(alert);
        if (allNewHomeworks.size() > 0) {
            notificationManager.cancel(AppNotificationsParams.HOMEWORKS_NOTIFICATION_ID);
            notificationManager.notify(AppNotificationsParams.HOMEWORKS_NOTIFICATION_ID, createHomeworksNotification(allNewHomeworks));
        }
    }
    if (canSendNotificationsTests && allOldTests.size() > 0 && allOldTests.get(0).page != -2) {
        for (Alert alert : allOldTests) allNewTests.remove(alert);
        if (allNewTests.size() > 0) {
            notificationManager.cancel(AppNotificationsParams.TESTS_NOTIFICATION_ID);
            notificationManager.notify(AppNotificationsParams.TESTS_NOTIFICATION_ID, createTestsNotification(allNewTests));
        }
    }
// endregion
}
Also used : Alert(com.giua.objects.Alert) ParseException(java.text.ParseException) Vector(java.util.Vector) SimpleDateFormat(java.text.SimpleDateFormat) URISyntaxException(java.net.URISyntaxException) ParseException(java.text.ParseException) IOException(java.io.IOException) Date(java.util.Date)

Aggregations

Alert (com.giua.objects.Alert)18 Vector (java.util.Vector)11 Cursor (android.database.Cursor)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 LinearLayout (android.widget.LinearLayout)3 IOException (java.io.IOException)3 TextView (android.widget.TextView)2 GiuaScraperExceptions (com.giua.webscraper.GiuaScraperExceptions)2 URISyntaxException (java.net.URISyntaxException)2 ParseException (java.text.ParseException)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 Notification (android.app.Notification)1 AlertsPage (com.giua.pages.AlertsPage)1 JsonBuilder (com.giua.utils.JsonBuilder)1 JsonParser (com.giua.utils.JsonParser)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1