Skip to content

Commit bf7c60d

Browse files
Fix shape of favorited entries
1 parent 6fc9cd5 commit bf7c60d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryListView.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@
4747
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader;
4848
import com.bumptech.glide.util.ViewPreloadSizeProvider;
4949
import com.google.android.material.bottomsheet.BottomSheetDialog;
50+
import com.google.android.material.card.MaterialCardView;
5051
import com.google.android.material.chip.Chip;
5152
import com.google.android.material.chip.ChipGroup;
5253
import com.google.android.material.divider.MaterialDividerItemDecoration;
54+
import com.google.android.material.shape.CornerFamily;
55+
import com.google.android.material.shape.ShapeAppearanceModel;
5356
import com.google.common.base.Strings;
5457

5558
import java.util.Collection;
@@ -639,6 +642,27 @@ public interface Listener {
639642
void onEntryListTouch();
640643
}
641644

645+
private void decorateFavoriteEntries(@NonNull View view, @NonNull RecyclerView parent) {
646+
int adapterPosition = parent.getChildAdapterPosition(view);
647+
int entryIndex = _adapter.translateEntryPosToIndex(adapterPosition);
648+
int totalFavorites = _adapter.getShownFavoritesCount();
649+
650+
if (entryIndex < totalFavorites) {
651+
ShapeAppearanceModel model = ((MaterialCardView)view).getShapeAppearanceModel();
652+
ShapeAppearanceModel.Builder builder = model.toBuilder();
653+
if ((entryIndex == 0 && totalFavorites > 1) || (entryIndex < (totalFavorites - 1))) {
654+
builder.setBottomLeftCorner(CornerFamily.ROUNDED, 0);
655+
builder.setBottomRightCorner(CornerFamily.ROUNDED, 0);
656+
}
657+
if (entryIndex > 0) {
658+
builder.setTopLeftCorner(CornerFamily.ROUNDED, 0);
659+
builder.setTopRightCorner(CornerFamily.ROUNDED, 0);
660+
}
661+
662+
((MaterialCardView)view).setShapeAppearanceModel(builder.build());
663+
}
664+
}
665+
642666
private class CompactDividerDecoration extends MaterialDividerItemDecoration {
643667
public CompactDividerDecoration() {
644668
super(requireContext(), DividerItemDecoration.VERTICAL);
@@ -661,6 +685,8 @@ public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull R
661685
return;
662686
}
663687

688+
decorateFavoriteEntries(view, parent);
689+
664690
super.getItemOffsets(outRect, view, parent, state);
665691
}
666692
}
@@ -713,6 +739,8 @@ public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull R
713739
if (entryIndex == totalFavorites) {
714740
outRect.top = _height;
715741
}
742+
743+
decorateFavoriteEntries(view, parent);
716744
}
717745

718746
// The last entry should never have a bottom margin

app/src/main/res/layout/card_entry_compact.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
android:layout_width="15dp"
2727
android:layout_height="match_parent"
2828
android:layout_marginStart="-11dp"
29+
android:layout_marginBottom="8dp"
30+
android:layout_marginTop="8dp"
2931
android:backgroundTint="?attr/colorFavorite"
3032
android:background="@drawable/favorite_indicator" />
3133

app/src/main/res/layout/card_entry_small.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
<LinearLayout
1717
android:orientation="horizontal"
18-
android:background="?attr/colorSurfaceContainerLow"
1918
android:id="@+id/rlCardEntry"
2019
android:paddingTop="5dp"
2120
android:paddingBottom="5dp"
@@ -27,6 +26,8 @@
2726
android:layout_width="15dp"
2827
android:layout_height="match_parent"
2928
android:layout_marginStart="-11dp"
29+
android:layout_marginTop="4dp"
30+
android:layout_marginBottom="4dp"
3031
android:backgroundTint="?attr/colorFavorite"
3132
android:background="@drawable/favorite_indicator" />
3233

0 commit comments

Comments
 (0)