Skip to content

Commit ed4647d

Browse files
imhappidrchen
authored andcommittedOct 10, 2023
[Carousel] Cleaning up multi-browse strategy and removing compact arrangement
PiperOrigin-RevId: 572006115
1 parent f1da3c3 commit ed4647d

File tree

4 files changed

+1
-46
lines changed

4 files changed

+1
-46
lines changed
 

‎catalog/java/io/material/catalog/carousel/MultiBrowseCarouselDemoFragment.java

-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import androidx.annotation.Nullable;
2929
import com.google.android.material.carousel.CarouselLayoutManager;
3030
import com.google.android.material.carousel.CarouselSnapHelper;
31-
import com.google.android.material.carousel.MultiBrowseCarouselStrategy;
3231
import com.google.android.material.divider.MaterialDividerItemDecoration;
3332
import com.google.android.material.materialswitch.MaterialSwitch;
3433
import com.google.android.material.slider.Slider;
@@ -59,7 +58,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) {
5958
requireContext(), MaterialDividerItemDecoration.HORIZONTAL);
6059

6160
MaterialSwitch debugSwitch = view.findViewById(R.id.debug_switch);
62-
MaterialSwitch forceCompactSwitch = view.findViewById(R.id.force_compact_arrangement_switch);
6361
MaterialSwitch drawDividers = view.findViewById(R.id.draw_dividers_switch);
6462
MaterialSwitch snapSwitch = view.findViewById(R.id.snap_switch);
6563
AutoCompleteTextView itemCountDropdown = view.findViewById(R.id.item_count_dropdown);
@@ -82,11 +80,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) {
8280
multiBrowseStartRecyclerView, isChecked);
8381
});
8482

85-
forceCompactSwitch.setOnCheckedChangeListener(
86-
(buttonView, isChecked) ->
87-
multiBrowseStartCarouselLayoutManager.setCarouselStrategy(
88-
new MultiBrowseCarouselStrategy(isChecked)));
89-
9083
drawDividers.setOnCheckedChangeListener(
9184
(buttonView, isChecked) -> {
9285
if (isChecked) {

‎catalog/java/io/material/catalog/carousel/res/layout/cat_carousel_multi_browse_fragment.xml

-10
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@
4949
android:textAppearance="?attr/textAppearanceBodyLarge"
5050
android:text="@string/cat_carousel_debug_mode_label"/>
5151

52-
<com.google.android.material.materialswitch.MaterialSwitch
53-
android:id="@+id/force_compact_arrangement_switch"
54-
android:layout_width="match_parent"
55-
android:layout_height="wrap_content"
56-
android:checked="false"
57-
android:layout_marginHorizontal="16dp"
58-
android:layout_marginVertical="8dp"
59-
android:textAppearance="?attr/textAppearanceBodyLarge"
60-
android:text="@string/cat_carousel_force_compact_arrangement_label"/>
61-
6252
<com.google.android.material.materialswitch.MaterialSwitch
6353
android:id="@+id/draw_dividers_switch"
6454
android:layout_width="match_parent"

‎catalog/java/io/material/catalog/carousel/res/values/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
<resources>
1919
<string name="cat_carousel_debug_mode_label" translatable="false">Debug mode</string>
20-
<string name="cat_carousel_force_compact_arrangement_label" translatable="false">Force compact arrangement</string>
2120
<string name="cat_carousel_draw_dividers_label" translatable="false">Draw dividers</string>
2221
<string name="cat_carousel_enable_snap_label" description="The title of a switch to enable snapping to carousel items.[CHAR_LIMIT=NONE]">Enable Snap</string>
2322
<string name="cat_carousel_enable_fling_label" description="The title of a switch to enable the flinging gesture.[CHAR_LIMIT=NONE]">Enable fling</string>

‎lib/java/com/google/android/material/carousel/MultiBrowseCarouselStrategy.java

+1-28
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import androidx.recyclerview.widget.RecyclerView.LayoutParams;
2929
import android.view.View;
3030
import androidx.annotation.NonNull;
31-
import androidx.annotation.RestrictTo;
32-
import androidx.annotation.RestrictTo.Scope;
3331
import androidx.core.math.MathUtils;
3432

3533
/**
@@ -54,31 +52,6 @@ public final class MultiBrowseCarouselStrategy extends CarouselStrategy {
5452

5553
private static final int[] SMALL_COUNTS = new int[] {1};
5654
private static final int[] MEDIUM_COUNTS = new int[] {1, 0};
57-
private static final int[] MEDIUM_COUNTS_COMPACT = new int[] {0};
58-
59-
// True if medium items should never be added and arrangements should consist of only large and
60-
// small items. This will often result in a greater number of large items but more variability in
61-
// large item size. This can be desirable when optimizing for the greatest number of fully
62-
// unmasked items visible at once.
63-
// TODO(b/274604170): Remove this option
64-
private final boolean forceCompactArrangement;
65-
66-
public MultiBrowseCarouselStrategy() {
67-
this(false);
68-
}
69-
70-
/**
71-
* Create a new instance of {@link MultiBrowseCarouselStrategy}.
72-
*
73-
* @param forceCompactArrangement true if items should be fit in a way that maximizes the number
74-
* of large, unmasked items. false if this strategy is free to determine an opinionated
75-
* balance between item sizes.
76-
* @hide
77-
*/
78-
@RestrictTo(Scope.LIBRARY_GROUP)
79-
public MultiBrowseCarouselStrategy(boolean forceCompactArrangement) {
80-
this.forceCompactArrangement = forceCompactArrangement;
81-
}
8255

8356
@Override
8457
@NonNull
@@ -125,7 +98,7 @@ KeylineState onFirstChildMeasuredWithMargins(@NonNull Carousel carousel, @NonNul
12598
smallCounts = new int[] { 0 };
12699
}
127100

128-
int[] mediumCounts = forceCompactArrangement ? MEDIUM_COUNTS_COMPACT : MEDIUM_COUNTS;
101+
int[] mediumCounts = MEDIUM_COUNTS;
129102
if (carousel.getCarouselAlignment() == CarouselLayoutManager.ALIGNMENT_CENTER) {
130103
smallCounts = doubleCounts(smallCounts);
131104
mediumCounts = doubleCounts(mediumCounts);

0 commit comments

Comments
 (0)
Please sign in to comment.