use of com.giua.app.LoggerManager in project Giua-App by Giua-app.
the class LoginActivity method login.
private void login() {
if (GlobalVariables.gsThread == null || GlobalVariables.gsThread.isInterrupted())
GlobalVariables.gsThread = new GiuaScraperThread();
GlobalVariables.gsThread.addTask(() -> {
try {
if (isAddingAccount && AppData.getAllAccountUsernames(this).contains(etUsername.getText().toString().toLowerCase())) {
runOnUiThread(() -> {
txtLayoutUsername.setError("Username già salvato");
etPassword.setText("");
pgProgressBar.setVisibility(View.INVISIBLE);
btnLogin.setVisibility(View.VISIBLE);
});
return;
}
loggerManager.d("Eseguo login...");
GlobalVariables.gS = new GiuaScraper(etUsername.getText().toString(), etPassword.getText().toString(), true, SettingsData.getSettingBoolean(this, SettingKey.DEMO_MODE), new LoggerManager("GiuaScraper", this));
GlobalVariables.gS.login();
loggerManager.d("Devo ricordare le credenziali? " + chRememberCredentials.isChecked());
if (GlobalVariables.gS.isSessionValid(GlobalVariables.gS.getCookie())) {
if (chRememberCredentials.isChecked()) {
AccountData.setCredentials(this, etUsername.getText().toString(), etPassword.getText().toString(), GlobalVariables.gS.getCookie(), GlobalVariables.gS.getUserTypeString(), GlobalVariables.gS.getProfilePage(false).getProfileInformation()[2]);
AccountData.setSiteUrl(this, etUsername.getText().toString(), GlobalVariables.gS.getSiteUrl());
AppData.addAccountUsername(this, etUsername.getText().toString().toLowerCase());
AppData.saveActiveUsername(this, etUsername.getText().toString().toLowerCase());
}
startDrawerActivity();
} else {
loggerManager.e("Errore sconosciuto, login eseguito ma checkLogin ritorna false");
setErrorMessage("Qualcosa e' andato storto!");
this.runOnUiThread(() -> {
txtLayoutPassword.setError("Riprova");
etPassword.setText("");
btnLogin.setVisibility(View.VISIBLE);
pgProgressBar.setVisibility(View.INVISIBLE);
});
}
} catch (GiuaScraperExceptions.SessionCookieEmpty e) {
loggerManager.e("Errore: il sito dice: " + e.siteSays);
if (e.siteSays.equals("Tipo di utente non ammesso: usare l'autenticazione tramite GSuite.")) {
loggerManager.d("Rilevato credenziali account google");
startStudentLoginActivity();
} else {
loggerManager.e("Errore: credenziali errate");
setErrorMessage("Credenziali di login errate!");
this.runOnUiThread(() -> {
etPassword.setText("");
txtLayoutPassword.setError("Password o Username errato");
pgProgressBar.setVisibility(View.INVISIBLE);
btnLogin.setVisibility(View.VISIBLE);
});
}
} catch (GiuaScraperExceptions.UnableToLogin e) {
loggerManager.e("Errore sconosciuto - " + e.getMessage());
setErrorMessage("E' stato riscontrato qualche problema sconosciuto");
this.runOnUiThread(() -> {
etPassword.setText("");
pgProgressBar.setVisibility(View.INVISIBLE);
btnLogin.setVisibility(View.VISIBLE);
});
} catch (GiuaScraperExceptions.MaintenanceIsActiveException e) {
loggerManager.e("Errore: Manutenzione attiva");
try {
Maintenance maintenance = GlobalVariables.gS.getMaintenanceInfo();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm", Locale.ITALY);
runOnUiThread(() -> setErrorMessage("Il sito è in manutenzione sino alle " + simpleDateFormat.format(maintenance.end)));
} catch (Exception e2) {
runOnUiThread(() -> setErrorMessage(getString(R.string.maintenance_is_active_error)));
}
this.runOnUiThread(() -> {
etPassword.setText("");
txtLayoutPassword.setError("In manutenzione, riprova più tardi!");
pgProgressBar.setVisibility(View.INVISIBLE);
btnLogin.setVisibility(View.VISIBLE);
});
} catch (GiuaScraperExceptions.YourConnectionProblems e) {
loggerManager.e("Errore di connessione dell'utente");
setErrorMessage(getString(R.string.your_connection_error));
this.runOnUiThread(() -> {
etPassword.setText("");
txtLayoutPassword.setError("C'è un problema con la tua rete");
pgProgressBar.setVisibility(View.INVISIBLE);
btnLogin.setVisibility(View.VISIBLE);
});
} catch (GiuaScraperExceptions.SiteConnectionProblems e) {
loggerManager.e("Errore di connessione da parte del server");
setErrorMessage(getString(R.string.site_connection_error));
this.runOnUiThread(() -> {
etPassword.setText("");
txtLayoutPassword.setError("Errore di connesione al registro");
pgProgressBar.setVisibility(View.INVISIBLE);
btnLogin.setVisibility(View.VISIBLE);
});
}
});
}
use of com.giua.app.LoggerManager in project Giua-App by Giua-app.
the class LoginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if (GlobalVariables.gsThread == null || GlobalVariables.gsThread.isInterrupted())
GlobalVariables.gsThread = new GiuaScraperThread();
isAddingAccount = getIntent().getBooleanExtra("addAccount", false);
loggerManager = new LoggerManager("LoginActivity", this);
loggerManager.d("onCreate chiamato");
txtLayoutUsername = findViewById(R.id.login_txtlayout_user);
txtLayoutPassword = findViewById(R.id.login_txtlayout_password);
txtCardTitle = findViewById(R.id.login_card_title);
etUsername = txtLayoutUsername.getEditText();
etPassword = txtLayoutPassword.getEditText();
pgProgressBar = findViewById(R.id.progressBar);
btnLogin = findViewById(R.id.login_button);
chRememberCredentials = findViewById(R.id.checkbox_remember_credentials);
btnLoginAsStudent = findViewById(R.id.btn_student_login);
btnLoginAsStudent.setText(Html.fromHtml("<p>Sei uno studente?\n<u><i>Clicca qui!</i></u></p>", 0));
Objects.requireNonNull(txtLayoutUsername.getEditText()).addTextChangedListener(onTextChange(txtLayoutUsername));
Objects.requireNonNull(txtLayoutPassword.getEditText()).addTextChangedListener(onTextChange(txtLayoutPassword));
findViewById(R.id.login_btn_settings).setOnClickListener(this::btnSettingOnClick);
btnLogin.setOnClickListener(this::btnLoginOnClick);
btnLoginAsStudent.setOnClickListener(this::btnLoginAsStudentOnClick);
checkDisplayMetrics();
checkForUpdateChangelog();
GlobalVariables.gsThread.addTask(() -> {
try {
if (!GiuaScraper.isGoogleLoginAvailable())
runOnUiThread(() -> btnLoginAsStudent.setVisibility(View.INVISIBLE));
} catch (Exception ignored) {
}
});
new Thread(() -> {
try {
String str = GiuaScraper.getSchoolName();
runOnUiThread(() -> txtCardTitle.setText("Accesso a " + str));
} catch (Exception e) {
runOnUiThread(() -> txtCardTitle.setText("Accesso al registro"));
}
}).start();
if (isAddingAccount) {
btnLogin.setText("Aggiungi account");
chRememberCredentials.setChecked(true);
chRememberCredentials.setVisibility(View.INVISIBLE);
}
}
use of com.giua.app.LoggerManager in project Giua-App by Giua-app.
the class StudentLoginActivity method onCreate.
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_login);
loggerManager = new LoggerManager("StudentLoginActivity", this);
loggerManager.d("onCreate chiamato");
goTo = getIntent().getStringExtra("goTo");
isRequestedFromAccounts = getIntent().getBooleanExtra("requested_from_accounts_activity", false);
webView = findViewById(R.id.studentWebView);
obscureLayoutView = findViewById(R.id.studentObscureLayoutView);
progressBar = findViewById(R.id.login_google_progress);
obscureLayoutView.setVisibility(View.GONE);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest request) {
loggerManager.d("Richiesto caricamento dell'url " + request.getUrl().toString());
String requestedUrl = request.getUrl().toString();
if (requestedUrl.equals(GiuaScraper.getGlobalSiteUrl() + "/") || requestedUrl.equals(GiuaScraper.getGlobalSiteUrl() + "/#")) {
loggerManager.d("Ottengo cookie del registro...");
String rawCookie = CookieManager.getInstance().getCookie(GiuaScraper.getGlobalSiteUrl());
if (rawCookie != null) {
cookie = rawCookie.split("=")[1];
onStoppedWebView(getIntent().getStringExtra("sender").equals("LoginActivity") || // Aumenta il conteggio solo se StudentLogin viene chiamata dal LoginActivity
getIntent().getStringExtra("sender").equals("AccountsActivity"));
return true;
}
loggerManager.e("Errore, cookie ottenuto è null. Impossibile continuare");
Analytics.sendDefaultRequest(Analytics.WEBVIEW_ERROR);
Snackbar.make(findViewById(android.R.id.content), "Login studente non disponibile, contatta gli sviluppatori", Snackbar.LENGTH_LONG).show();
}
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
loggerManager.d("Caricamento pagina " + url + " completato");
webView.setVisibility(View.VISIBLE);
}
});
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
progressBar.setProgress(newProgress);
}
});
webView.getSettings().setUserAgentString(userAgent);
webView.getSettings().setJavaScriptEnabled(true);
CookieManager.getInstance().setAcceptCookie(true);
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
webView.loadUrl(GiuaScraper.getGlobalSiteUrl() + "/login/gsuite");
}
use of com.giua.app.LoggerManager in project Giua-App by Giua-app.
the class AbsencesFragment method onCreateView.
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
root = inflater.inflate(R.layout.fragment_absences, container, false);
loggerManager = new LoggerManager("AbsencesFragment", getContext());
swipeRefreshLayout = root.findViewById(R.id.absences_refresh_layout);
tvConfirmText = root.findViewById(R.id.absences_confirm_text);
obscureLayoutView = root.findViewById(R.id.absences_obscure_view);
btnConfirm = root.findViewById(R.id.absences_confirm_button);
otherInfoLayoutButton = root.findViewById(R.id.absences_other_info_layout_button);
confirmLayout = root.findViewById(R.id.absences_confirm_layout);
tvNoElements = root.findViewById(R.id.absences_no_elements_text);
activity = requireActivity();
swipeRefreshLayout.setRefreshing(true);
swipeRefreshLayout.setOnRefreshListener(this::onRefresh);
obscureLayoutView.setOnClickListener(this::obscureViewOnClick);
btnConfirm.setOnClickListener(this::btnConfirmOnClick);
otherInfoLayoutButton.setOnClickListener(this::otherInfoOnClick);
offlineMode = activity.getIntent().getBooleanExtra("offline", false);
return root;
}
use of com.giua.app.LoggerManager in project Giua-App by Giua-app.
the class AgendaFragment method onCreateView.
@SuppressLint("SetTextI18n")
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
root = inflater.inflate(R.layout.fragment_agenda, container, false);
loggerManager = new LoggerManager("AgendaFragment", getContext());
loggerManager.d("onCreateView chiamato");
scrollView = root.findViewById(R.id.agenda_scroll_view);
calendarView = root.findViewById(R.id.agenda_calendar);
viewsLayout = root.findViewById(R.id.agenda_views_layout);
tvNoElements = root.findViewById(R.id.agenda_no_elements_text);
pbForDetails = root.findViewById(R.id.agenda_progress_bar_details);
swipeRefreshLayout = root.findViewById(R.id.agenda_swipe_refresh_layout);
activity = requireActivity();
allAgendaObjects = new Vector<>();
dateFormatForMonth = new SimpleDateFormat("MM", Locale.ITALIAN);
dateFormatForYear = new SimpleDateFormat("yyyy", Locale.ITALIAN);
offlineMode = activity.getIntent().getBooleanExtra("offline", false);
if (SettingsData.getSettingBoolean(requireActivity(), SettingKey.DEMO_MODE)) {
calendar = Calendar.getInstance();
calendar.set(2021, 11, 1);
currentDisplayedDate = calendar.getTime();
} else {
// No demo
calendar = Calendar.getInstance();
currentDisplayedDate = calendar.getTime();
currentDate = calendar;
}
calendarView = root.findViewById(R.id.agenda_calendar);
calendarView.setUseThreeLetterAbbreviation(true);
calendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
@Override
public void onDayClick(Date dateClicked) {
onDayChanged(dateClicked);
}
@Override
public void onMonthScroll(Date firstDayOfNewMonth) {
scrollView.requestDisallowInterceptTouchEvent(false);
swipeRefreshLayout.requestDisallowInterceptTouchEvent(false);
onMonthChanged(firstDayOfNewMonth);
}
});
((TextView) root.findViewById(R.id.agenda_calendar_month)).setText(getMonthFromNumber(Integer.parseInt(dateFormatForMonth.format(new Date()))));
((TextView) root.findViewById(R.id.agenda_calendar_year)).setText(dateFormatForYear.format(new Date()));
root.findViewById(R.id.agenda_prev_month).setOnClickListener((view -> calendarView.scrollLeft()));
root.findViewById(R.id.agenda_next_month).setOnClickListener((view -> calendarView.scrollRight()));
swipeRefreshLayout.setOnRefreshListener(this::onRefresh);
activity.getSystemService(NotificationManager.class).cancel(13);
activity.getSystemService(NotificationManager.class).cancel(14);
return root;
}
Aggregations