Set max num of slices allowed in panel view
Setup a max allowed num for PanelSlicesAdapter to prevent too many slices showing in single panel. Test: Manual verify Test: atest PanelSlicesAdapterTest Fixes: 129358092 Change-Id: I7b72a29489e597b8309d74841eaeab0fe42aace6
This commit is contained in:
@@ -44,6 +44,12 @@ import java.util.List;
|
||||
public class PanelSlicesAdapter
|
||||
extends RecyclerView.Adapter<PanelSlicesAdapter.SliceRowViewHolder> {
|
||||
|
||||
/**
|
||||
* Maximum number of slices allowed on the panel view.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static final int MAX_NUM_OF_SLICES = 5;
|
||||
|
||||
private final List<LiveData<Slice>> mSliceLiveData;
|
||||
private final int mMetricsCategory;
|
||||
private final PanelFragment mPanelFragment;
|
||||
@@ -70,14 +76,21 @@ public class PanelSlicesAdapter
|
||||
sliceRowViewHolder.onBind(mSliceLiveData.get(position));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of available items in the adapter with max number of slices enforced.
|
||||
*/
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mSliceLiveData.size();
|
||||
return Math.min(mSliceLiveData.size(), MAX_NUM_OF_SLICES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the available data from the adapter. If the number of Slices over the max number
|
||||
* allowed, the list will only have the first MAX_NUM_OF_SLICES of slices.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
List<LiveData<Slice>> getData() {
|
||||
return mSliceLiveData;
|
||||
return mSliceLiveData.subList(0, getItemCount());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user