Search in sources :

Example 11 with LoggerManager

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

the class AutomaticLoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_automatic_login);
    loggerManager = new LoggerManager("AutomaticLoginActivity", this);
    loggerManager.d("onCreate chiamato");
    btnLogout = findViewById(R.id.loading_screen_logout_btn);
    tvAutoLogin = findViewById(R.id.loading_screen_minor_text_view);
    pbLoadingScreen = findViewById(R.id.loading_screen_progressbar);
    btnOffline = findViewById(R.id.loading_screen_offline_btn);
    btnOffline.setOnClickListener(this::btnOfflineOnClick);
    btnLogout.setOnClickListener(this::btnLogoutOnClick);
    findViewById(R.id.loading_screen_btn_settings).setOnClickListener(this::btnSettingOnClick);
    GiuaScraper.setDebugMode(true);
    loginWithPreviousCredentials();
}
Also used : LoggerManager(com.giua.app.LoggerManager)

Example 12 with LoggerManager

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

the class AutomaticLoginActivity method loginWithPreviousCredentials.

private void loginWithPreviousCredentials() {
    if (GlobalVariables.gsThread == null || GlobalVariables.gsThread.isInterrupted() || GlobalVariables.gsThread.isInterrupting())
        GlobalVariables.gsThread = new GiuaScraperThread();
    loggerManager.d("Login automatico con credenziali salvate in corso");
    GlobalVariables.gsThread.addTask(() -> {
        runOnUiThread(() -> pbLoadingScreen.setVisibility(View.VISIBLE));
        try {
            String username = AppData.getActiveUsername(this);
            String password = AccountData.getPassword(this, username);
            String cookie = AccountData.getCookie(this, username);
            String savedSiteUrl = AccountData.getSiteUrl(this, username);
            GlobalVariables.gS = new GiuaScraper(username, password, cookie, true, SettingsData.getSettingBoolean(this, SettingKey.DEMO_MODE), new LoggerManager("GiuaScraper", this));
            if (!savedSiteUrl.equals(""))
                GlobalVariables.gS.setPrivateSiteUrl(savedSiteUrl);
            GlobalVariables.gS.login();
            AccountData.setCredentials(this, username, password, GlobalVariables.gS.getCookie(), GlobalVariables.gS.getUserTypeString(), GlobalVariables.gS.getProfilePage(false).getProfileInformation()[2]);
            AccountData.setSiteUrl(this, username, GlobalVariables.gS.getSiteUrl());
            if (!AppData.getAllAccountUsernames(this).contains(username))
                AppData.addAccountUsername(this, username);
            startDrawerActivity();
        } catch (GiuaScraperExceptions.YourConnectionProblems | GiuaScraperExceptions.SiteConnectionProblems e) {
            loggerManager.e("Errore di connessione - " + e.getMessage());
            loggerManager.e(Arrays.toString(e.getStackTrace()));
            runOnUiThread(() -> btnLogout.setVisibility(View.VISIBLE));
            runOnUiThread(() -> btnOffline.setVisibility(View.VISIBLE));
            if (SettingsData.getSettingBoolean(this, SettingKey.EXP_MODE))
                runOnUiThread(() -> btnOffline.setVisibility(View.VISIBLE));
            if (e.getClass() == GiuaScraperExceptions.YourConnectionProblems.class)
                runOnUiThread(() -> setErrorMessage(getString(R.string.your_connection_error)));
            else if (e.getClass() == GiuaScraperExceptions.SiteConnectionProblems.class)
                runOnUiThread(() -> setErrorMessage(getString(R.string.site_connection_error)));
            else
                runOnUiThread(() -> setErrorMessage("E' stato riscontrato qualche problema sconosciuto riguardo la rete"));
            runOnUiThread(() -> pbLoadingScreen.setVisibility(View.INVISIBLE));
            threadSleepWithTextUpdates();
            if (waitToReLogin < 30)
                waitToReLogin += 5;
            loginWithPreviousCredentials();
        } catch (GiuaScraperExceptions.SessionCookieEmpty sce) {
            // Se il login non dovesse funzionare lancia l acitvity di login ed elimina le credenziali salvate
            if (AppData.getActiveUsername(this).equals("gsuite")) {
                // Questa condizione si verifica quando è presente un acccount studente con il cookie scaduto
                loggerManager.w("Cookie gS dell'account studente scaduto, avvio StudentLoginActivity");
                startStudentLoginActivity();
            } else {
                loggerManager.w("Cookie gS scaduto, avvio ActivityManager");
                AppData.removeAccountUsername(this, AppData.getActiveUsername(this));
                AppData.saveActiveUsername(this, "");
                setErrorMessage("Le credenziali di accesso non sono più valide");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                startActivity(new Intent(AutomaticLoginActivity.this, ActivityManager.class));
            }
        } catch (GiuaScraperExceptions.MaintenanceIsActiveException e) {
            loggerManager.e("Errore: sito in manutenzione");
            try {
                Maintenance maintenance = GlobalVariables.gS.getMaintenanceInfo();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
                runOnUiThread(() -> setErrorMessage("Il sito è in manutenzione sino alle " + simpleDateFormat.format(maintenance.end)));
            } catch (Exception e2) {
                loggerManager.e("Errore nel ricevere informazioni manutenzione: " + e.getMessage());
                runOnUiThread(() -> setErrorMessage(getString(R.string.maintenance_is_active_error)));
            }
            runOnUiThread(() -> btnLogout.setVisibility(View.VISIBLE));
            if (SettingsData.getSettingBoolean(this, SettingKey.EXP_MODE))
                runOnUiThread(() -> btnOffline.setVisibility(View.VISIBLE));
            runOnUiThread(() -> pbLoadingScreen.setVisibility(View.GONE));
            runOnUiThread(() -> tvAutoLogin.setText("Accesso fallito."));
        }
    });
    if (SettingsData.getSettingBoolean(this, SettingKey.EXP_MODE)) {
        new Thread(() -> {
            // mostra il pulsante per l'offline dopo 5 secondi
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            runOnUiThread(() -> {
                btnOffline.setVisibility(View.INVISIBLE);
                btnOffline.setAlpha(0f);
                btnOffline.animate().alpha(1f).setDuration(400);
                btnOffline.setVisibility(View.VISIBLE);
            });
        }).start();
    }
}
Also used : Intent(android.content.Intent) Maintenance(com.giua.objects.Maintenance) GiuaScraperThread(com.giua.app.GiuaScraperThread) GiuaScraperThread(com.giua.app.GiuaScraperThread) LoggerManager(com.giua.app.LoggerManager) GiuaScraperExceptions(com.giua.webscraper.GiuaScraperExceptions) SimpleDateFormat(java.text.SimpleDateFormat) GiuaScraper(com.giua.webscraper.GiuaScraper)

