diff options
| author | George Zacharia <george.zcharia@gmail.com> | 2023-07-02 14:33:47 +0530 |
|---|---|---|
| committer | George Zacharia <george.zcharia@gmail.com> | 2023-07-02 14:33:47 +0530 |
| commit | 913b11dfd2b52e445c773838c766f0d4f8ba0d05 (patch) | |
| tree | adb07f584833593bad6fca5495927c276ceef531 /src/com/android/customization/model/themedicon/ThemedIconSectionController.java | |
| parent | b2d9a4961b3804f79c151630421d480846fd0176 (diff) | |
| parent | cc6f666d7c0bc3b6927f6e9e3c7e46123be6263d (diff) | |
Merge tag 'android-13.0.0_r52' of https://android.googlesource.com/platform/packages/apps/ThemePicker into HEADHEADt13.0
Android 13.0.0 Release 52 (TQ3A.230605.012)
Change-Id: I2cea11fa2f1f02fbd3c9d21cfc1697a79d42a5b7
Diffstat (limited to 'src/com/android/customization/model/themedicon/ThemedIconSectionController.java')
| -rw-r--r-- | src/com/android/customization/model/themedicon/ThemedIconSectionController.java | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/com/android/customization/model/themedicon/ThemedIconSectionController.java b/src/com/android/customization/model/themedicon/ThemedIconSectionController.java index a1623d18..5d551a6a 100644 --- a/src/com/android/customization/model/themedicon/ThemedIconSectionController.java +++ b/src/com/android/customization/model/themedicon/ThemedIconSectionController.java @@ -20,11 +20,13 @@ import android.os.Bundle; import android.view.LayoutInflater; 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.wallpaper.R; import com.android.wallpaper.model.CustomizationSectionController; -import com.android.wallpaper.model.WorkspaceViewModel; /** The {@link CustomizationSectionController} for themed icon section. */ 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 final ThemedIconSwitchProvider mThemedIconOptionsProvider; - private final WorkspaceViewModel mWorkspaceViewModel; + private final ThemedIconInteractor mInteractor; + private final ThemedIconSnapshotRestorer mSnapshotRestorer; + private final Observer<Boolean> mIsActivatedChangeObserver; private ThemedIconSectionView mThemedIconSectionView; private boolean mSavedThemedIconEnabled = false; - - public ThemedIconSectionController(ThemedIconSwitchProvider themedIconOptionsProvider, - WorkspaceViewModel workspaceViewModel, @Nullable Bundle savedInstanceState) { + public ThemedIconSectionController( + ThemedIconSwitchProvider themedIconOptionsProvider, + ThemedIconInteractor interactor, + @Nullable Bundle savedInstanceState, + ThemedIconSnapshotRestorer snapshotRestorer) { mThemedIconOptionsProvider = themedIconOptionsProvider; - mWorkspaceViewModel = workspaceViewModel; + mInteractor = interactor; + mSnapshotRestorer = snapshotRestorer; + mIsActivatedChangeObserver = isActivated -> { + if (mThemedIconSectionView.isAttachedToWindow()) { + mThemedIconSectionView.getSwitch().setChecked(isActivated); + } + }; if (savedInstanceState != null) { mSavedThemedIconEnabled = savedInstanceState.getBoolean( @@ -64,15 +76,22 @@ public class ThemedIconSectionController implements mThemedIconSectionView.getSwitch().setChecked(mSavedThemedIconEnabled); mThemedIconOptionsProvider.fetchThemedIconEnabled( enabled -> mThemedIconSectionView.getSwitch().setChecked(enabled)); + mInteractor.isActivatedAsLiveData().observeForever(mIsActivatedChangeObserver); return mThemedIconSectionView; } + @Override + public void release() { + mInteractor.isActivatedAsLiveData().removeObserver(mIsActivatedChangeObserver); + } + private void onViewActivated(Context context, boolean viewActivated) { if (context == null) { return; } mThemedIconOptionsProvider.setThemedIconEnabled(viewActivated); - mWorkspaceViewModel.getUpdateWorkspace().setValue(viewActivated); + mInteractor.setActivated(viewActivated); + mSnapshotRestorer.store(viewActivated); } @Override |
