Merge "Set max num of slices allowed in panel view" into qt-dev

This commit is contained in:
Linda Tseng
2019-04-19 17:19:59 +00:00
committed by Android (Google) Code Review
2 changed files with 44 additions and 16 deletions

View File

@@ -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());
}
/**