From 71c0ad2a085babfb36ffe891f475e7b9d2d8e987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Sch=C3=A4ttgen?= Date: Tue, 6 Aug 2024 00:41:51 +0200 Subject: [PATCH] Add ability to hide account name in tiles mode --- .../AppearancePreferencesFragment.java | 13 +++--- .../aegis/ui/views/EntryAdapter.java | 4 +- .../aegis/ui/views/EntryHolder.java | 41 +++++++++++++------ app/src/main/res/layout/card_entry_tile.xml | 9 ++-- app/src/main/res/values/strings.xml | 2 +- 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java index a0b39a3326..b8cb7809e4 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java @@ -116,7 +116,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { int i = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); _prefs.setCurrentViewMode(ViewMode.fromInteger(i)); viewModePreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.view_mode_titles)[i])); - overrideAccountNamePosition(ViewMode.fromInteger(i) == ViewMode.TILES); + refreshAccountNamePositionText(); dialog.dismiss(); }) .setNegativeButton(android.R.string.cancel, null) @@ -156,6 +156,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 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])); + refreshAccountNamePositionText(); dialog.dismiss(); }) .setNegativeButton(android.R.string.cancel, null) @@ -164,15 +165,15 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { return true; }); - overrideAccountNamePosition(_prefs.getCurrentViewMode() == ViewMode.TILES); + refreshAccountNamePositionText(); } - private void overrideAccountNamePosition(boolean override) { + private void refreshAccountNamePositionText() { + boolean override = (_prefs.getCurrentViewMode() == ViewMode.TILES && _prefs.getAccountNamePosition() == AccountNamePosition.END); + if (override) { - _currentAccountNamePositionPreference.setEnabled(false); - _currentAccountNamePositionPreference.setSummary(getString(R.string.pref_account_name_position_summary_override)); + _currentAccountNamePositionPreference.setSummary(String.format("%s: %s. %s", getString(R.string.selected), getResources().getStringArray(R.array.account_name_position_titles)[_prefs.getAccountNamePosition().ordinal()], getString(R.string.pref_account_name_position_summary_override))); } else { - _currentAccountNamePositionPreference.setEnabled(true); _currentAccountNamePositionPreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.account_name_position_titles)[_prefs.getAccountNamePosition().ordinal()])); } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java index 544c16d52c..e503b7cf1d 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java @@ -550,7 +550,7 @@ public void onClick(View v) { case SINGLETAP: if (!handled) { _view.onEntryCopy(entry); - entryHolder.animateCopyText(_viewMode != ViewMode.TILES); + entryHolder.animateCopyText(); _clickedEntry = null; } break; @@ -559,7 +559,7 @@ public void onClick(View v) { if(entry == _clickedEntry) { _view.onEntryCopy(entry); - entryHolder.animateCopyText(_viewMode != ViewMode.TILES); + entryHolder.animateCopyText(); _clickedEntry = null; } else { _clickedEntry = entry; diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryHolder.java b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryHolder.java index a2fc82c00e..b9ce5c1871 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryHolder.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryHolder.java @@ -1,7 +1,9 @@ package com.beemdevelopment.aegis.ui.views; import android.os.Handler; +import android.view.Gravity; import android.view.View; +import android.view.ViewGroup; import android.view.animation.Animation; import android.widget.ImageView; import android.widget.RelativeLayout; @@ -108,6 +110,9 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, ViewMo _codeGrouping = groupSize; _viewMode = viewMode; _accountNamePosition = accountNamePosition; + if (viewMode.equals(ViewMode.TILES) && _accountNamePosition == AccountNamePosition.END) { + _accountNamePosition = AccountNamePosition.BELOW; + } _selected.clearAnimation(); _selected.setVisibility(View.GONE); @@ -143,15 +148,25 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, ViewMo } private void setAccountNameLayout(AccountNamePosition accountNamePosition, Boolean hasBothIssuerAndName) { - if (_viewMode == ViewMode.TILES) { - return; - } - RelativeLayout.LayoutParams profileNameLayoutParams; - RelativeLayout.LayoutParams copiedLayoutParams; + switch (accountNamePosition) { case HIDDEN: _profileName.setVisibility(View.GONE); + + if (_viewMode == ViewMode.TILES) { + _profileCopied.setGravity(Gravity.CENTER_VERTICAL); + ((RelativeLayout.LayoutParams)_profileCopied.getLayoutParams()).removeRule(RelativeLayout.BELOW); + _profileCopied.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; + _profileCopied.setTextSize(14); + + _profileIssuer.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; + _profileIssuer.setGravity(Gravity.CENTER_VERTICAL); + _profileIssuer.setTextSize(14); + + _profileName.setVisibility(View.GONE); + } + break; case BELOW: @@ -349,7 +364,7 @@ public void highlight() { animateAlphaTo(DEFAULT_ALPHA); } - public void animateCopyText(boolean includeSlideAnimation) { + public void animateCopyText() { _animationHandler.removeCallbacksAndMessages(null); Animation slideDownFadeIn = AnimationsHelper.loadScaledAnimation(itemView.getContext(), R.anim.slide_down_fade_in); @@ -357,23 +372,25 @@ public void animateCopyText(boolean includeSlideAnimation) { Animation fadeOut = AnimationsHelper.loadScaledAnimation(itemView.getContext(), R.anim.fade_out); Animation fadeIn = AnimationsHelper.loadScaledAnimation(itemView.getContext(), R.anim.fade_in); - if (includeSlideAnimation) { + // Use slideDown animation when user is not using Tiles mode + if (_viewMode != ViewMode.TILES) { _profileCopied.startAnimation(slideDownFadeIn); - View fadeOutView = (_accountNamePosition == AccountNamePosition.BELOW) ? _profileName : _description; - - fadeOutView.startAnimation(slideDownFadeOut); + View fadeOutView = (_accountNamePosition == AccountNamePosition.BELOW) ? _profileName : _description; + fadeOutView.startAnimation(slideDownFadeOut); _animationHandler.postDelayed(() -> { _profileCopied.startAnimation(fadeOut); fadeOutView.startAnimation(fadeIn); }, 3000); } else { + View visibleProfileText = _accountNamePosition == AccountNamePosition.BELOW ? _profileName : _profileIssuer; + _profileCopied.startAnimation(fadeIn); - _profileName.startAnimation(fadeOut); + visibleProfileText.startAnimation(fadeOut); _animationHandler.postDelayed(() -> { _profileCopied.startAnimation(fadeOut); - _profileName.startAnimation(fadeIn); + visibleProfileText.startAnimation(fadeIn); }, 3000); } } diff --git a/app/src/main/res/layout/card_entry_tile.xml b/app/src/main/res/layout/card_entry_tile.xml index d3351fbd75..8a18a16283 100644 --- a/app/src/main/res/layout/card_entry_tile.xml +++ b/app/src/main/res/layout/card_entry_tile.xml @@ -66,9 +66,9 @@ + android:layout_toEndOf="@id/layoutImage"> - - - Show the account name Only show account name when necessary Only show account names whenever they share the same issuer. Other account names will be hidden. - This setting is overridden by the tiles view mode. Account name will always be shown below the issuer. + This setting is overridden by the tiles view mode. Account name will be shown below the issuer. Import from file Import tokens from a file Android cloud backups