Improve color section loading

Make sure preset colors are loaded only once by keeping track of the
loading job and joining it.
Make the overflow option the same height as a selected option to avoid
a change in the section height when the options load.

Bug: 332749262
Test: atest WallpaperPickerTests
Test: Manually compared jank. See video in bug
Flag: N/A
Change-Id: I033aa8dde215fbe1cc610f279b6934a5b5340429
diff --git a/res/layout/color_option_overflow_no_background.xml b/res/layout/color_option_overflow_no_background.xml
index abb9c6b..7a37536 100644
--- a/res/layout/color_option_overflow_no_background.xml
+++ b/res/layout/color_option_overflow_no_background.xml
@@ -24,7 +24,10 @@
     android:layout_gravity="center"
     android:clipChildren="false"
     android:gravity="center"
-    android:padding="@dimen/option_tile_grid_tile_padding_min"
+    android:paddingStart="@dimen/option_tile_grid_tile_padding_min"
+    android:paddingEnd="@dimen/option_tile_grid_tile_padding_min"
+    android:paddingTop="@dimen/option_tile_grid_icon_padding_min"
+    android:paddingBottom="@dimen/option_tile_grid_icon_padding_min"
     android:layout_weight="1"
     app:layout_constraintDimensionRatio="1:1"
     app:layout_constraintWidth_max="@dimen/component_color_chip_small_diameter_default">
diff --git a/src/com/android/customization/model/color/ColorProvider.kt b/src/com/android/customization/model/color/ColorProvider.kt
index eb8d8df..2d7037e 100644
--- a/src/com/android/customization/model/color/ColorProvider.kt
+++ b/src/com/android/customization/model/color/ColorProvider.kt
@@ -42,6 +42,7 @@
 import com.android.wallpaper.module.InjectorProvider
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.Job
 import kotlinx.coroutines.SupervisorJob
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
@@ -62,6 +63,7 @@
         private const val ALPHA_MASK = 0xFF
     }
 
+    private var loaderJob: Job? = null
     private val monetEnabled = ColorUtils.isMonetEnabled(context)
     // TODO(b/202145216): Use style method to fetch the list of style.
     private var styleList =
@@ -105,19 +107,21 @@
             this.homeWallpaperColors = homeWallpaperColors
             this.lockWallpaperColors = lockWallpaperColors
         }
-        if (presetColorBundles == null || reload) {
-            scope.launch {
+
+        scope.launch {
+            loaderJob?.join()
+            if (presetColorBundles == null || reload) {
                 try {
-                    loadPreset()
+                    loaderJob = launch { loadPreset() }
                 } catch (e: Throwable) {
                     colorsAvailable = false
                     callback?.onError(e)
                     return@launch
                 }
                 callback?.onOptionsLoaded(buildFinalList())
+            } else {
+                callback?.onOptionsLoaded(buildFinalList())
             }
-        } else {
-            callback?.onOptionsLoaded(buildFinalList())
         }
     }
 
@@ -367,6 +371,7 @@
             }
 
             presetColorBundles = bundles
+            loaderJob = null
         }
 
     private fun buildPreset(