Search in sources :

Example 16 with LoggerManager

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

the class HomeFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    root = inflater.inflate(R.layout.fragment_home, container, false);
    activity = requireActivity();
    loggerManager = new LoggerManager("HomeFragment", activity);
    contentLayout = root.findViewById(R.id.home_content_layout);
    tvHomeworks = root.findViewById(R.id.home_txt_homeworks);
    tvTests = root.findViewById(R.id.home_txt_tests);
    swipeRefreshLayout = root.findViewById(R.id.home_swipe_refresh_layout);
    txUserInfo = root.findViewById(R.id.home_user_info);
    allCharts = new Vector<>(4);
    allCharts.add(new HomeChartView(activity));
    ((LinearLayout) allCharts.get(0).findViewById(R.id.view_home_main_layout)).addView(createArrowIconForChart(), 0);
    contentLayout.addView(allCharts.get(0));
    allCharts.get(0).setOnClickListener(this::mainChartOnClick);
    root.findViewById(R.id.home_agenda_alerts).setOnClickListener(this::agendaAlertsOnClick);
    swipeRefreshLayout.setRefreshing(true);
    swipeRefreshLayout.setOnRefreshListener(this::onRefresh);
    offlineMode = activity.getIntent().getBooleanExtra("offline", false);
    addVoteNotRelevantForMean = SettingsData.getSettingBoolean(activity, SettingKey.VOTE_NRFM_ON_CHART);
    new Thread(() -> {
        if (offlineMode) {
            activity.runOnUiThread(() -> txUserInfo.setText("Accesso eseguito in modalità Offline"));
        } else {
            String userType = GlobalVariables.gS.getUserTypeString();
            activity.runOnUiThread(() -> txUserInfo.setText("Accesso eseguito nell'account " + GlobalVariables.gS.getUser() + " (" + userType + ")"));
        }
        AppUpdateManager manager = new AppUpdateManager(activity);
        if (manager.checkForUpdates()) {
            activity.runOnUiThread(() -> {
                loggerManager.d("Rendo visibile avviso su home dell'aggiornamento");
                root.findViewById(R.id.home_app_update_reminder).setVisibility(View.VISIBLE);
                root.findViewById(R.id.home_app_update_reminder).setOnClickListener(this::updateReminderOnClick);
            });
        }
    }).start();
    return root;
}
Also used : LoggerManager(com.giua.app.LoggerManager) LinearLayout(android.widget.LinearLayout) AppUpdateManager(com.giua.app.AppUpdateManager) Nullable(androidx.annotation.Nullable)

Example 17 with LoggerManager

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

the class LoginActivity method onBackPressed.

/**
 * Esci dall'applicazione simulando la pressione del tasto home
 */
@Override
public void onBackPressed() {
    if (!isAddingAccount) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } else {
        GlobalVariables.gsThread.addTask(() -> {
            String username = AppData.getActiveUsername(this);
            GlobalVariables.gS = new GiuaScraper(username, AccountData.getPassword(this, username), AccountData.getCookie(this, username), true, SettingsData.getSettingBoolean(this, SettingKey.DEMO_MODE), new LoggerManager("GiuaScraper", this));
            GlobalVariables.gS.login();
            runOnUiThread(this::startDrawerActivity);
        });
    }
}
Also used : LoggerManager(com.giua.app.LoggerManager) Intent(android.content.Intent) GiuaScraper(com.giua.webscraper.GiuaScraper)

Example 18 with LoggerManager

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

the class StudentLoginActivity method onStoppedWebView.

