Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20277084 authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

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
parent 5f2d28ad
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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">
+10 −5
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.themepicker.R
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 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
        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,21 +107,23 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
            this.homeWallpaperColors = homeWallpaperColors
            this.lockWallpaperColors = lockWallpaperColors
        }
        if (presetColorBundles == null || reload) {

        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())
            }
        }
    }

    private fun isLockScreenWallpaperLastApplied(): Boolean {
        // The WallpaperId increases every time a new wallpaper is set, so the larger wallpaper id
@@ -367,6 +371,7 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
            }

            presetColorBundles = bundles
            loaderJob = null
        }

    private fun buildPreset(