Example 13 with LoggerManager

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

the class BugReportActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bugreport);
    lm = new LoggerManager("BugReportActivity", this);
    btnSend = findViewById(R.id.btn_bug_send);
    btnCancel = findViewById(R.id.btn_bug_cancel);
    txBugTitle = findViewById(R.id.txtBugTitle);
    txBugDesc = findViewById(R.id.txtBugDesc);
    txBugDesc2 = findViewById(R.id.txtBugDesc2);
    progressBar = findViewById(R.id.bug_progressbar);
    btnSend.setOnClickListener(v -> onSendBug());
    btnCancel.setOnClickListener(v -> exitActivity());
    dontStealMePlease = BuildConfig.SECRET_KEY;
    fromCAOC = getIntent().getBooleanExtra("fromCAOC", false);
    if (fromCAOC) {
        stacktrace = getIntent().getStringExtra("stacktrace");
    }
}
Also used : LoggerManager(com.giua.app.LoggerManager)

Example 14 with LoggerManager

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

the class CaocActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_caoc);
    loggerManager = new LoggerManager("ErrorHandler", CaocActivity.this);
    loggerManager.d("onCreate chiamato");
    loggerManager.e("-.@CRASH");
    loggerManager.d("Costruzione activity error handler");
    Button restartButton = findViewById(R.id.caoc_restart_btn);
    Button reportCrash = findViewById(R.id.caoc_report_btn);
    final CaocConfig config = CustomActivityOnCrash.getConfigFromIntent(getIntent());
    if (config == null) {
        // This should never happen - Just finish the activity to avoid a recursive crash.
        loggerManager.e("Errore Critico: Config di CAOC è null. Impossibile continuare");
        finish();
        return;
    }
    restartButton.setText(R.string.customactivityoncrash_error_activity_restart_app);
    restartButton.setOnClickListener(v -> {
        loggerManager.w("Riavvio app");
        Intent intent = new Intent(this, ActivityManager.class);
        intent.putExtra("fromCAOC", true);
        intent.putExtra("stacktrace", getAllErrorDetailsFromIntent(getIntent()));
        CustomActivityOnCrash.restartApplicationWithIntent(this, intent, config);
    });
    /*if (config.isShowRestartButton() && config.getRestartActivityClass() != null) {
            restartButton.setText(R.string.customactivityoncrash_error_activity_restart_app);
            restartButton.setOnClickListener(v -> {
                loggerManager.w("Riavvio app");
                CustomActivityOnCrash.restartApplication(CaocActivity.this, config);
            });
        } else {
            restartButton.setOnClickListener(v -> {
                loggerManager.w("Chiusura app");
                CustomActivityOnCrash.closeApplication(CaocActivity.this, config);
            });
        }*/
    Button moreInfoButton = findViewById(R.id.caoc_error_info_btn);
    moreInfoButton.setOnClickListener(v -> {
        AlertDialog dialog = new AlertDialog.Builder(CaocActivity.this).setTitle(R.string.customactivityoncrash_error_activity_error_details_title).setMessage(getAllErrorDetailsFromIntent(getIntent())).setPositiveButton(R.string.customactivityoncrash_error_activity_error_details_close, null).setNeutralButton(R.string.customactivityoncrash_error_activity_error_details_copy, (dialog1, which) -> copyErrorToClipboard()).show();
        TextView textView = dialog.findViewById(android.R.id.message);
        if (textView != null) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.customactivityoncrash_error_activity_error_details_text_size));
        }
    });
    Integer defaultErrorActivityDrawableId = config.getErrorDrawable();
    ImageView errorImageView = findViewById(R.id.caoc_image);
    if (defaultErrorActivityDrawableId != null) {
        errorImageView.setImageDrawable(ResourcesCompat.getDrawable(getResources(), defaultErrorActivityDrawableId, getTheme()));
    }
    reportCrash.setOnClickListener(v -> {
        loggerManager.d("Avvio BugReportActivity in un nuovo processo");
        Intent intent = new Intent(this, BugReportActivity.class);
        intent.putExtra("fromCAOC", true);
        intent.putExtra("stacktrace", getAllErrorDetailsFromIntent(getIntent()));
        CustomActivityOnCrash.restartApplicationWithIntent(this, intent, config);
    });
    findViewById(R.id.caoc_settings_btn).setOnClickListener(this::btnSettingOnClick);
    AppData.saveCrashStatus(this, true);
    loggerManager.e(getAllErrorDetailsFromIntent(getIntent()));
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) CaocConfig(cat.ereza.customactivityoncrash.config.CaocConfig) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) ResourcesCompat(androidx.core.content.res.ResourcesCompat) NonNull(androidx.annotation.NonNull) Date(java.util.Date) ImageView(android.widget.ImageView) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) R(com.giua.app.R) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AppData(com.giua.app.AppData) ClipData(android.content.ClipData) ActivityManager(com.giua.app.ActivityManager) Locale(java.util.Locale) Toast(android.widget.Toast) ClipboardManager(android.content.ClipboardManager) View(android.view.View) Button(android.widget.Button) Build(android.os.Build) DateFormat(java.text.DateFormat) BuildConfig(com.giua.app.BuildConfig) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) CustomActivityOnCrash(cat.ereza.customactivityoncrash.CustomActivityOnCrash) TypedValue(android.util.TypedValue) LoggerManager(com.giua.app.LoggerManager) CaocConfig(cat.ereza.customactivityoncrash.config.CaocConfig) Button(android.widget.Button) LoggerManager(com.giua.app.LoggerManager) Intent(android.content.Intent) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 15 with LoggerManager

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