private void onStoppedWebView(boolean increaseVisitCount) {
    loggerManager.d("onStoppedWebView chiamato");
    if (increaseVisitCount)
        new Analytics.Builder(Analytics.LOG_IN).addCustomValue("account_type", "Studente (Google)").send();
    webView.setVisibility(View.INVISIBLE);
    obscureLayoutView.setVisibility(View.VISIBLE);
    loggerManager.d("Creazione credenziali con cookie ottenuto da google");
    GlobalVariables.gS = new GiuaScraper("gsuite", "gsuite", cookie, true, new LoggerManager("GiuaScraper", this));
    AccountData.setCredentials(this, "gsuite", "gsuite", cookie, "Studente", "");
    AccountData.setSiteUrl(this, "gsuite", GiuaScraper.getGlobalSiteUrl());
    GlobalVariables.gsThread.addTask(() -> {
        try {
            String email = GlobalVariables.gS.getProfilePage(false).getProfileInformation()[2];
            runOnUiThread(() -> AccountData.setEmail(this, "gsuite", email));
        } catch (Exception ignored) {
        }
    });
    obscureLayoutView.setVisibility(View.GONE);
    loggerManager.d("Avvio DrawerActivity");
    if (!AppData.getAllAccountUsernames(this).contains("gsuite")) {
        AppData.addAccountUsername(this, "gsuite");
        if (!isRequestedFromAccounts)
            AppData.saveActiveUsername(this, "gsuite");
    }
    if (goTo == null)
        goTo = "";
    if (isRequestedFromAccounts) {
        webView.clearHistory();
        onBackPressed();
        return;
    }
    Intent intent = new Intent(this, DrawerActivity.class).putExtra("goTo", goTo);
    startActivity(intent);
    finish();
}
Also used : LoggerManager(com.giua.app.LoggerManager) Intent(android.content.Intent) Analytics(com.giua.app.Analytics) GiuaScraper(com.giua.webscraper.GiuaScraper)

Example 19 with LoggerManager

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

the class TransparentUpdateDialogActivity method onCreate.

// TODO: Rendere questa activity universale per qualsiasi dialogo a cui serva una activity trasparente
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transparent);
    loggerManager = new LoggerManager("TrasparentUpdateDialogActivity", this);
    loggerManager.d("onCreate chiamato");
    String json = getIntent().getStringExtra("json");
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        rootNode = objectMapper.readTree(json);
    } catch (IOException e) {
        loggerManager.e("Impossibile leggere json! - " + e.getMessage());
        e.printStackTrace();
        finish();
    }
    url = Objects.requireNonNull(rootNode).get(0).findPath("browser_download_url").asText();
    tagName = rootNode.get(0).findPath("tag_name").asText();
    date = Calendar.getInstance();
    if (getIntent().getBooleanExtra("doUpdate", false)) {
        showDialogNewUpdate();
        return;
    }
    showDialogUpdateChangelog();
}
Also used : LoggerManager(com.giua.app.LoggerManager) SpannableString(android.text.SpannableString) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with LoggerManager

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

the class AgendaView method initializeComponent.

