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

Commit ea078c3f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Reset support for themed icons (2/3)." into tm-qpr-dev

parents f028725d 7a06228d
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -77,6 +77,7 @@ java_defaults {
        "SettingsLibSettingsTheme",
        "SettingsLibSettingsTheme",
        "SystemUI-statsd",
        "SystemUI-statsd",
        "styleprotoslite",
        "styleprotoslite",
        "androidx.lifecycle_lifecycle-livedata-ktx",
        "androidx.lifecycle_lifecycle-runtime-ktx",
        "androidx.lifecycle_lifecycle-runtime-ktx",
        "androidx.lifecycle_lifecycle-viewmodel-ktx",
        "androidx.lifecycle_lifecycle-viewmodel-ktx",
        "androidx.recyclerview_recyclerview",
        "androidx.recyclerview_recyclerview",
+26 −7
Original line number Original line Diff line number Diff line
@@ -20,11 +20,13 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.LayoutInflater;


import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;


import com.android.customization.model.themedicon.domain.interactor.ThemedIconInteractor;
import com.android.customization.model.themedicon.domain.interactor.ThemedIconSnapshotRestorer;
import com.android.customization.picker.themedicon.ThemedIconSectionView;
import com.android.customization.picker.themedicon.ThemedIconSectionView;
import com.android.wallpaper.R;
import com.android.wallpaper.R;
import com.android.wallpaper.model.CustomizationSectionController;
import com.android.wallpaper.model.CustomizationSectionController;
import com.android.wallpaper.model.WorkspaceViewModel;


/** The {@link CustomizationSectionController} for themed icon section. */
/** The {@link CustomizationSectionController} for themed icon section. */
public class ThemedIconSectionController implements
public class ThemedIconSectionController implements
@@ -33,16 +35,26 @@ public class ThemedIconSectionController implements
    private static final String KEY_THEMED_ICON_ENABLED = "SAVED_THEMED_ICON_ENABLED";
    private static final String KEY_THEMED_ICON_ENABLED = "SAVED_THEMED_ICON_ENABLED";


    private final ThemedIconSwitchProvider mThemedIconOptionsProvider;
    private final ThemedIconSwitchProvider mThemedIconOptionsProvider;
    private final WorkspaceViewModel mWorkspaceViewModel;
    private final ThemedIconInteractor mInteractor;
    private final ThemedIconSnapshotRestorer mSnapshotRestorer;
    private final Observer<Boolean> mIsActivatedChangeObserver;


    private ThemedIconSectionView mThemedIconSectionView;
    private ThemedIconSectionView mThemedIconSectionView;
    private boolean mSavedThemedIconEnabled = false;
    private boolean mSavedThemedIconEnabled = false;



    public ThemedIconSectionController(
    public ThemedIconSectionController(ThemedIconSwitchProvider themedIconOptionsProvider,
            ThemedIconSwitchProvider themedIconOptionsProvider,
            WorkspaceViewModel workspaceViewModel, @Nullable Bundle savedInstanceState) {
            ThemedIconInteractor interactor,
            @Nullable Bundle savedInstanceState,
            ThemedIconSnapshotRestorer snapshotRestorer) {
        mThemedIconOptionsProvider = themedIconOptionsProvider;
        mThemedIconOptionsProvider = themedIconOptionsProvider;
        mWorkspaceViewModel = workspaceViewModel;
        mInteractor = interactor;
        mSnapshotRestorer = snapshotRestorer;
        mIsActivatedChangeObserver = isActivated -> {
            if (mThemedIconSectionView.isAttachedToWindow()) {
                mThemedIconSectionView.getSwitch().setChecked(isActivated);
            }
        };


        if (savedInstanceState != null) {
        if (savedInstanceState != null) {
            mSavedThemedIconEnabled = savedInstanceState.getBoolean(
            mSavedThemedIconEnabled = savedInstanceState.getBoolean(
@@ -64,15 +76,22 @@ public class ThemedIconSectionController implements
        mThemedIconSectionView.getSwitch().setChecked(mSavedThemedIconEnabled);
        mThemedIconSectionView.getSwitch().setChecked(mSavedThemedIconEnabled);
        mThemedIconOptionsProvider.fetchThemedIconEnabled(
        mThemedIconOptionsProvider.fetchThemedIconEnabled(
                enabled -> mThemedIconSectionView.getSwitch().setChecked(enabled));
                enabled -> mThemedIconSectionView.getSwitch().setChecked(enabled));
        mInteractor.isActivatedAsLiveData().observeForever(mIsActivatedChangeObserver);
        return mThemedIconSectionView;
        return mThemedIconSectionView;
    }
    }


    @Override
    public void release() {
        mInteractor.isActivatedAsLiveData().removeObserver(mIsActivatedChangeObserver);
    }

    private void onViewActivated(Context context, boolean viewActivated) {
    private void onViewActivated(Context context, boolean viewActivated) {
        if (context == null) {
        if (context == null) {
            return;
            return;
        }
        }
        mThemedIconOptionsProvider.setThemedIconEnabled(viewActivated);
        mThemedIconOptionsProvider.setThemedIconEnabled(viewActivated);
        mWorkspaceViewModel.getUpdateWorkspace().setValue(viewActivated);
        mInteractor.setActivated(viewActivated);
        mSnapshotRestorer.store(viewActivated);
    }
    }


    @Override
    @Override
+1 −1
Original line number Original line Diff line number Diff line
@@ -118,7 +118,7 @@ public class ThemedIconSwitchProvider {
     *
     *
     * <p>The value would also be stored in SharedPreferences.
     * <p>The value would also be stored in SharedPreferences.
     */
     */
    protected void setThemedIconEnabled(boolean enabled) {
    public void setThemedIconEnabled(boolean enabled) {
        mExecutorService.submit(() -> {
        mExecutorService.submit(() -> {
            ContentValues values = new ContentValues();
            ContentValues values = new ContentValues();
            values.put(COL_ICON_THEMED_VALUE, enabled);
            values.put(COL_ICON_THEMED_VALUE, enabled);
+30 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.android.customization.model.themedicon.data.repository

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow

class ThemeIconRepository {
    private val _isActivated = MutableStateFlow(false)
    val isActivated = _isActivated.asStateFlow()

    fun setActivated(isActivated: Boolean) {
        _isActivated.value = isActivated
    }
}
+38 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.android.customization.model.themedicon.domain.interactor

import androidx.lifecycle.LiveData
import androidx.lifecycle.asLiveData
import com.android.customization.model.themedicon.data.repository.ThemeIconRepository

class ThemedIconInteractor(
    private val repository: ThemeIconRepository,
) {
    val isActivated = repository.isActivated

    private var isActivatedAsLiveData: LiveData<Boolean>? = null

    fun isActivatedAsLiveData(): LiveData<Boolean> {
        return isActivatedAsLiveData ?: isActivated.asLiveData().also { isActivatedAsLiveData = it }
    }

    fun setActivated(isActivated: Boolean) {
        repository.setActivated(isActivated)
    }
}
Loading