Merge "[Search] Support flexible results-per-row in AllApps" into sc-dev

This commit is contained in:
Samuel Fufa authored and Android (Google) Code Review committed 2021-03-08 20:04:19 +00:00
commit 3b61fb2b01
2 files changed
+19 -11

No files matched your search

@@ -240,20 +240,18 @@ public class AllAppsGridAdapter extends
@Override
public int getSpanSize(int position) {
int viewType = mApps.getAdapterItems().get(position).viewType;
int totalSpans = mGridLayoutMgr.getSpanCount();
if (isIconViewType(viewType)) {
return 1 * SPAN_MULTIPLIER;
return totalSpans / mAppsPerRow;
} else if (mSearchAdapterProvider.isSearchView(viewType)) {
return mSearchAdapterProvider.getGridSpanSize(viewType, mAppsPerRow);
return totalSpans / mSearchAdapterProvider.getItemsPerRow(viewType, mAppsPerRow);
} else {
// Section breaks span the full width
return mAppsPerRow * SPAN_MULTIPLIER;
return totalSpans;
}
}
}
// multiplier to support adapter item column count that is not mAppsPerRow.
public static final int SPAN_MULTIPLIER = 3;
private final BaseDraggingActivity mLauncher;
private final LayoutInflater mLayoutInflater;
private final AlphabeticalAppsList mApps;
@@ -285,14 +283,17 @@ public class AllAppsGridAdapter extends
mOnIconClickListener = launcher.getItemOnClickListener();
setAppsPerRow(mLauncher.getDeviceProfile().inv.numAllAppsColumns);
mSearchAdapterProvider = searchAdapterProvider;
setAppsPerRow(mLauncher.getDeviceProfile().inv.numAllAppsColumns);
}
public void setAppsPerRow(int appsPerRow) {
mAppsPerRow = appsPerRow;
mGridLayoutMgr.setSpanCount(mAppsPerRow * SPAN_MULTIPLIER);
int totalSpans = mAppsPerRow;
for (int itemPerRow : mSearchAdapterProvider.getSupportedItemsPerRow()) {
totalSpans *= itemPerRow;
}
mGridLayoutMgr.setSpanCount(totalSpans);
}
/**
@@ -50,11 +50,18 @@ public abstract class SearchAdapterProvider {
public abstract AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater,
ViewGroup parent, int viewType);
/**
* Returns supported item per row combinations supported
*/
public int[] getSupportedItemsPerRow() {
return new int[]{};
}
/**
* Returns how many cells a view should span
*/
public int getGridSpanSize(int viewType, int appsPerRow) {
return appsPerRow * AllAppsGridAdapter.SPAN_MULTIPLIER;
public int getItemsPerRow(int viewType, int appsPerRow) {
return appsPerRow;
}
/**