Skip to content

Commit

Permalink
Added auto login, improved settings and translations
Browse files Browse the repository at this point in the history
Added:

- Auto-login feature.
- Auto-login option on settings screen.

Improved:

- Fixed portuguese translation for notifications of invalid data.
- Settings screen changes availability of other options according to the hierarchy [effects on user experience, only].
  • Loading branch information
mauromascarenhas committed Jun 14, 2019
1 parent 5d90d02 commit 48fda66
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class MainActivity extends AppCompatActivity
private SearchBookAdapter adapter;
private ArrayList<BookSearchProperties> availableBooks;

private boolean isFirstRequest;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -129,13 +131,16 @@ private void loadPreferences(){
GlobalVariables.ringAlarm = pref.getBoolean(getString(R.string.key_notification_enable_warning), true);
GlobalVariables.showExtWarning = pref.getBoolean(getString(R.string.key_general_leave_warning), true);
GlobalVariables.storeUserFormData = pref.getBoolean(getString(R.string.key_privacy_store_password), true);
GlobalVariables.loginAutomatically = pref.getBoolean(getString(R.string.key_privacy_auto_login), true);

String syncInterval = pref.getString(getString(R.string.key_notification_sync_interval), "2");
GlobalVariables.syncInterval = Integer.parseInt(syncInterval == null ? "2" : syncInterval);

String warningDelay = pref.getString(getString(R.string.key_notification_warning_delay), "0");
GlobalVariables.ringAlarmOffset = Integer.parseInt(warningDelay == null ? "0" : warningDelay);

isFirstRequest = true;

applyPreferences(pref);
}

Expand Down Expand Up @@ -399,6 +404,14 @@ private void setUserConnected(boolean connected){
navViewMenu.findItem(R.id.nav_logout).setVisible(connected);
navViewMenu.findItem(R.id.nav_renew).setVisible(connected);
navViewMenu.findItem(R.id.nav_reservation).setVisible(connected);

if (isFirstRequest){
if (!connected && GlobalVariables.loginAutomatically){
Intent acIntent = new Intent(this, LoginActivity.class);
startActivityForResult(acIntent, GlobalConstants.ACTIVITY_LOGIN_REQUEST_CODE);
}
isFirstRequest = false;
}
}

