summaryrefslogtreecommitdiff
path: root/src/com/android
diff options
context:
space:
mode:
authorChing-Sung Li <chriscsli@google.com>2021-06-30 15:37:48 +0800
committerChing Sung Li <chriscsli@google.com>2021-07-01 10:31:08 +0000
commit3f62f8a220ccdcdf517fbd974826160c396765f0 (patch)
treee5f84939e958f538bf442b437140aa773a51c2d5 /src/com/android
parent386b180e2db9b1ae38b30fbad50467314328ee0e (diff)
downloadThemePicker-3f62f8a220ccdcdf517fbd974826160c396765f0.tar.gz
Save themed icon switch's chcked state in savedInstanceState
Add section views with tasks in the message queue (view#post()) running separately would see themed icon switch's checkd state changing quickly. Save the state to the savedInstanceState and restore it could prevent this phenomenon. Bug: 192200516 Test: Manual Change-Id: I04309bd634e2b9a240570fe304dfa34372c2b6df
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/customization/model/themedicon/ThemedIconSectionController.java30
-rw-r--r--src/com/android/customization/module/DefaultCustomizationSections.java3
2 files changed, 27 insertions, 6 deletions
diff --git a/src/com/android/customization/model/themedicon/ThemedIconSectionController.java b/src/com/android/customization/model/themedicon/ThemedIconSectionController.java
index c097b6b0..a1623d18 100644
--- a/src/com/android/customization/model/themedicon/ThemedIconSectionController.java
+++ b/src/com/android/customization/model/themedicon/ThemedIconSectionController.java
@@ -16,6 +16,7 @@
package com.android.customization.model.themedicon;
import android.content.Context;
+import android.os.Bundle;
import android.view.LayoutInflater;
import androidx.annotation.Nullable;
@@ -29,14 +30,24 @@ import com.android.wallpaper.model.WorkspaceViewModel;
public class ThemedIconSectionController implements
CustomizationSectionController<ThemedIconSectionView> {
+ private static final String KEY_THEMED_ICON_ENABLED = "SAVED_THEMED_ICON_ENABLED";
+
private final ThemedIconSwitchProvider mThemedIconOptionsProvider;
private final WorkspaceViewModel mWorkspaceViewModel;
+ private ThemedIconSectionView mThemedIconSectionView;
+ private boolean mSavedThemedIconEnabled = false;
+
public ThemedIconSectionController(ThemedIconSwitchProvider themedIconOptionsProvider,
- WorkspaceViewModel workspaceViewModel) {
+ WorkspaceViewModel workspaceViewModel, @Nullable Bundle savedInstanceState) {
mThemedIconOptionsProvider = themedIconOptionsProvider;
mWorkspaceViewModel = workspaceViewModel;
+
+ if (savedInstanceState != null) {
+ mSavedThemedIconEnabled = savedInstanceState.getBoolean(
+ KEY_THEMED_ICON_ENABLED, /* defaultValue= */ false);
+ }
}
@Override
@@ -46,13 +57,14 @@ public class ThemedIconSectionController implements
@Override
public ThemedIconSectionView createView(Context context) {
- ThemedIconSectionView themedIconColorSectionView =
+ mThemedIconSectionView =
(ThemedIconSectionView) LayoutInflater.from(context).inflate(
R.layout.themed_icon_section_view, /* root= */ null);
- themedIconColorSectionView.setViewListener(this::onViewActivated);
+ mThemedIconSectionView.setViewListener(this::onViewActivated);
+ mThemedIconSectionView.getSwitch().setChecked(mSavedThemedIconEnabled);
mThemedIconOptionsProvider.fetchThemedIconEnabled(
- enabled -> themedIconColorSectionView.getSwitch().setChecked(enabled));
- return themedIconColorSectionView;
+ enabled -> mThemedIconSectionView.getSwitch().setChecked(enabled));
+ return mThemedIconSectionView;
}
private void onViewActivated(Context context, boolean viewActivated) {
@@ -62,4 +74,12 @@ public class ThemedIconSectionController implements
mThemedIconOptionsProvider.setThemedIconEnabled(viewActivated);
mWorkspaceViewModel.getUpdateWorkspace().setValue(viewActivated);
}
+
+ @Override
+ public void onSaveInstanceState(Bundle savedInstanceState) {
+ if (mThemedIconSectionView != null) {
+ savedInstanceState.putBoolean(KEY_THEMED_ICON_ENABLED,
+ mThemedIconSectionView.getSwitch().isChecked());
+ }
+ }
}
diff --git a/src/com/android/customization/module/DefaultCustomizationSections.java b/src/com/android/customization/module/DefaultCustomizationSections.java
index eb5296d9..a4510eab 100644
--- a/src/com/android/customization/module/DefaultCustomizationSections.java
+++ b/src/com/android/customization/module/DefaultCustomizationSections.java
@@ -47,7 +47,8 @@ public final class DefaultCustomizationSections implements CustomizationSections
// Themed app icon section.
sectionControllers.add(new ThemedIconSectionController(
- ThemedIconSwitchProvider.getInstance(activity), workspaceViewModel));
+ ThemedIconSwitchProvider.getInstance(activity), workspaceViewModel,
+ savedInstanceState));
// App grid section.
sectionControllers.add(new GridSectionController(