Add ability to change view mode

This commit is contained in:
Michael Schättgen 2019-04-01 01:21:12 +02:00
parent ee8fd2e9f2
commit f3ed79dc71
6 changed files with 80 additions and 0 deletions

View file

@ -61,6 +61,16 @@ public class Preferences {
} }
public int getCurrentViewMode() {
return _prefs.getInt("pref_current_view_mode", 0);
}
public void setCurrentViewMode(ViewMode viewMode) {
_prefs.edit().putInt("pref_current_view_mode", viewMode.ordinal()).apply();
}
public int getTimeout() { public int getTimeout() {
return _prefs.getInt("pref_timeout", -1); return _prefs.getInt("pref_timeout", -1);

View file

@ -0,0 +1,33 @@
package com.beemdevelopment.aegis;
public enum ViewMode {
NORMAL,
COMPACT;
public static ViewMode fromInteger(int x) {
switch(x) {
case 0:
return NORMAL;
case 1:
return COMPACT;
}
return null;
}
public static String getViewModeName(int x) {
switch(x) {
case 0:
return "Normal";
case 1:
return "Compact";
}
return null;
}
public static String[] getViewModeNames() {
return new String[] {
"Normal",
"Compact"
};
}
}

View file

@ -19,6 +19,7 @@ import android.widget.Toast;
import com.beemdevelopment.aegis.Preferences; import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.Theme; import com.beemdevelopment.aegis.Theme;
import com.beemdevelopment.aegis.ViewMode;
import com.beemdevelopment.aegis.db.DatabaseFileCredentials; import com.beemdevelopment.aegis.db.DatabaseFileCredentials;
import com.beemdevelopment.aegis.helpers.FingerprintHelper; import com.beemdevelopment.aegis.helpers.FingerprintHelper;
import com.beemdevelopment.aegis.helpers.PermissionHelper; import com.beemdevelopment.aegis.helpers.PermissionHelper;
@ -130,6 +131,33 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
} }
}); });
int currentViewMode = app.getPreferences().getCurrentViewMode();
Preference viewModePreference = findPreference("pref_view_mode");
viewModePreference.setSummary("Selected: " + ViewMode.getViewModeName(currentViewMode));
viewModePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String[] viewModes = ViewMode.getViewModeNames();
int checkedMode = app.getPreferences().getCurrentViewMode();
Dialogs.showSecureDialog(new AlertDialog.Builder(getActivity())
.setTitle(getString(R.string.choose_view_mode))
.setSingleChoiceItems(viewModes, checkedMode, (dialog, which) -> {
int i = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
app.getPreferences().setCurrentViewMode(ViewMode.fromInteger(i));
dialog.dismiss();
_result.putExtra("needsRecreate", true);
getActivity().recreate();
})
.setPositiveButton(android.R.string.ok, null)
.create());
return true;
}
});
Preference importPreference = findPreference("pref_import"); Preference importPreference = findPreference("pref_import");
importPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { importPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override @Override

View file

@ -12,6 +12,7 @@
<string name="settings">Предпочтения</string> <string name="settings">Предпочтения</string>
<string name="pref_select_theme_title">Тема</string> <string name="pref_select_theme_title">Тема</string>
<string name="pref_view_mode_title">Select view mode</string>
<string name="pref_account_name_title">Показать имя аккаунта</string> <string name="pref_account_name_title">Показать имя аккаунта</string>
<string name="pref_account_name_summary">Включите это, чтобы показать имя учетной записи рядом с эмитентом</string> <string name="pref_account_name_summary">Включите это, чтобы показать имя учетной записи рядом с эмитентом</string>
<string name="pref_timeout_title">Тайм-аут</string> <string name="pref_timeout_title">Тайм-аут</string>

View file

@ -12,6 +12,7 @@
<string name="settings">Preferences</string> <string name="settings">Preferences</string>
<string name="pref_select_theme_title">Theme</string> <string name="pref_select_theme_title">Theme</string>
<string name="pref_view_mode_title">View mode</string>
<string name="pref_account_name_title">Show the account name</string> <string name="pref_account_name_title">Show the account name</string>
<string name="pref_account_name_summary">Enable this to show the account name next to the issuer</string> <string name="pref_account_name_summary">Enable this to show the account name next to the issuer</string>
<string name="pref_timeout_title">Timeout</string> <string name="pref_timeout_title">Timeout</string>
@ -120,6 +121,7 @@
<string name="permission_denied">Permission denied</string> <string name="permission_denied">Permission denied</string>
<string name="choose_application">Select the application you\'d like to import a database from</string> <string name="choose_application">Select the application you\'d like to import a database from</string>
<string name="choose_theme">Select your desired theme</string> <string name="choose_theme">Select your desired theme</string>
<string name="choose_view_mode">Select your desired view mode</string>
<string name="parsing_file_error">An error occurred while trying to parse the file</string> <string name="parsing_file_error">An error occurred while trying to parse the file</string>
<string name="file_not_found">Error: File not found</string> <string name="file_not_found">Error: File not found</string>
<string name="reading_file_error">An error occurred while trying to read the file</string> <string name="reading_file_error">An error occurred while trying to read the file</string>

View file

@ -13,6 +13,12 @@
android:title="@string/pref_select_theme_title" android:title="@string/pref_select_theme_title"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>
<Preference
android:defaultValue="false"
android:key="pref_view_mode"
android:title="@string/pref_view_mode_title"
app:iconSpaceReserved="false"/>
<androidx.preference.SwitchPreferenceCompat <androidx.preference.SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:key="pref_account_name" android:key="pref_account_name"