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

Commit 04aaba02 authored by Fengjiang Li's avatar Fengjiang Li Committed by Android (Google) Code Review
Browse files

Merge changes Iab300137,Id8e808f1 into udc-qpr-dev

* changes:
  [3/n] Pass grid name to preview grid
  [2/n] Let picker refresh preview when user selects a different grid
parents 95e5c0f8 8408e8c0
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -72,6 +72,9 @@ public interface CustomizationManager<T extends CustomizationOption> {
     */
    void apply(T option, Callback callback);

    /** Preview the given option without committing the change. */
    default void preview(T option) {}

    /**
     * Loads the available options for the type of Customization managed by this class, calling the
     * given callback when done.
+5 −1
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ public class GridOption implements CustomizationOption<GridOption>, Parcelable {
    };

    private final String mTitle;
    private final boolean mIsCurrent;
    private final String mIconShapePath;
    private final GridTileDrawable mTileDrawable;
    public final String name;
@@ -57,6 +56,7 @@ public class GridOption implements CustomizationOption<GridOption>, Parcelable {
    public final int cols;
    public final Uri previewImageUri;
    public final int previewPagesCount;
    private boolean mIsCurrent;

    public GridOption(String title, String name, boolean isCurrent, int rows, int cols,
            Uri previewImageUri, int previewPagesCount, String iconShapePath) {
@@ -71,6 +71,10 @@ public class GridOption implements CustomizationOption<GridOption>, Parcelable {
        this.previewPagesCount = previewPagesCount;
    }

    public void setIsCurrent(boolean isCurrent) {
        mIsCurrent = isCurrent;
    }

    protected GridOption(Parcel in) {
        mTitle = in.readString();
        mIsCurrent = in.readByte() != 0;
+5 −0
Original line number Diff line number Diff line
@@ -98,6 +98,11 @@ public class GridOptionsManager implements CustomizationManager<GridOption> {
        }
    }

    @Override
    public void preview(GridOption option) {
        mProvider.updateView();
    }

    @Override
    public void fetchOptions(OptionsFetchedListener<GridOption> callback, boolean reload) {
        sExecutorService.submit(() -> {
+4 −0
Original line number Diff line number Diff line
@@ -117,6 +117,10 @@ public class LauncherGridOptionsProvider {
        mPreviewUtils.renderPreview(bundle, callback);
    }

    void updateView() {
        mLiveData.postValue(new Object());
    }

    int applyGrid(String name) {
        ContentValues values = new ContentValues();
        values.put("name", name);
+28 −12
Original line number Diff line number Diff line
@@ -38,12 +38,14 @@ interface GridRepository {
    suspend fun isAvailable(): Boolean
    fun getOptionChanges(): Flow<Unit>
    suspend fun getOptions(): GridOptionItemsModel
    fun getSelectedOption(): GridOption?
}

class GridRepositoryImpl(
    private val applicationScope: CoroutineScope,
    private val manager: GridOptionsManager,
    private val backgroundDispatcher: CoroutineDispatcher,
    private val isGridApplyButtonEnabled: Boolean,
) : GridRepository {

    override suspend fun isAvailable(): Boolean {
@@ -55,6 +57,8 @@ class GridRepositoryImpl(

    private val selectedOption = MutableStateFlow<GridOption?>(null)

    override fun getSelectedOption() = selectedOption.value

    override suspend fun getOptions(): GridOptionItemsModel {
        return withContext(backgroundDispatcher) {
            suspendCancellableCoroutine { continuation ->
@@ -62,7 +66,11 @@ class GridRepositoryImpl(
                    object : CustomizationManager.OptionsFetchedListener<GridOption> {
                        override fun onOptionsLoaded(options: MutableList<GridOption>?) {
                            val optionsOrEmpty = options ?: emptyList()
                            // After Apply Button is added, we will rely on onSelected() method
                            // to update selectedOption.
                            if (!isGridApplyButtonEnabled || selectedOption.value == null) {
                                selectedOption.value = optionsOrEmpty.find { it.isActive(manager) }
                            }
                            continuation.resume(
                                GridOptionItemsModel.Loaded(
                                    optionsOrEmpty.map { option -> toModel(option) }
@@ -105,6 +113,13 @@ class GridRepositoryImpl(
    private suspend fun onSelected(option: GridOption) {
        withContext(backgroundDispatcher) {
            suspendCancellableCoroutine { continuation ->
                if (isGridApplyButtonEnabled) {
                    selectedOption.value?.setIsCurrent(false)
                    selectedOption.value = option
                    selectedOption.value?.setIsCurrent(true)
                    manager.preview(option)
                    continuation.resume(true)
                } else {
                    manager.apply(
                        option,
                        object : CustomizationManager.Callback {
@@ -120,6 +135,7 @@ class GridRepositoryImpl(
                }
            }
        }
    }

    private fun GridOption?.key(): String? {
        return if (this != null) "${cols}x${rows}" else null
Loading