public void receiveError(String message){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nintersoft.bibliotecaufabc;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.ListPreference;
Expand All @@ -13,6 +14,8 @@
import android.preference.PreferenceManager;
import android.view.MenuItem;

import com.nintersoft.bibliotecaufabc.appcontext.ContextApp;

import java.util.List;

/**
Expand Down Expand Up @@ -151,13 +154,6 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
setHasOptionsMenu(true);

// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
//bindPreferenceSummaryToValue(findPreference("example_text"));
//bindPreferenceSummaryToValue(findPreference("example_list"));
}

@Override
Expand Down Expand Up @@ -188,6 +184,22 @@ public void onCreate(Bundle savedInstanceState) {
// guidelines.
bindPreferenceSummaryToValue(findPreference(getString(R.string.key_notification_warning_delay)));
bindPreferenceSummaryToValue(findPreference(getString(R.string.key_notification_sync_interval)));

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ContextApp.getContext());
boolean hasPasswordStored = preferences.getBoolean(getString(R.string.key_privacy_store_password), true);
findPreference(getString(R.string.key_notification_enable_warning)).setEnabled(hasPasswordStored);
findPreference(getString(R.string.key_notification_warning_delay)).setEnabled(hasPasswordStored);
findPreference(getString(R.string.key_notification_sync_interval)).setEnabled(hasPasswordStored);

findPreference(getString(R.string.key_notification_enable_warning))
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
findPreference(getString(R.string.key_notification_warning_delay)).setEnabled((Boolean)newValue);
findPreference(getString(R.string.key_notification_sync_interval)).setEnabled((Boolean)newValue);
return true;
}
});
}

@Override
Expand Down Expand Up @@ -217,6 +229,23 @@ public void onCreate(Bundle savedInstanceState) {
// updated to reflect the new value, per the Android Design
// guidelines.
bindPreferenceSummaryToValue(findPreference(getString(R.string.key_privacy_login_username)));

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ContextApp.getContext());
boolean hasPasswordStored = preferences.getBoolean(getString(R.string.key_privacy_store_password), true);
findPreference(getString(R.string.key_privacy_auto_login)).setEnabled(hasPasswordStored);
findPreference(getString(R.string.key_privacy_login_username)).setEnabled(hasPasswordStored);
findPreference(getString(R.string.key_privacy_login_password)).setEnabled(hasPasswordStored);

findPreference(getString(R.string.key_privacy_store_password))
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
findPreference(getString(R.string.key_privacy_auto_login)).setEnabled((Boolean)newValue);
findPreference(getString(R.string.key_privacy_login_username)).setEnabled((Boolean)newValue);
findPreference(getString(R.string.key_privacy_login_password)).setEnabled((Boolean)newValue);
return true;
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class GlobalVariables {
public static boolean ringAlarm = true;
public static boolean showExtWarning = true;
public static boolean storeUserFormData = true;
public static boolean loginAutomatically = true;

public static int syncInterval = 2;
public static int ringAlarmOffset = 0;
Expand Down
7 changes: 5 additions & 2 deletions BibliotecaUFABC/app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"Baixe-o em: https://play.google.com/store/apps/details?id=com.nintersoft.bibliotecaufabc"
</string>
<string name="pref_title_store_password">Armazenar senha</string>
<string name="pref_title_auto_login">Conectar automaticamente</string>
<string name="pref_title_share_app">Botão de compartilhamento do aplicativo</string>
<string name="pref_title_login_username">Usuário</string>
<string name="pref_title_login_password">Senha</string>
Expand All @@ -126,6 +127,8 @@
<string name="pref_summary_bug_report">Envie-nos um email reportanto possíveis problemas para que possamos resolvê-los.</string>
<string name="pref_summary_bug_intent_extra_subject">[ BUG REPORT ] Biblioteca UFABC</string>
<string name="pref_summary_privacy_policy">Visualise a política de privacidade do app em um navegador.</string>
<string name="pref_description_auto_login">Se você permitir que a aplicação salve suas credenciais,
ela poderá conectá-lo automaticamente (apenas quando iniciada através de seu lançador principal).</string>
<string name="label_renewal_connection_error">
"Parece que algo deu errado enquanto tentávamos nos comunicar com os servidores da universidade.\n\n"
"Detalhes do erro: %1$s.\n\n"
Expand Down Expand Up @@ -203,8 +206,8 @@
<string name="notification_syncing_message">Sincronizando dados de renovação&#8230;</string>
<string name="notification_sync_error_title">Biblioteca UFABC - Erro de sincronização</string>
<string name="notification_sync_error_message">Erro durante o processo de sincronização.
Seu nome de usuário e senha não são mais válidas. Por favor, tente reconectar na aplicação
assim poderemos sincronizar as renovações novamente.</string>
Suas credenciais de acesso (usuário e senha) não são mais válidas. Por favor, tente reconectar-se
à aplicação, assim poderemos sincronizar os dados de renovação novamente.</string>
<string name="notification_sync_denied_title">Biblioteca UFABC - Permissão negada</string>
<string name="notification_sync_denied_message">Como você negou a permissão,
infelizmente não poderemos sincronizar seus livros &#128557;</string>
Expand Down
2 changes: 2 additions & 0 deletions BibliotecaUFABC/app/src/main/res/values/setting_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<string name="key_privacy_cache_main_content" translatable="false">key_privacy_cache_main_content</string>

<string name="key_privacy_store_password" translatable="false">key_privacy_store_password</string>
<string name="key_privacy_auto_login" translatable="false">key_privacy_auto_login</string>

<string name="key_privacy_login_username" translatable="false">key_privacy_login_username</string>
<string name="key_privacy_login_password" translatable="false">key_privacy_login_password</string>

Expand Down
4 changes: 4 additions & 0 deletions BibliotecaUFABC/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@
<string name="pref_description_store_password">Allows the application to store your login data.
It makes the login process a bit faster for you. (See Privacy Policy for more details)</string>

<string name="pref_title_auto_login">Login automatically</string>
<string name="pref_description_auto_login">If the application have your credentials already saved,
it will be able to login automatically (only when started from your main launcher).</string>

<string name="pref_title_login_username">Username</string>
<string name="pref_title_login_password">Password</string>

Expand Down
6 changes: 6 additions & 0 deletions BibliotecaUFABC/app/src/main/res/xml/pref_privacy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
android:summary="@string/pref_description_store_password"
android:title="@string/pref_title_store_password" />

<SwitchPreference
android:defaultValue="true"
android:key="@string/key_privacy_auto_login"
android:summary="@string/pref_description_auto_login"
android:title="@string/pref_title_auto_login" />

<EditTextPreference
android:capitalize="none"
android:inputType="textAutoComplete"
Expand Down

0 comments on commit 48fda66

Please sign in to comment.