From bf7c60d6204b4e19217a8e4120909d9fdf500500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Sch=C3=A4ttgen?= Date: Sat, 16 Mar 2024 17:31:21 +0100 Subject: [PATCH] Fix shape of favorited entries --- .../aegis/ui/views/EntryListView.java | 28 +++++++++++++++++++ .../main/res/layout/card_entry_compact.xml | 2 ++ app/src/main/res/layout/card_entry_small.xml | 3 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryListView.java b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryListView.java index 74e43188..de92d788 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryListView.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryListView.java @@ -47,9 +47,12 @@ import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader; import com.bumptech.glide.util.ViewPreloadSizeProvider; import com.google.android.material.bottomsheet.BottomSheetDialog; +import com.google.android.material.card.MaterialCardView; import com.google.android.material.chip.Chip; import com.google.android.material.chip.ChipGroup; import com.google.android.material.divider.MaterialDividerItemDecoration; +import com.google.android.material.shape.CornerFamily; +import com.google.android.material.shape.ShapeAppearanceModel; import com.google.common.base.Strings; import java.util.Collection; @@ -639,6 +642,27 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener { void onEntryListTouch(); } + private void decorateFavoriteEntries(@NonNull View view, @NonNull RecyclerView parent) { + int adapterPosition = parent.getChildAdapterPosition(view); + int entryIndex = _adapter.translateEntryPosToIndex(adapterPosition); + int totalFavorites = _adapter.getShownFavoritesCount(); + + if (entryIndex < totalFavorites) { + ShapeAppearanceModel model = ((MaterialCardView)view).getShapeAppearanceModel(); + ShapeAppearanceModel.Builder builder = model.toBuilder(); + if ((entryIndex == 0 && totalFavorites > 1) || (entryIndex < (totalFavorites - 1))) { + builder.setBottomLeftCorner(CornerFamily.ROUNDED, 0); + builder.setBottomRightCorner(CornerFamily.ROUNDED, 0); + } + if (entryIndex > 0) { + builder.setTopLeftCorner(CornerFamily.ROUNDED, 0); + builder.setTopRightCorner(CornerFamily.ROUNDED, 0); + } + + ((MaterialCardView)view).setShapeAppearanceModel(builder.build()); + } + } + private class CompactDividerDecoration extends MaterialDividerItemDecoration { public CompactDividerDecoration() { super(requireContext(), DividerItemDecoration.VERTICAL); @@ -661,6 +685,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener { return; } + decorateFavoriteEntries(view, parent); + super.getItemOffsets(outRect, view, parent, state); } } @@ -713,6 +739,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener { if (entryIndex == totalFavorites) { outRect.top = _height; } + + decorateFavoriteEntries(view, parent); } // The last entry should never have a bottom margin diff --git a/app/src/main/res/layout/card_entry_compact.xml b/app/src/main/res/layout/card_entry_compact.xml index a5a1e562..54d6e8a4 100644 --- a/app/src/main/res/layout/card_entry_compact.xml +++ b/app/src/main/res/layout/card_entry_compact.xml @@ -26,6 +26,8 @@ android:layout_width="15dp" android:layout_height="match_parent" android:layout_marginStart="-11dp" + android:layout_marginBottom="8dp" + android:layout_marginTop="8dp" android:backgroundTint="?attr/colorFavorite" android:background="@drawable/favorite_indicator" /> diff --git a/app/src/main/res/layout/card_entry_small.xml b/app/src/main/res/layout/card_entry_small.xml index 92a8ad71..fcca4190 100644 --- a/app/src/main/res/layout/card_entry_small.xml +++ b/app/src/main/res/layout/card_entry_small.xml @@ -15,7 +15,6 @@