Skip to content

Commit

Permalink
[Carousel] Cleaning up multi-browse strategy and removing compact arr…
Browse files Browse the repository at this point in the history
…angement

PiperOrigin-RevId: 572006115
  • Loading branch information
imhappi authored and drchen committed Oct 10, 2023
1 parent f1da3c3 commit ed4647d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 46 deletions.
Expand Up @@ -28,7 +28,6 @@
import androidx.annotation.Nullable;
import com.google.android.material.carousel.CarouselLayoutManager;
import com.google.android.material.carousel.CarouselSnapHelper;
import com.google.android.material.carousel.MultiBrowseCarouselStrategy;
import com.google.android.material.divider.MaterialDividerItemDecoration;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.slider.Slider;
Expand Down Expand Up @@ -59,7 +58,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) {
requireContext(), MaterialDividerItemDecoration.HORIZONTAL);

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

forceCompactSwitch.setOnCheckedChangeListener(
(buttonView, isChecked) ->
multiBrowseStartCarouselLayoutManager.setCarouselStrategy(
new MultiBrowseCarouselStrategy(isChecked)));

drawDividers.setOnCheckedChangeListener(
(buttonView, isChecked) -> {
if (isChecked) {
Expand Down
Expand Up @@ -49,16 +49,6 @@
android:textAppearance="?attr/textAppearanceBodyLarge"
android:text="@string/cat_carousel_debug_mode_label"/>

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/force_compact_arrangement_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp"
android:textAppearance="?attr/textAppearanceBodyLarge"
android:text="@string/cat_carousel_force_compact_arrangement_label"/>

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/draw_dividers_switch"
android:layout_width="match_parent"
Expand Down
Expand Up @@ -17,7 +17,6 @@

<resources>
<string name="cat_carousel_debug_mode_label" translatable="false">Debug mode</string>
<string name="cat_carousel_force_compact_arrangement_label" translatable="false">Force compact arrangement</string>
<string name="cat_carousel_draw_dividers_label" translatable="false">Draw dividers</string>
<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>
<string name="cat_carousel_enable_fling_label" description="The title of a switch to enable the flinging gesture.[CHAR_LIMIT=NONE]">Enable fling</string>
Expand Down
Expand Up @@ -28,8 +28,6 @@
import androidx.recyclerview.widget.RecyclerView.LayoutParams;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.Scope;
import androidx.core.math.MathUtils;

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

private static final int[] SMALL_COUNTS = new int[] {1};
private static final int[] MEDIUM_COUNTS = new int[] {1, 0};
private static final int[] MEDIUM_COUNTS_COMPACT = new int[] {0};

// True if medium items should never be added and arrangements should consist of only large and
// small items. This will often result in a greater number of large items but more variability in
// large item size. This can be desirable when optimizing for the greatest number of fully
// unmasked items visible at once.
// TODO(b/274604170): Remove this option
private final boolean forceCompactArrangement;

public MultiBrowseCarouselStrategy() {
this(false);
}

/**
* Create a new instance of {@link MultiBrowseCarouselStrategy}.
*
* @param forceCompactArrangement true if items should be fit in a way that maximizes the number
* of large, unmasked items. false if this strategy is free to determine an opinionated
* balance between item sizes.
* @hide
*/
@RestrictTo(Scope.LIBRARY_GROUP)
public MultiBrowseCarouselStrategy(boolean forceCompactArrangement) {
this.forceCompactArrangement = forceCompactArrangement;
}

@Override
@NonNull
Expand Down Expand Up @@ -125,7 +98,7 @@ KeylineState onFirstChildMeasuredWithMargins(@NonNull Carousel carousel, @NonNul
smallCounts = new int[] { 0 };
}

int[] mediumCounts = forceCompactArrangement ? MEDIUM_COUNTS_COMPACT : MEDIUM_COUNTS;
int[] mediumCounts = MEDIUM_COUNTS;
if (carousel.getCarouselAlignment() == CarouselLayoutManager.ALIGNMENT_CENTER) {
smallCounts = doubleCounts(smallCounts);
mediumCounts = doubleCounts(mediumCounts);
Expand Down

0 comments on commit ed4647d

Please sign in to comment.