Skip to content

Commit

Permalink
Merge pull request #1447 from michaelschattgen/feature/hide-account-n…
Browse files Browse the repository at this point in the history
…ame-tiles

Add ability to hide account name in tiles mode
  • Loading branch information
alexbakker committed Aug 12, 2024
2 parents bc5cb48 + 71c0ad2 commit a46c816
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()]));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -349,31 +364,33 @@ 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);
Animation slideDownFadeOut = AnimationsHelper.loadScaledAnimation(itemView.getContext(), R.anim.slide_down_fade_out);
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);
}
}
Expand Down
9 changes: 3 additions & 6 deletions app/src/main/res/layout/card_entry_tile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="24dp"
android:id="@+id/description"
android:layout_toEndOf="@+id/layoutImage">
android:layout_toEndOf="@id/layoutImage">

<TextView
android:layout_width="wrap_content"
Expand All @@ -80,19 +80,16 @@
android:textSize="11sp"
android:ellipsize="end"
android:maxLines="1"/>


<TextView
android:id="@+id/profile_copied"
android:layout_width="wrap_content"
android:layout_below="@id/profile_issuer"
android:layout_height="wrap_content"
android:layout_below="@id/profile_issuer"
android:maxLines="1"
android:includeFontPadding="false"
android:visibility="invisible"
android:text="@string/copied"
android:textSize="9sp" />

<TextView
android:id="@+id/profile_account_name"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<string name="pref_account_name_position_title">Show the account name</string>
<string name="pref_shared_issuer_account_name_title">Only show account name when necessary</string>
<string name="pref_shared_issuer_account_name_summary">Only show account names whenever they share the same issuer. Other account names will be hidden.</string>
<string name="pref_account_name_position_summary_override">This setting is overridden by the tiles view mode. Account name will always be shown below the issuer.</string>
<string name="pref_account_name_position_summary_override">This setting is overridden by the tiles view mode. Account name will be shown below the issuer.</string>
<string name="pref_import_file_title">Import from file</string>
<string name="pref_import_file_summary">Import tokens from a file</string>
<string name="pref_android_backups_title">Android cloud backups</string>
Expand Down

0 comments on commit a46c816

Please sign in to comment.