the class DrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (savedInstanceState != null)
        savedInstanceState.clear();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_drawer);
    loggerManager = new LoggerManager("DrawerActivity", this);
    loggerManager.d("onCreate chiamato");
    offlineMode = getIntent().getBooleanExtra("offline", false);
    demoMode = SettingsData.getSettingBoolean(this, SettingKey.DEMO_MODE);
    goTo = getIntent().getStringExtra("goTo");
    notificationsDBController = new NotificationsDBController(this);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (GlobalVariables.gsThread == null || GlobalVariables.gsThread.isInterrupted())
        GlobalVariables.gsThread = new GiuaScraperThread();
    if (GlobalVariables.gS == null) {
        loggerManager.w("gs è null ma non dovrebbe esserlo quindi avvio AutomaticLogin");
        startActivityManager();
        return;
    }
    if (!offlineMode) {
        GlobalVariables.gsThread.addTask(() -> {
            if (!GlobalVariables.gS.isSessionValid(GlobalVariables.gS.getCookie())) {
                runOnUiThread(this::startActivityManager);
            }
        });
    }
    myFragmentManager = new MyFragmentManager(this, toolbar, getSupportFragmentManager(), offlineMode, demoMode, unstableFeatures);
    myDrawerManager = new MyDrawerManager(this, this::onChangeAccountFromDrawer, this::settingsItemOnClick, this::logoutItemOnClick, realUsername, userType, toolbar, myFragmentManager, demoMode);
    if (goTo == null || goTo.equals(""))
        myFragmentManager.changeFragment(R.id.nav_home);
    else if (goTo.equals(AppNotificationsParams.NEWSLETTERS_NOTIFICATION_GOTO))
        myFragmentManager.changeFragment(R.id.nav_newsletters);
    else if (goTo.equals(AppNotificationsParams.ALERTS_NOTIFICATION_GOTO))
        myFragmentManager.changeFragment(R.id.nav_alerts);
    else if (goTo.equals(AppNotificationsParams.VOTES_NOTIFICATION_GOTO))
        myFragmentManager.changeFragment(R.id.nav_votes);
    else if (goTo.equals(AppNotificationsParams.AGENDA_NOTIFICATION_GOTO))
        myFragmentManager.changeFragment(R.id.nav_agenda);
    else
        myFragmentManager.changeFragment(R.id.nav_home);
    setupAppNotifications();
    getAndSetupUsernameUsertype();
    new Thread(() -> {
        // Anche se siamo in offline mode, proviamo a scaricarle comunque (magari il registro è in manutenzione)
        loggerManager.d("Scarico le informazioni sulle funzionalità instabili");
        try {
            unstableFeatures = GiuaScraper.getExtPage("https://giua-app.github.io/unstable_features2.txt").text();
            myFragmentManager.unstableFeatures = unstableFeatures;
        } catch (Exception ignored) {
        }
    }).start();
    checkForUpdateChangelog();
}
Also used : NotificationsDBController(com.giua.app.NotificationsDBController) GiuaScraperThread(com.giua.app.GiuaScraperThread) MyFragmentManager(com.giua.app.MyFragmentManager) LoggerManager(com.giua.app.LoggerManager) MyDrawerManager(com.giua.app.MyDrawerManager) GiuaScraperThread(com.giua.app.GiuaScraperThread)

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