Skip to content

Commit

Permalink
Merge pull request #1162 from michaelschattgen/feature/account-name-p…
Browse files Browse the repository at this point in the history
…osition

Add ability to change account name position
  • Loading branch information
michaelschattgen committed Aug 17, 2023
2 parents 8c81ec0 + 813fd62 commit d3c4884
Show file tree
Hide file tree
Showing 49 changed files with 118 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.beemdevelopment.aegis;

public enum AccountNamePosition {
HIDDEN,
END,
BELOW;

private static AccountNamePosition[] _values;

static {
_values = values();
}

public static AccountNamePosition fromInteger(int x) {
return _values[x];
}
}
12 changes: 8 additions & 4 deletions app/src/main/java/com/beemdevelopment/aegis/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ public void resetPasswordReminderTimestamp() {
setPasswordReminderTimestamp(new Date().getTime());
}

public boolean isAccountNameVisible() {
return _prefs.getBoolean("pref_account_name", true);
}

public boolean isIconVisible() {
return _prefs.getBoolean("pref_show_icons", true);
}
Expand Down Expand Up @@ -189,6 +185,14 @@ public void setCurrentViewMode(ViewMode viewMode) {
_prefs.edit().putInt("pref_current_view_mode", viewMode.ordinal()).apply();
}

public AccountNamePosition getAccountNamePosition() {
return AccountNamePosition.fromInteger(_prefs.getInt("pref_account_name_position", AccountNamePosition.END.ordinal()));
}

public void setAccountNamePosition(AccountNamePosition accountNamePosition) {
_prefs.edit().putInt("pref_account_name_position", accountNamePosition.ordinal()).apply();
}

