mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-15 22:42:51 +00:00
Add ability to change account name position
This commit is contained in:
parent
b08a2f5f93
commit
813fd62dc7
49 changed files with 118 additions and 102 deletions
|
@ -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];
|
||||
}
|
||||
}
|
|
@ -114,10 +114,6 @@ public class Preferences {
|
|||
setPasswordReminderTimestamp(new Date().getTime());
|
||||
}
|
||||
|
||||
public boolean isAccountNameVisible() {
|
||||
return _prefs.getBoolean("pref_account_name", true);
|
||||
}
|
||||
|
||||
public boolean isIconVisible() {
|
||||
return _prefs.getBoolean("pref_show_icons", true);
|
||||
}
|
||||
|
@ -189,6 +185,14 @@ public class Preferences {
|
|||
_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);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
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;
|
||||
|
@ -131,7 +132,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
|||
_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());
|
||||
|
@ -269,7 +270,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
|||
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();
|
||||
|
@ -278,7 +279,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
|||
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);
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.os.Bundle;
|
|||
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;
|
||||
|
@ -102,9 +103,24 @@ public class AppearancePreferencesFragment extends PreferencesFragment {
|
|||
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;
|
||||
});
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import android.widget.TextView;
|
|||
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;
|
||||
|
@ -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;
|
||||
|
@ -87,8 +88,8 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
_codeGroupSize = codeGroupSize;
|
||||
}
|
||||
|
||||
public void setShowAccountName(boolean showAccountName) {
|
||||
_showAccountName = showAccountName;
|
||||
public void setAccountNamePosition(AccountNamePosition accountNamePosition) {
|
||||
_accountNamePosition = accountNamePosition;
|
||||
}
|
||||
|
||||
public void setShowIcon(boolean showIcon) {
|
||||
|
@ -421,7 +422,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
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));
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment;
|
|||
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;
|
||||
|
@ -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;
|
||||
|
@ -105,11 +107,12 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
});
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -125,12 +128,13 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
_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();
|
||||
|
@ -143,6 +147,41 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
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;
|
||||
}
|
||||
|
@ -337,11 +376,14 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import androidx.recyclerview.widget.ItemTouchHelper;
|
|||
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;
|
||||
|
@ -324,8 +325,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
|||
_adapter.setCodeGroupSize(codeGrouping);
|
||||
}
|
||||
|
||||
public void setShowAccountName(boolean showAccountName) {
|
||||
_adapter.setShowAccountName(showAccountName);
|
||||
public void setAccountNamePosition(AccountNamePosition accountNamePosition) {
|
||||
_adapter.setAccountNamePosition(accountNamePosition);
|
||||
}
|
||||
|
||||
public void setShowIcon(boolean showIcon) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue