Change the logic of flexible layout

Change the logic of determining 2 column or 3 column layout in the wallpaper selecting page.
It will be determined by the wallpaper count in the collection.

Bug: 186005937
Test: manual
Change-Id: Ic13d607bb5dfbea0d2d58ec225f975b4df7dc565
diff --git a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
index 655187f..fda20a6 100755
--- a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
+++ b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
@@ -125,6 +125,7 @@
     private static final String TAG_SET_WALLPAPER_ERROR_DIALOG_FRAGMENT =
             "individual_set_wallpaper_error_dialog";
     private static final String KEY_NIGHT_MODE = "IndividualPickerFragment.NIGHT_MODE";
+    private static final int MAX_CAPACITY_IN_FEWER_COLUMN_LAYOUT = 8;
 
     /**
      * An interface for updating the thumbnail with the specific wallpaper.
@@ -430,8 +431,6 @@
             mPackageStatusNotifier.addListener(mAppStatusListener,
                     WallpaperService.SERVICE_INTERFACE);
         }
-
-        maybeSetUpImageGrid();
     }
 
     void fetchWallpapers(boolean forceReload) {
@@ -446,6 +445,7 @@
                 for (WallpaperInfo wallpaper : wallpapers) {
                     mWallpapers.add(wallpaper);
                 }
+                maybeSetUpImageGrid();
 
                 // Wallpapers may load after the adapter is initialized, in which case we have
                 // to explicitly notify that the data set has changed.
@@ -565,7 +565,7 @@
         }
     }
 
-    private void maybeSetUpImageGrid() {
+    protected void maybeSetUpImageGrid() {
         // Skip if mImageGrid been initialized yet
         if (mImageGrid == null) {
             return;
@@ -583,7 +583,7 @@
         int edgePadding = getEdgePadding();
         mImageGrid.setPadding(edgePadding, mImageGrid.getPaddingTop(), edgePadding,
                 mImageGrid.getPaddingBottom());
-        mTileSizePx = mCategoryProvider.isFeaturedCategory(mCategory)
+        mTileSizePx = isFewerColumnLayout()
                 ? SizeCalculator.getFeaturedIndividualTileSize(getActivity())
                 : SizeCalculator.getIndividualTileSize(getActivity());
         setUpImageGrid();
@@ -592,8 +592,12 @@
                         mImageGrid, (BottomSheetHost) getParentFragment(), getNumColumns()));
     }
 
+    private boolean isFewerColumnLayout() {
+        return mWallpapers != null && mWallpapers.size() <= MAX_CAPACITY_IN_FEWER_COLUMN_LAYOUT;
+    }
+
     private int getGridItemPaddingHorizontal() {
-        return mCategoryProvider.isFeaturedCategory(mCategory)
+        return isFewerColumnLayout()
                 ? getResources().getDimensionPixelSize(
                 R.dimen.grid_item_featured_individual_padding_horizontal)
                 : getResources().getDimensionPixelSize(
@@ -601,14 +605,14 @@
     }
 
     private int getGridItemPaddingBottom() {
-        return mCategoryProvider.isFeaturedCategory(mCategory)
+        return isFewerColumnLayout()
                 ? getResources().getDimensionPixelSize(
                 R.dimen.grid_item_featured_individual_padding_bottom)
                 : getResources().getDimensionPixelSize(R.dimen.grid_item_individual_padding_bottom);
     }
 
     private int getEdgePadding() {
-        return mCategoryProvider.isFeaturedCategory(mCategory)
+        return isFewerColumnLayout()
                 ? getResources().getDimensionPixelSize(R.dimen.featured_wallpaper_grid_edge_space)
                 : getResources().getDimensionPixelSize(R.dimen.wallpaper_grid_edge_space);
     }
@@ -886,7 +890,7 @@
         if (activity == null) {
             return 1;
         }
-        return mCategoryProvider.isFeaturedCategory(mCategory)
+        return isFewerColumnLayout()
                 ? SizeCalculator.getNumFeaturedIndividualColumns(activity)
                 : SizeCalculator.getNumIndividualColumns(activity);
     }