public Integer getUsageCount(UUID uuid) {
Integer usageCount = getUsageCounts().get(uuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.SearchView;

import com.beemdevelopment.aegis.AccountNamePosition;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.SortCategory;
Expand Down Expand Up @@ -131,7 +132,7 @@ protected void onCreate(Bundle savedInstanceState) {
_entryListView = (EntryListView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
_entryListView.setListener(this);
_entryListView.setCodeGroupSize(_prefs.getCodeGroupSize());
_entryListView.setShowAccountName(_prefs.isAccountNameVisible());
_entryListView.setAccountNamePosition(_prefs.getAccountNamePosition());
_entryListView.setShowIcon(_prefs.isIconVisible());
_entryListView.setHighlightEntry(_prefs.isEntryHighlightEnabled());
_entryListView.setPauseFocused(_prefs.isPauseFocusedEnabled());
Expand Down Expand Up @@ -269,7 +270,7 @@ private void onPreferencesResult(Intent data) {
if (data.getBooleanExtra("needsRecreate", false)) {
recreate();
} else if (data.getBooleanExtra("needsRefresh", false)) {
boolean showAccountName = _prefs.isAccountNameVisible();
AccountNamePosition accountNamePosition = _prefs.getAccountNamePosition();
boolean showIcons = _prefs.isIconVisible();
Preferences.CodeGrouping codeGroupSize = _prefs.getCodeGroupSize();
boolean highlightEntry = _prefs.isEntryHighlightEnabled();
Expand All @@ -278,7 +279,7 @@ private void onPreferencesResult(Intent data) {
int tapToRevealTime = _prefs.getTapToRevealTime();
ViewMode viewMode = _prefs.getCurrentViewMode();
boolean copyOnTap = _prefs.isCopyOnTapEnabled();
_entryListView.setShowAccountName(showAccountName);
_entryListView.setAccountNamePosition(accountNamePosition);
_entryListView.setShowIcon(showIcons);
_entryListView.setCodeGroupSize(codeGroupSize);
_entryListView.setHighlightEntry(highlightEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;

import com.beemdevelopment.aegis.AccountNamePosition;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.Theme;
import com.beemdevelopment.aegis.ViewMode;
Expand Down Expand Up @@ -102,9 +103,24 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
return true;
});

Preference issuerPreference = requirePreference("pref_account_name");
issuerPreference.setOnPreferenceChangeListener((preference, newValue) -> {
getResult().putExtra("needsRefresh", true);
int currentAccountNamePosition = _prefs.getAccountNamePosition().ordinal();
Preference currentAccountNamePositionPreference = requirePreference("pref_account_name_position");
currentAccountNamePositionPreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.account_name_position_titles)[currentAccountNamePosition]));
currentAccountNamePositionPreference.setOnPreferenceClickListener(preference -> {
int currentAccountNamePosition1 = _prefs.getAccountNamePosition().ordinal();

Dialogs.showSecureDialog(new AlertDialog.Builder(requireContext())
.setTitle(getString(R.string.choose_account_name_position))
.setSingleChoiceItems(R.array.account_name_position_titles, currentAccountNamePosition1, (dialog, which) -> {
int i = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
_prefs.setAccountNamePosition(AccountNamePosition.fromInteger(i));
currentAccountNamePositionPreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.account_name_position_titles)[i]));
getResult().putExtra("needsRefresh", true);
dialog.dismiss();
})
.setNegativeButton(android.R.string.cancel, null)
.create());

return true;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.beemdevelopment.aegis.AccountNamePosition;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.SortCategory;
Expand Down Expand Up @@ -47,7 +48,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private VaultEntry _focusedEntry;
private VaultEntry _copiedEntry;
private Preferences.CodeGrouping _codeGroupSize;
private boolean _showAccountName;
private AccountNamePosition _accountNamePosition;
private boolean _showIcon;
private boolean _highlightEntry;
private boolean _tempHighlightEntry;
Expand Down Expand Up @@ -87,8 +88,8 @@ public void setCodeGroupSize(Preferences.CodeGrouping codeGroupSize) {
_codeGroupSize = codeGroupSize;
}

public void setShowAccountName(boolean showAccountName) {
_showAccountName = showAccountName;
public void setAccountNamePosition(AccountNamePosition accountNamePosition) {
_accountNamePosition = accountNamePosition;
}

public void setShowIcon(boolean showIcon) {
Expand Down Expand Up @@ -421,7 +422,7 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position)
boolean paused = _pauseFocused && entry == _focusedEntry;
boolean dimmed = (_highlightEntry || _tempHighlightEntry) && _focusedEntry != null && _focusedEntry != entry;
boolean showProgress = entry.getInfo() instanceof TotpInfo && ((TotpInfo) entry.getInfo()).getPeriod() != getMostFrequentPeriod();
entryHolder.setData(entry, _codeGroupSize, _showAccountName, _showIcon, showProgress, hidden, paused, dimmed);
entryHolder.setData(entry, _codeGroupSize, _accountNamePosition, _showIcon, showProgress, hidden, paused, dimmed);
entryHolder.setFocused(_selectedEntries.contains(entry));
entryHolder.setShowDragHandle(isEntryDraggable(entry));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import androidx.recyclerview.widget.RecyclerView;

import com.amulyakhare.textdrawable.TextDrawable;
import com.beemdevelopment.aegis.AccountNamePosition;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.helpers.IconViewHelper;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
private final Handler _selectedHandler;

private Preferences.CodeGrouping _codeGrouping = Preferences.CodeGrouping.NO_GROUPING;
private AccountNamePosition _accountNamePosition = AccountNamePosition.HIDDEN;

private boolean _hidden;
private boolean _paused;
Expand Down Expand Up @@ -105,11 +107,12 @@ public long getMillisTillNextRefresh() {
});
}

public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, boolean showAccountName, boolean showIcon, boolean showProgress, boolean hidden, boolean paused, boolean dimmed) {
public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, AccountNamePosition accountNamePosition, boolean showIcon, boolean showProgress, boolean hidden, boolean paused, boolean dimmed) {
_entry = entry;
_hidden = hidden;
_paused = paused;
_codeGrouping = groupSize;
_accountNamePosition = accountNamePosition;

_selected.clearAnimation();
_selected.setVisibility(View.GONE);
Expand All @@ -125,12 +128,13 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, boolea
_buttonRefresh.setVisibility(entry.getInfo() instanceof HotpInfo ? View.VISIBLE : View.GONE);

String profileIssuer = entry.getIssuer();
String profileName = showAccountName ? entry.getName() : "";
if (!profileIssuer.isEmpty() && !profileName.isEmpty()) {
String profileName = entry.getName();
if (!profileIssuer.isEmpty() && !profileName.isEmpty() && accountNamePosition == AccountNamePosition.END) {
profileName = String.format(" (%s)", profileName);
}
_profileIssuer.setText(profileIssuer);
_profileName.setText(profileName);
setAccountNameLayout(accountNamePosition);

if (_hidden) {
hideCode();
Expand All @@ -143,6 +147,41 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, boolea
itemView.setAlpha(dimmed ? DIMMED_ALPHA : DEFAULT_ALPHA);
}

private void setAccountNameLayout(AccountNamePosition accountNamePosition) {
RelativeLayout.LayoutParams profileNameLayoutParams;
RelativeLayout.LayoutParams copiedLayoutParams;
switch (accountNamePosition) {
case HIDDEN:
_profileName.setVisibility(View.GONE);
break;

case BELOW:
profileNameLayoutParams = (RelativeLayout.LayoutParams) _profileName.getLayoutParams();
profileNameLayoutParams.removeRule(RelativeLayout.END_OF);
profileNameLayoutParams.addRule(RelativeLayout.BELOW, R.id.profile_issuer);
_profileName.setLayoutParams(profileNameLayoutParams);
_profileName.setVisibility(View.VISIBLE);

copiedLayoutParams = (RelativeLayout.LayoutParams) _profileCopied.getLayoutParams();
copiedLayoutParams.addRule(RelativeLayout.ABOVE, R.id.profile_account_name);
_profileCopied.setLayoutParams(copiedLayoutParams);
break;

case END:
default:
profileNameLayoutParams = (RelativeLayout.LayoutParams) _profileName.getLayoutParams();
profileNameLayoutParams.addRule(RelativeLayout.END_OF, R.id.profile_issuer);
profileNameLayoutParams.removeRule(RelativeLayout.BELOW);
_profileName.setLayoutParams(profileNameLayoutParams);
_profileName.setVisibility(View.VISIBLE);

copiedLayoutParams = (RelativeLayout.LayoutParams) _profileCopied.getLayoutParams();
copiedLayoutParams.addRule(RelativeLayout.ABOVE, R.id.description);
_profileCopied.setLayoutParams(copiedLayoutParams);
break;
}
}

public VaultEntry getEntry() {
return _entry;
}
Expand Down Expand Up @@ -337,11 +376,14 @@ public void animateCopyText() {
Animation fadeIn = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.fade_in);

_profileCopied.startAnimation(slideDownFadeIn);
_description.startAnimation(slideDownFadeOut);

View fadeOutView = (_accountNamePosition == AccountNamePosition.BELOW) ? _profileName : _description;

fadeOutView.startAnimation(slideDownFadeOut);

_animationHandler.postDelayed(() -> {
_profileCopied.startAnimation(fadeOut);
_description.startAnimation(fadeIn);
fadeOutView.startAnimation(fadeIn);
}, 3000);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.beemdevelopment.aegis.AccountNamePosition;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.SortCategory;
Expand Down Expand Up @@ -324,8 +325,8 @@ public void setCodeGroupSize(Preferences.CodeGrouping codeGrouping) {
_adapter.setCodeGroupSize(codeGrouping);
}

public void setShowAccountName(boolean showAccountName) {
_adapter.setShowAccountName(showAccountName);
public void setAccountNamePosition(AccountNamePosition accountNamePosition) {
_adapter.setAccountNamePosition(accountNamePosition);
}

public void setShowIcon(boolean showIcon) {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/card_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/profile_issuer"
android:layout_marginStart="2dp"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/card_entry_compact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/profile_issuer"
android:layout_marginStart="2dp"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/card_entry_small.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/profile_issuer"
android:layout_marginStart="2dp"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-ar-rSA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
<string name="pref_show_icons_summary">عرض الأيقونات بجانب كل مدخل</string>
<string name="pref_code_group_size_title">تجميع أرقام الكود</string>
<string name="pref_code_group_size_summary">اختر عدد الخانات المستخدمة في تجميع الرموز</string>
<string name="pref_account_name_title">اظهر اسم الحساب</string>
<string name="pref_account_name_summary">قم بالتفعيل لإظهار اسم الحساب بجانب المصدِّر</string>
<string name="pref_import_file_title">استيراد من ملف</string>
<string name="pref_import_file_summary">استيراد الرموز من ملف</string>
<string name="pref_android_backups_title">النسخ الاحتياطية السحابية للأندرويد</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-ast-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
<string name="pref_show_icons_summary">Amuesa los iconos al llau de cada entrada</string>
<string name="pref_code_group_size_title">Agrupamientu de díxitos</string>
<string name="pref_code_group_size_summary">Seleiciona\'l númberu de díxitos pol que s\'agrupen los códigos</string>
<string name="pref_account_name_title">Amosar el nome de les cuentes</string>
<string name="pref_account_name_summary">Activa esta opción p\'amosar el nome de les cuentes xunto al del emisor</string>
<string name="pref_import_file_title">Importar d\'un ficheru</string>
<string name="pref_import_file_summary">Importa los pases d\'un ficheru</string>
<string name="pref_android_backups_title">Copies de seguranza na ñube</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-bg-rBG/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
<string name="pref_view_mode_title">Режим на преглед</string>
<string name="pref_lang_title">Език</string>
<string name="pref_code_group_size_title">Групиране на кодови цифри</string>
<string name="pref_account_name_title">Показване на профилното име</string>
<string name="pref_account_name_summary">Активирайте това, за да се показва името на акаунта до издателя</string>
<string name="pref_import_file_title">Импорт от файл</string>
<string name="pref_import_file_summary">Импортиране на токени от файл</string>
<string name="pref_backups_title">Автоматично архивирайте трезора</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-ca-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
<string name="pref_show_icons_summary">Mostra icones al costat de cada entrada</string>
<string name="pref_code_group_size_title">Agrupació dels dígits</string>
<string name="pref_code_group_size_summary">Triar nombre de digits per agrupar els codis</string>
<string name="pref_account_name_title">Mostra el nom del compte</string>
<string name="pref_account_name_summary">Activa això per a mostrar en nom del compte al costat de l\'emissor</string>
<string name="pref_import_file_title">Importa des d\'un fitxer</string>
<string name="pref_import_file_summary">Importar fitxes des d\'un fitxer</string>
<string name="pref_android_backups_title">Copies al núvol d\'Android</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-cs-rCZ/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
<string name="pref_show_icons_summary">Zobrazit ikony vedle každého záznamu</string>
<string name="pref_code_group_size_title">Seskupení číslic kódu</string>
<string name="pref_code_group_size_summary">Vyberte počet číslic, po kterých se mají seskupovat kódy</string>
<string name="pref_account_name_title">Zobrazit název účtu</string>
<string name="pref_account_name_summary">Zobrazit název účtu vedle poskytovatele</string>
<string name="pref_import_file_title">Importovat ze souboru</string>
<string name="pref_import_file_summary">Importovat tokeny ze souboru</string>
<string name="pref_android_backups_title">Cloudové zálohování systému Android</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-da-rDK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
<string name="pref_show_icons_summary">Vis ikoner ved siden af hver post</string>
<string name="pref_code_group_size_title">Kodeciffergruppering</string>
<string name="pref_code_group_size_summary">Vælg antal cifre til kodegruppering</string>
<string name="pref_account_name_title">Vis kontonavn</string>
<string name="pref_account_name_summary">Aktiver dette for at vise kontonavnet ved siden af udstederen</string>
<string name="pref_import_file_title">Import fra fil</string>
<string name="pref_import_file_summary">Importér tokens fra en fil</string>
<string name="pref_android_backups_title">Android cloud-sikkerhedskopier</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
<string name="pref_show_icons_summary">Symbole neben jedem Eintrag anzeigen</string>
<string name="pref_code_group_size_title">Zifferngruppierung</string>
<string name="pref_code_group_size_summary">Wähle die Anzahl der Ziffern, nach denen die Codes gruppiert werden sollen</string>
<string name="pref_account_name_title">Kontonamen anzeigen</string>
<string name="pref_account_name_summary">Aktiviere dies, um den Kontonamen neben dem Herausgeber anzuzeigen</string>
<string name="pref_import_file_title">Aus Datei importieren</string>
<string name="pref_import_file_summary">Token aus einer Datei importieren</string>
<string name="pref_android_backups_title">Cloud-Back-ups durch Android</string>
Expand Down
Loading

0 comments on commit d3c4884

Please sign in to comment.