summaryrefslogtreecommitdiff
path: root/src/com/android/customization/model/grid/GridSectionController.java
diff options
context:
space:
mode:
authorGeorge Zacharia <george.zcharia@gmail.com>2023-07-02 14:33:47 +0530
committerGeorge Zacharia <george.zcharia@gmail.com>2023-07-02 14:33:47 +0530
commit913b11dfd2b52e445c773838c766f0d4f8ba0d05 (patch)
treeadb07f584833593bad6fca5495927c276ceef531 /src/com/android/customization/model/grid/GridSectionController.java
parentb2d9a4961b3804f79c151630421d480846fd0176 (diff)
parentcc6f666d7c0bc3b6927f6e9e3c7e46123be6263d (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/grid/GridSectionController.java')
-rw-r--r--src/com/android/customization/model/grid/GridSectionController.java91
1 files changed, 70 insertions, 21 deletions
diff --git a/src/com/android/customization/model/grid/GridSectionController.java b/src/com/android/customization/model/grid/GridSectionController.java
index 2f54a1bf..c50bfcc2 100644
--- a/src/com/android/customization/model/grid/GridSectionController.java
+++ b/src/com/android/customization/model/grid/GridSectionController.java
@@ -22,8 +22,12 @@ import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+import androidx.lifecycle.LifecycleOwner;
+import androidx.lifecycle.Observer;
import com.android.customization.model.CustomizationManager.OptionsFetchedListener;
+import com.android.customization.model.grid.ui.fragment.GridFragment2;
import com.android.customization.picker.grid.GridFragment;
import com.android.customization.picker.grid.GridSectionView;
import com.android.wallpaper.R;
@@ -38,11 +42,22 @@ public class GridSectionController implements CustomizationSectionController<Gri
private final GridOptionsManager mGridOptionsManager;
private final CustomizationSectionNavigationController mSectionNavigationController;
+ private final boolean mIsRevampedUiEnabled;
+ private final Observer<Object> mOptionChangeObserver;
+ private final LifecycleOwner mLifecycleOwner;
+ private TextView mSectionDescription;
+ private View mSectionTile;
- public GridSectionController(GridOptionsManager gridOptionsManager,
- CustomizationSectionNavigationController sectionNavigationController) {
+ public GridSectionController(
+ GridOptionsManager gridOptionsManager,
+ CustomizationSectionNavigationController sectionNavigationController,
+ LifecycleOwner lifecycleOwner,
+ boolean isRevampedUiEnabled) {
mGridOptionsManager = gridOptionsManager;
mSectionNavigationController = sectionNavigationController;
+ mIsRevampedUiEnabled = isRevampedUiEnabled;
+ mLifecycleOwner = lifecycleOwner;
+ mOptionChangeObserver = o -> updateUi(/* reload= */ true);
}
@Override
@@ -52,34 +67,68 @@ public class GridSectionController implements CustomizationSectionController<Gri
@Override
public GridSectionView createView(Context context) {
- GridSectionView gridSectionView = (GridSectionView) LayoutInflater.from(context)
+ final GridSectionView gridSectionView = (GridSectionView) LayoutInflater.from(context)
.inflate(R.layout.grid_section_view, /* root= */ null);
- TextView sectionDescription = gridSectionView.findViewById(R.id.grid_section_description);
- View sectionTile = gridSectionView.findViewById(R.id.grid_section_tile);
+ mSectionDescription = gridSectionView.findViewById(R.id.grid_section_description);
+ mSectionTile = gridSectionView.findViewById(R.id.grid_section_tile);
// Fetch grid options to show currently set grid.
- mGridOptionsManager.fetchOptions(new OptionsFetchedListener<GridOption>() {
- @Override
- public void onOptionsLoaded(List<GridOption> options) {
- sectionDescription.setText(getActiveOption(options).getTitle());
- }
-
- @Override
- public void onError(@Nullable Throwable throwable) {
- if (throwable != null) {
- Log.e(TAG, "Error loading grid options", throwable);
- }
- sectionDescription.setText(R.string.something_went_wrong);
- sectionTile.setVisibility(View.GONE);
- }
- }, /* The result is getting when calling isAvailable(), so reload= */ false);
+ updateUi(/* The result is getting when calling isAvailable(), so reload= */ false);
+ if (mIsRevampedUiEnabled) {
+ mGridOptionsManager.getOptionChangeObservable(/* handler= */ null).observe(
+ mLifecycleOwner,
+ mOptionChangeObserver);
+ }
gridSectionView.setOnClickListener(
- v -> mSectionNavigationController.navigateTo(new GridFragment()));
+ v -> {
+ final Fragment gridFragment;
+ if (mIsRevampedUiEnabled) {
+ gridFragment = new GridFragment2();
+ } else {
+ gridFragment = new GridFragment();
+ }
+ mSectionNavigationController.navigateTo(gridFragment);
+ });
return gridSectionView;
}
+ @Override
+ public void release() {
+ if (mIsRevampedUiEnabled && mGridOptionsManager.isAvailable()) {
+ mGridOptionsManager.getOptionChangeObservable(/* handler= */ null).removeObserver(
+ mOptionChangeObserver
+ );
+ }
+ }
+
+ @Override
+ public void onTransitionOut() {
+ CustomizationSectionController.super.onTransitionOut();
+ }
+
+ private void updateUi(final boolean reload) {
+ mGridOptionsManager.fetchOptions(
+ new OptionsFetchedListener<GridOption>() {
+ @Override
+ public void onOptionsLoaded(List<GridOption> options) {
+ final String title = getActiveOption(options).getTitle();
+ mSectionDescription.setText(title);
+ }
+
+ @Override
+ public void onError(@Nullable Throwable throwable) {
+ if (throwable != null) {
+ Log.e(TAG, "Error loading grid options", throwable);
+ }
+ mSectionDescription.setText(R.string.something_went_wrong);
+ mSectionTile.setVisibility(View.GONE);
+ }
+ },
+ reload);
+ }
+
private GridOption getActiveOption(List<GridOption> options) {
return options.stream()
.filter(option -> option.isActive(mGridOptionsManager))