private void initializeComponent(Context context) {
    // Rappresenta il giorno del compito o della verifica
    Calendar objectDay = Calendar.getInstance();
    loggerManager = new LoggerManager("AgendaView", context);
    LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layoutInflater.inflate(R.layout.view_agenda, this);
    TextView tvTime = findViewById(R.id.agenda_view_time);
    TextView tvDate = findViewById(R.id.agenda_view_date);
    TextView tvSubject = findViewById(R.id.agenda_view_subject);
    TextView tvTeacher = findViewById(R.id.agenda_view_teacher);
    TextView tvText = findViewById(R.id.agenda_view_text);
    TextView tvType = findViewById(R.id.agenda_view_type);
    LinearLayout layout = findViewById(R.id.agenda_view_layout);
    if (getRepresentedObject() == Homework.class) {
        Homework homework = (Homework) agendaObject;
        objectDay.set(Integer.parseInt(homework.year), Integer.parseInt(homework.month) - 1, Integer.parseInt(homework.day), 23, 59, 59);
        tvDate.setText(homework.day + "-" + homework.month + "-" + homework.year);
        tvType.setText(R.string.agenda_view_type_homeworks);
        tvText.setText(homework.details);
        tvSubject.setText(homework.subject.split(": ")[1]);
        tvTeacher.setText(homework.creator);
        layout.setBackgroundTintList(ResourcesCompat.getColorStateList(getResources(), R.color.adaptive_agenda_views_cyan, context.getTheme()));
    } else if (getRepresentedObject() == Test.class) {
        Test test = (Test) agendaObject;
        objectDay.set(Integer.parseInt(test.year), Integer.parseInt(test.month) - 1, Integer.parseInt(test.day), 23, 59, 59);
        tvDate.setText(test.day + "-" + test.month + "-" + test.year);
        tvType.setText(R.string.agenda_view_type_tests);
        tvText.setText(test.details);
        tvSubject.setText(test.subject);
        tvTeacher.setText(test.creator);
        layout.setBackgroundTintList(ResourcesCompat.getColorStateList(getResources(), R.color.adaptive_agenda_views_orange, context.getTheme()));
    } else if (getRepresentedObject() == com.giua.objects.Activity.class) {
        com.giua.objects.Activity activity = (com.giua.objects.Activity) agendaObject;
        objectDay.set(Integer.parseInt(activity.year), Integer.parseInt(activity.month) - 1, Integer.parseInt(activity.day), 23, 59, 59);
        tvDate.setText(activity.day + "-" + activity.month + "-" + activity.year);
        tvType.setText(R.string.agenda_view_type_activities);
        tvText.setText(activity.details);
        tvSubject.setVisibility(GONE);
        tvTeacher.setVisibility(GONE);
        layout.setBackgroundTintList(ResourcesCompat.getColorStateList(getResources(), R.color.adaptive_agenda_views_green, context.getTheme()));
    } else if (getRepresentedObject() == InterviewAgenda.class) {
        InterviewAgenda test = (InterviewAgenda) agendaObject;
        objectDay.set(Integer.parseInt(test.year), Integer.parseInt(test.month) - 1, Integer.parseInt(test.day), 23, 59, 59);
        tvDate.setText(test.day + "-" + test.month + "-" + test.year);
        tvType.setText(R.string.agenda_view_type_interviews);
        tvText.setText(test.details);
        tvSubject.setText(test.period);
        tvTeacher.setText(test.creator);
        layout.setBackgroundTintList(ResourcesCompat.getColorStateList(getResources(), R.color.adaptive_agenda_views_purple, context.getTheme()));
    }
    // Calendar fake = Calendar.getInstance();
    // fake.set(Calendar.MONTH, 11);
    // fake.set(Calendar.DAY_OF_MONTH, 29);
    int timeDiff = calcTimeDifferenceInDay(Calendar.getInstance(), objectDay);
    loggerManager.d("mancano " + timeDiff + " giorni al compito del " + objectDay.get(Calendar.DAY_OF_MONTH) + "/" + objectDay.get(Calendar.MONTH) + "/" + objectDay.get(Calendar.YEAR));
    if (timeDiff < 0)
        if (timeDiff == -1)
            tvTime.setText("Ieri");
        else
            tvTime.setText(Math.abs(timeDiff) + " giorni fa");
    else {
        switch(timeDiff) {
            case 3:
                tvTime.setTextColor(getResources().getColor(R.color.middle_vote_lighter, context.getTheme()));
                tvTime.setText("Tra " + timeDiff + " giorni");
                break;
            case 2:
                tvTime.setTextColor(getResources().getColor(R.color.middle_vote_no_night, context.getTheme()));
                tvTime.setText("Tra " + timeDiff + " giorni");
                break;
            case 1:
                tvTime.setTextColor(getResources().getColor(R.color.bad_vote, context.getTheme()));
                tvTime.setText("Domani");
                break;
            case 0:
                tvTime.setTextColor(getResources().getColor(R.color.bad_vote, context.getTheme()));
                tvTime.setText("Oggi");
                break;
            default:
                tvTime.setText("Tra " + timeDiff + " giorni");
                break;
        }
    }
}
Also used : Calendar(java.util.Calendar) Test(com.giua.objects.Test) InterviewAgenda(com.giua.objects.InterviewAgenda) LayoutInflater(android.view.LayoutInflater) LoggerManager(com.giua.app.LoggerManager) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) Homework(com.giua.objects.Homework)

Aggregations

LoggerManager (com.giua.app.LoggerManager)20 Intent (android.content.Intent)6 TextView (android.widget.TextView)5 GiuaScraper (com.giua.webscraper.GiuaScraper)5 SimpleDateFormat (java.text.SimpleDateFormat)5 GiuaScraperThread (com.giua.app.GiuaScraperThread)4 R (com.giua.app.R)4 SuppressLint (android.annotation.SuppressLint)3 Bundle (android.os.Bundle)3 View (android.view.View)3 LinearLayout (android.widget.LinearLayout)3 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 Context (android.content.Context)2 SpannableString (android.text.SpannableString)2 LayoutInflater (android.view.LayoutInflater)2 ProgressBar (android.widget.ProgressBar)2 ResourcesCompat (androidx.core.content.res.ResourcesCompat)2 Analytics (com.giua.app.Analytics)2