Skip to content

Commit

Permalink
Add tiles view mode
Browse files Browse the repository at this point in the history
Minor UI improvements

Fix animations

Fix typo
  • Loading branch information
michaelschattgen committed Feb 18, 2023
1 parent fd42c5c commit 2c650ee
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 28 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,11 @@ 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 +63,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position)
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, _viewMode, _showAccountName, _showIcon, showProgress, hidden, paused, dimmed);
entryHolder.setFocused(_selectedEntries.contains(entry));
entryHolder.setShowDragHandle(isEntryDraggable(entry));

Expand All @@ -435,7 +435,7 @@ public void onClick(View v) {

if (_copyOnTap && !entryHolder.isHidden() && !(entry == _copiedEntry)) {
_view.onEntryCopy(entry);
entryHolder.animateCopyText();
entryHolder.animateCopyText(_viewMode != ViewMode.TILES);
_copiedEntry = entry;
copiedThisClick = true;
handled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.amulyakhare.textdrawable.TextDrawable;
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 @@ -105,7 +106,7 @@ public long getMillisTillNextRefresh() {
});
}

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, ViewMode viewMode, boolean showAccountName, boolean showIcon, boolean showProgress, boolean hidden, boolean paused, boolean dimmed) {
_entry = entry;
_hidden = hidden;
_paused = paused;
Expand All @@ -127,7 +128,7 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, boolea
String profileIssuer = entry.getIssuer();
String profileName = showAccountName ? entry.getName() : "";
if (!profileIssuer.isEmpty() && !profileName.isEmpty()) {
profileName = String.format(" (%s)", profileName);
profileName = viewMode.getFormattedAccountName(profileName);
}
_profileIssuer.setText(profileIssuer);
_profileName.setText(profileName);
Expand Down Expand Up @@ -328,21 +329,31 @@ 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);
_description.startAnimation(slideDownFadeOut);
if (includeSlideAnimation) {
_profileCopied.startAnimation(slideDownFadeIn);
_description.startAnimation(slideDownFadeOut);

_animationHandler.postDelayed(() -> {
_profileCopied.startAnimation(fadeOut);
_description.startAnimation(fadeIn);
}, 3000);
_animationHandler.postDelayed(() -> {
_profileCopied.startAnimation(fadeOut);
_description.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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -61,7 +62,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
private ItemTouchHelper _touchHelper;

private RecyclerView _recyclerView;
private RecyclerView.ItemDecoration _dividerDecoration;
private RecyclerView.ItemDecoration _verticalDividerDecoration;
private RecyclerView.ItemDecoration _horizontalDividerDecoration;
private ViewPreloadSizeProvider<VaultEntry> _preloadSizeProvider;
private TotpProgressBar _progressBar;
private boolean _showProgress;
Expand Down Expand Up @@ -119,7 +121,17 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
RecyclerViewPreloader<VaultEntry> preloader = new RecyclerViewPreloader<>(Glide.with(this), modelProvider, _preloadSizeProvider, 10);
_recyclerView.addOnScrollListener(preloader);

LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
GridLayoutManager layoutManager = new GridLayoutManager(requireContext(), 1);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (_viewMode == ViewMode.TILES && position == _adapter.getEntriesCount()) {
return 2;
}

return 1;
}
});
_recyclerView.setLayoutManager(layoutManager);
_touchCallback = new SimpleItemTouchHelperCallback(_adapter);
_touchHelper = new ItemTouchHelper(_touchCallback);
Expand Down Expand Up @@ -217,6 +229,13 @@ public void setViewMode(ViewMode mode) {
_viewMode = mode;
updateDividerDecoration();
_adapter.setViewMode(_viewMode);
if (_viewMode == ViewMode.TILES) {
_touchCallback.setDragFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
} else {
_touchCallback.setDragFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN);
}

((GridLayoutManager)_recyclerView.getLayoutManager()).setSpanCount(mode.getColumnSpan());
}

public void startDrag(RecyclerView.ViewHolder viewHolder) {
Expand Down Expand Up @@ -527,18 +546,28 @@ private List<String> cleanGroupFilter(List<String> groupFilter) {
}

private void updateDividerDecoration() {
if (_dividerDecoration != null) {
_recyclerView.removeItemDecoration(_dividerDecoration);
if (_verticalDividerDecoration != null) {
_recyclerView.removeItemDecoration(_verticalDividerDecoration);
}

if(_horizontalDividerDecoration != null) {
_recyclerView.removeItemDecoration(_horizontalDividerDecoration);
}

float height = _viewMode.getDividerHeight();
float width = _viewMode.getDividerWidth();
if (_showProgress && height == 0) {
_dividerDecoration = new CompactDividerDecoration();
_verticalDividerDecoration = new CompactDividerDecoration();
} else {
_dividerDecoration = new VerticalSpaceItemDecoration(height);
_verticalDividerDecoration = new VerticalSpaceItemDecoration(height);
}

_recyclerView.addItemDecoration(_dividerDecoration);
if (width != 0) {
_horizontalDividerDecoration = new TileSpaceItemDecoration(width, height);
_recyclerView.addItemDecoration(_horizontalDividerDecoration);
} else {
_recyclerView.addItemDecoration(_verticalDividerDecoration);
}
}

private void updateEmptyState() {
Expand Down Expand Up @@ -642,6 +671,30 @@ public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull R
}
}

private class TileSpaceItemDecoration extends RecyclerView.ItemDecoration {
private final int _width;
private final int _height;

private TileSpaceItemDecoration(float width, float height) {
// convert dp to pixels
_width = MetricsHelper.convertDpToPixels(requireContext(), width);
_height = MetricsHelper.convertDpToPixels(requireContext(), height);
}

@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
int adapterPosition = parent.getChildAdapterPosition(view);
if (adapterPosition == NO_POSITION) {
return;
}

outRect.left = _width;
outRect.right = _width;
outRect.top = _height;
outRect.bottom = _height;
}
}

private class IconPreloadProvider implements ListPreloader.PreloadModelProvider<VaultEntry> {
@NonNull
@Override
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/anim/fade_in.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true">
<translate
android:duration="0"
android:fromYDelta="-100%"
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/anim/fade_out.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true">

<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="300"/>

</set>
19 changes: 19 additions & 0 deletions app/src/main/res/drawable-v24/rounded_card_entry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="#f6eef1" />

<stroke
android:width="2dp"
android:color="#000000" />

<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />

<corners android:radius="5dp" />

</shape>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/card_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/profile_issuer"
android:layout_marginStart="2dp"
android:layout_marginStart="4dp"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/card_entry_compact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/profile_issuer"
android:layout_marginStart="2dp"
android:layout_marginStart="4dp"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/card_entry_small.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/profile_issuer"
android:layout_marginStart="2dp"
android:layout_marginStart="4dp"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
Expand Down
Loading

0 comments on commit 2c650ee

Please sign in to comment.