Skip to content

Commit

Permalink
Merge pull request #1096 from beemdevelopment/feature/view-mode-tiles
Browse files Browse the repository at this point in the history
Add tiles view mode
  • Loading branch information
alexbakker committed Aug 23, 2023
2 parents 94a38e8 + d90303c commit 3e35215
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 112 deletions.
31 changes: 30 additions & 1 deletion app/src/main/java/com/beemdevelopment/aegis/ViewMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
public enum ViewMode {
NORMAL,
COMPACT,
SMALL;
SMALL,
TILES;

private static ViewMode[] _values;

Expand All @@ -26,6 +27,8 @@ public int getLayoutId() {
return R.layout.card_entry_compact;
case SMALL:
return R.layout.card_entry_small;
case TILES:
return R.layout.card_entry_tile;
default:
return R.layout.card_entry;
}
Expand All @@ -37,8 +40,34 @@ public int getLayoutId() {
public float getDividerHeight() {
if (this == ViewMode.COMPACT) {
return 0;
} else if (this == ViewMode.TILES) {
return 4;
}

return 20;
}

public int getColumnSpan() {
if (this == ViewMode.TILES) {
return 2;
}

return 1;
}

public float getDividerWidth() {
if (this == ViewMode.TILES) {
return 4;
}

return 0;
}

public String getFormattedAccountName(String accountName) {
if (this == ViewMode.TILES) {
return accountName;
}

return String.format("(%s)", accountName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback {
private final EntryAdapter _adapter;
private boolean _positionChanged = false;
private boolean _isLongPressDragEnabled = true;
private int _dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;

public SimpleItemTouchHelperCallback(EntryAdapter adapter) {
_adapter = adapter;
Expand Down Expand Up @@ -46,6 +47,10 @@ public boolean isItemViewSwipeEnabled() {
return false;
}

public void setDragFlags(int dragFlags) {
_dragFlags = dragFlags;
}

@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
// It's not clear when this can happen, but sometimes the ViewHolder
Expand All @@ -57,16 +62,15 @@ public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull Recycle
}

int swipeFlags = 0;
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;

EntryAdapter adapter = (EntryAdapter) recyclerView.getAdapter();
if (adapter.isPositionFooter(position)
|| adapter.getEntryAt(position) != _selectedEntry
|| !isLongPressDragEnabled()) {
dragFlags = 0;
return makeMovementFlags(0, swipeFlags);
}

return makeMovementFlags(dragFlags, swipeFlags);
return makeMovementFlags(_dragFlags, swipeFlags);
}

@Override
Expand All @@ -75,7 +79,11 @@ public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHol
if (target.getAdapterPosition() < _adapter.getShownFavoritesCount()){
return false;
}
_adapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());

int firstPosition = viewHolder.getLayoutPosition();
int secondPosition = target.getAdapterPosition();

_adapter.onItemMove(firstPosition, secondPosition);
_positionChanged = true;
return true;
}
Expand All @@ -92,6 +100,7 @@ public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHol
if (_positionChanged) {
_adapter.onItemDrop(viewHolder.getAdapterPosition());
_positionChanged = false;
_adapter.refresh(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ private void startActionMode() {

@Override
public void onEntryMove(VaultEntry entry1, VaultEntry entry2) {
_vaultManager.getVault().swapEntries(entry1, entry2);
_vaultManager.getVault().moveEntry(entry1, entry2);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class AppearancePreferencesFragment extends PreferencesFragment {
private Preference _groupsPreference;
private Preference _resetUsageCountPreference;
private Preference _currentAccountNamePositionPreference;

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Expand Down Expand Up @@ -89,6 +90,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
_prefs.setCurrentViewMode(ViewMode.fromInteger(i));
viewModePreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.view_mode_titles)[i]));
getResult().putExtra("needsRefresh", true);
overrideAccountNamePosition(ViewMode.fromInteger(i) == ViewMode.TILES);
dialog.dismiss();
})
.setNegativeButton(android.R.string.cancel, null)
Expand All @@ -110,17 +112,17 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
});

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 -> {
_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]));
_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();
})
Expand All @@ -135,5 +137,17 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getResult().putExtra("needsRefresh", true);
return true;
});

overrideAccountNamePosition(_prefs.getCurrentViewMode() == ViewMode.TILES);
}

