Merge pull request #1312 from michaelschattgen/fix/favorites-ui

Fix shape of favorited entries
This commit is contained in:
Alexander Bakker 2024-03-16 17:40:29 +01:00 committed by GitHub
commit 9737c85f86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 1 deletions

View file

@ -47,9 +47,12 @@ import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader; import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader;
import com.bumptech.glide.util.ViewPreloadSizeProvider; import com.bumptech.glide.util.ViewPreloadSizeProvider;
import com.google.android.material.bottomsheet.BottomSheetDialog; 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.Chip;
import com.google.android.material.chip.ChipGroup; import com.google.android.material.chip.ChipGroup;
import com.google.android.material.divider.MaterialDividerItemDecoration; 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 com.google.common.base.Strings;
import java.util.Collection; import java.util.Collection;
@ -639,6 +642,27 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
void onEntryListTouch(); 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 { private class CompactDividerDecoration extends MaterialDividerItemDecoration {
public CompactDividerDecoration() { public CompactDividerDecoration() {
super(requireContext(), DividerItemDecoration.VERTICAL); super(requireContext(), DividerItemDecoration.VERTICAL);
@ -661,6 +685,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
return; return;
} }
decorateFavoriteEntries(view, parent);
super.getItemOffsets(outRect, view, parent, state); super.getItemOffsets(outRect, view, parent, state);
} }
} }
@ -713,6 +739,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
if (entryIndex == totalFavorites) { if (entryIndex == totalFavorites) {
outRect.top = _height; outRect.top = _height;
} }
decorateFavoriteEntries(view, parent);
} }
// The last entry should never have a bottom margin // The last entry should never have a bottom margin

View file

@ -26,6 +26,8 @@
android:layout_width="15dp" android:layout_width="15dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginStart="-11dp" android:layout_marginStart="-11dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:backgroundTint="?attr/colorFavorite" android:backgroundTint="?attr/colorFavorite"
android:background="@drawable/favorite_indicator" /> android:background="@drawable/favorite_indicator" />

View file

@ -15,7 +15,6 @@
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:background="?attr/colorSurfaceContainerLow"
android:id="@+id/rlCardEntry" android:id="@+id/rlCardEntry"
android:paddingTop="5dp" android:paddingTop="5dp"
android:paddingBottom="5dp" android:paddingBottom="5dp"
@ -27,6 +26,8 @@
android:layout_width="15dp" android:layout_width="15dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginStart="-11dp" android:layout_marginStart="-11dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:backgroundTint="?attr/colorFavorite" android:backgroundTint="?attr/colorFavorite"
android:background="@drawable/favorite_indicator" /> android:background="@drawable/favorite_indicator" />