Add ability to hide account name in tiles mode

This commit is contained in:
Michael Schättgen 2024-08-06 00:41:51 +02:00
parent e79c2c174b
commit 71c0ad2a08
5 changed files with 42 additions and 27 deletions

View file

@ -116,7 +116,7 @@ public class AppearancePreferencesFragment extends PreferencesFragment {
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 class AppearancePreferencesFragment extends PreferencesFragment {
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 class AppearancePreferencesFragment extends PreferencesFragment {
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()]));
}
}

View file

@ -550,7 +550,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
case SINGLETAP:
if (!handled) {
_view.onEntryCopy(entry);
entryHolder.animateCopyText(_viewMode != ViewMode.TILES);
entryHolder.animateCopyText();
_clickedEntry = null;
}
break;
@ -559,7 +559,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if(entry == _clickedEntry) {
_view.onEntryCopy(entry);
entryHolder.animateCopyText(_viewMode != ViewMode.TILES);
entryHolder.animateCopyText();
_clickedEntry = null;
} else {
_clickedEntry = entry;

View file

@ -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 class EntryHolder extends RecyclerView.ViewHolder {
_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 class EntryHolder extends RecyclerView.ViewHolder {
}
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 class EntryHolder extends RecyclerView.ViewHolder {
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 class EntryHolder extends RecyclerView.ViewHolder {
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);
}
}

View file

@ -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"
@ -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"

View file

@ -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>