Loading Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -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", Loading src/com/android/customization/model/themedicon/ThemedIconSectionController.java +26 −7 Original line number Original line Diff line number Diff line Loading @@ -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 Loading @@ -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( Loading @@ -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 Loading src/com/android/customization/model/themedicon/ThemedIconSwitchProvider.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -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); Loading src/com/android/customization/model/themedicon/data/repository/ThemedIconRepository.kt 0 → 100644 +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 } } src/com/android/customization/model/themedicon/domain/interactor/ThemedIconInteractor.kt 0 → 100644 +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
Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -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", Loading
src/com/android/customization/model/themedicon/ThemedIconSectionController.java +26 −7 Original line number Original line Diff line number Diff line Loading @@ -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 Loading @@ -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( Loading @@ -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 Loading
src/com/android/customization/model/themedicon/ThemedIconSwitchProvider.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -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); Loading
src/com/android/customization/model/themedicon/data/repository/ThemedIconRepository.kt 0 → 100644 +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 } }
src/com/android/customization/model/themedicon/domain/interactor/ThemedIconInteractor.kt 0 → 100644 +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) } }