private void overrideAccountNamePosition(boolean override) {
if (override) {
_currentAccountNamePositionPreference.setEnabled(false);
_currentAccountNamePositionPreference.setSummary(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()]));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.beemdevelopment.aegis.otp.OtpInfo;
import com.beemdevelopment.aegis.otp.OtpInfoException;
import com.beemdevelopment.aegis.otp.TotpInfo;
import com.beemdevelopment.aegis.util.CollectionUtils;
import com.beemdevelopment.aegis.vault.VaultEntry;

import java.util.ArrayList;
Expand Down Expand Up @@ -382,9 +383,10 @@ public void onItemMove(int firstPosition, int secondPosition) {
// notify the vault first
_view.onEntryMove(_entries.get(firstPosition), _entries.get(secondPosition));

// update our side of things
Collections.swap(_entries, firstPosition, secondPosition);
Collections.swap(_shownEntries, firstPosition, secondPosition);
// then update our end
CollectionUtils.move(_entries, firstPosition, secondPosition);
CollectionUtils.move(_shownEntries, firstPosition, secondPosition);

notifyItemMoved(firstPosition, secondPosition);
}

Expand Down Expand Up @@ -438,7 +440,7 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position)
}

AccountNamePosition accountNamePosition = showAccountName ? _accountNamePosition : AccountNamePosition.HIDDEN;
entryHolder.setData(entry, _codeGroupSize, accountNamePosition, _showIcon, showProgress, hidden, paused, dimmed);
entryHolder.setData(entry, _codeGroupSize, _viewMode, accountNamePosition, _showIcon, showProgress, hidden, paused, dimmed);
entryHolder.setFocused(_selectedEntries.contains(entry));
entryHolder.setShowDragHandle(isEntryDraggable(entry));

Expand Down Expand Up @@ -467,7 +469,7 @@ public void onClick(View v) {
case SINGLETAP:
if (!handled) {
_view.onEntryCopy(entry);
entryHolder.animateCopyText();
entryHolder.animateCopyText(_viewMode != ViewMode.TILES);
_clickedEntry = null;
}
break;
Expand All @@ -476,7 +478,7 @@ public void onClick(View v) {

if(entry == _clickedEntry) {
_view.onEntryCopy(entry);
entryHolder.animateCopyText();
entryHolder.animateCopyText(_viewMode != ViewMode.TILES);
_clickedEntry = null;
} else {
_clickedEntry = entry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.beemdevelopment.aegis.AccountNamePosition;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.ViewMode;
import com.beemdevelopment.aegis.helpers.IconViewHelper;
import com.beemdevelopment.aegis.helpers.TextDrawableHelper;
import com.beemdevelopment.aegis.helpers.ThemeHelper;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
private ImageView _buttonRefresh;
private RelativeLayout _description;
private ImageView _dragHandle;
private ViewMode _viewMode;

private final ImageView _selected;
private final Handler _selectedHandler;
Expand Down Expand Up @@ -107,11 +109,12 @@ public long getMillisTillNextRefresh() {
});
}

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

_selected.clearAnimation();
Expand All @@ -129,12 +132,12 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, Accoun

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

if (_hidden) {
hideCode();
Expand All @@ -148,6 +151,10 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, Accoun
}

private void setAccountNameLayout(AccountNamePosition accountNamePosition) {
if (_viewMode == ViewMode.TILES) {
return;
}

RelativeLayout.LayoutParams profileNameLayoutParams;
RelativeLayout.LayoutParams copiedLayoutParams;
switch (accountNamePosition) {
Expand Down Expand Up @@ -367,24 +374,33 @@ public void highlight() {
animateAlphaTo(DEFAULT_ALPHA);
}

public void animateCopyText() {
public void animateCopyText(boolean includeSlideAnimation) {
_animationHandler.removeCallbacksAndMessages(null);

Animation slideDownFadeIn = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.slide_down_fade_in);
Animation slideDownFadeOut = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.slide_down_fade_out);
Animation fadeOut = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.fade_out);
Animation fadeIn = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.fade_in);

_profileCopied.startAnimation(slideDownFadeIn);

View fadeOutView = (_accountNamePosition == AccountNamePosition.BELOW) ? _profileName : _description;
if (includeSlideAnimation) {
_profileCopied.startAnimation(slideDownFadeIn);
View fadeOutView = (_accountNamePosition == AccountNamePosition.BELOW) ? _profileName : _description;

fadeOutView.startAnimation(slideDownFadeOut);

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

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

private void animateAlphaTo(float alpha) {
Expand Down
Loading

0 comments on commit 3e35215

Please sign in to comment.