summaryrefslogtreecommitdiff
path: root/src/com/android/wallpaper/picker/CustomizationPickerFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/wallpaper/picker/CustomizationPickerFragment.java')
-rw-r--r--src/com/android/wallpaper/picker/CustomizationPickerFragment.java118
1 files changed, 69 insertions, 49 deletions
diff --git a/src/com/android/wallpaper/picker/CustomizationPickerFragment.java b/src/com/android/wallpaper/picker/CustomizationPickerFragment.java
index 380fe13c..cb0820d0 100644
--- a/src/com/android/wallpaper/picker/CustomizationPickerFragment.java
+++ b/src/com/android/wallpaper/picker/CustomizationPickerFragment.java
@@ -33,34 +33,40 @@ import com.android.wallpaper.R;
import com.android.wallpaper.model.CustomizationSectionController;
import com.android.wallpaper.model.CustomizationSectionController.CustomizationSectionNavigationController;
import com.android.wallpaper.model.PermissionRequester;
-import com.android.wallpaper.model.WallpaperColorsViewModel;
import com.android.wallpaper.model.WallpaperPreviewNavigator;
-import com.android.wallpaper.model.WorkspaceViewModel;
import com.android.wallpaper.module.CustomizationSections;
import com.android.wallpaper.module.FragmentFactory;
import com.android.wallpaper.module.Injector;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.customization.ui.binder.CustomizationPickerBinder;
import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationPickerViewModel;
+import com.android.wallpaper.picker.customization.ui.viewmodel.WallpaperQuickSwitchViewModel;
import com.android.wallpaper.util.ActivityUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
+import kotlinx.coroutines.DisposableHandle;
+
/** The Fragment UI for customization sections. */
public class CustomizationPickerFragment extends AppbarFragment implements
CustomizationSectionNavigationController {
private static final String TAG = "CustomizationPickerFragment";
private static final String SCROLL_POSITION_Y = "SCROLL_POSITION_Y";
- private static final String KEY_IS_USE_REVAMPED_UI = "is_use_revamped_ui";
+ protected static final String KEY_IS_USE_REVAMPED_UI = "is_use_revamped_ui";
+ private static final String KEY_START_FROM_LOCK_SCREEN = "start_from_lock_screen";
+ private DisposableHandle mBinding;
/** Returns a new instance of {@link CustomizationPickerFragment}. */
- public static CustomizationPickerFragment newInstance(boolean isUseRevampedUi) {
+ public static CustomizationPickerFragment newInstance(
+ boolean isUseRevampedUi,
+ boolean startFromLockScreen) {
final CustomizationPickerFragment fragment = new CustomizationPickerFragment();
final Bundle args = new Bundle();
args.putBoolean(KEY_IS_USE_REVAMPED_UI, isUseRevampedUi);
+ args.putBoolean(KEY_START_FROM_LOCK_SCREEN, startFromLockScreen);
fragment.setArguments(args);
return fragment;
}
@@ -68,9 +74,11 @@ public class CustomizationPickerFragment extends AppbarFragment implements
// Note that the section views will be displayed by the list ordering.
private final List<CustomizationSectionController<?>> mSectionControllers = new ArrayList<>();
private NestedScrollView mNestedScrollView;
- @Nullable private Bundle mBackStackSavedInstanceState;
+ @Nullable
+ private Bundle mBackStackSavedInstanceState;
private final FragmentFactory mFragmentFactory;
- @Nullable private CustomizationPickerViewModel mViewModel;
+ @Nullable
+ private CustomizationPickerViewModel mViewModel;
public CustomizationPickerFragment() {
mFragmentFactory = InjectorProvider.getInjector().getFragmentFactory();
@@ -79,9 +87,11 @@ public class CustomizationPickerFragment extends AppbarFragment implements
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Nullable Bundle savedInstanceState) {
- final View view = inflater.inflate(R.layout.collapsing_toolbar_container_layout,
- container, /* attachToRoot= */ false);
-
+ final boolean shouldUseRevampedUi = shouldUseRevampedUi();
+ final int layoutId = shouldUseRevampedUi
+ ? R.layout.toolbar_container_layout
+ : R.layout.collapsing_toolbar_container_layout;
+ final View view = inflater.inflate(layoutId, container, false);
if (ActivityUtils.isLaunchedFromSettingsRelated(getActivity().getIntent())) {
setUpToolbar(view, !ActivityEmbeddingUtils.shouldHideNavigateUpButton(
getActivity(), /* isSecondLayerPage= */ true));
@@ -90,16 +100,7 @@ public class CustomizationPickerFragment extends AppbarFragment implements
}
final Injector injector = InjectorProvider.getInjector();
- final Bundle args = getArguments();
- final boolean isUseRevampedUi;
- if (args != null && args.containsKey(KEY_IS_USE_REVAMPED_UI)) {
- isUseRevampedUi = args.getBoolean(KEY_IS_USE_REVAMPED_UI);
- } else {
- throw new IllegalStateException(
- "Must contain KEY_IS_USE_REVAMPED_UI argument, did you instantiate directly"
- + " instead of using the newInstance function?");
- }
- if (isUseRevampedUi) {
+ if (shouldUseRevampedUi) {
setContentView(view, R.layout.fragment_tabbed_customization_picker);
mViewModel = new ViewModelProvider(
this,
@@ -108,19 +109,26 @@ public class CustomizationPickerFragment extends AppbarFragment implements
savedInstanceState,
injector.getUndoInteractor(requireContext()))
).get(CustomizationPickerViewModel.class);
+ final Bundle arguments = getArguments();
+ mViewModel.setInitialScreen(
+ arguments != null && arguments.getBoolean(KEY_START_FROM_LOCK_SCREEN));
setUpToolbarMenu(R.menu.undoable_customization_menu);
final Bundle finalSavedInstanceState = savedInstanceState;
- CustomizationPickerBinder.bind(
+ if (mBinding != null) {
+ mBinding.dispose();
+ }
+ mBinding = CustomizationPickerBinder.bind(
view,
getToolbarId(),
mViewModel,
this,
- isOnLockScreen -> getSectionControllers(
- isOnLockScreen
- ? CustomizationSections.Screen.LOCK_SCREEN
- : CustomizationSections.Screen.HOME_SCREEN,
- finalSavedInstanceState));
+ isOnLockScreen -> filterAvailableSections(
+ getSectionControllers(
+ isOnLockScreen
+ ? CustomizationSections.Screen.LOCK_SCREEN
+ : CustomizationSections.Screen.HOME_SCREEN,
+ finalSavedInstanceState)));
} else {
setContentView(view, R.layout.fragment_customization_picker);
}
@@ -132,7 +140,7 @@ public class CustomizationPickerFragment extends AppbarFragment implements
mNestedScrollView = view.findViewById(R.id.scroll_container);
- if (!isUseRevampedUi) {
+ if (!shouldUseRevampedUi) {
ViewGroup sectionContainer = view.findViewById(R.id.section_container);
sectionContainer.setOnApplyWindowInsetsListener((v, windowInsets) -> {
v.setPadding(
@@ -187,12 +195,12 @@ public class CustomizationPickerFragment extends AppbarFragment implements
@Override
protected int getToolbarId() {
- return R.id.action_bar;
+ return shouldUseRevampedUi() ? R.id.toolbar : R.id.action_bar;
}
@Override
protected int getToolbarColorId() {
- return android.R.color.transparent;
+ return shouldUseRevampedUi() ? R.color.toolbar_color : android.R.color.transparent;
}
@Override
@@ -257,14 +265,10 @@ public class CustomizationPickerFragment extends AppbarFragment implements
mSectionControllers.clear();
mSectionControllers.addAll(
- getAvailableSections(getAvailableSectionControllers(savedInstanceState)));
- }
-
- private List<CustomizationSectionController<?>> getAvailableSectionControllers(
- @Nullable Bundle savedInstanceState) {
- return getSectionControllers(
- null,
- savedInstanceState);
+ filterAvailableSections(
+ getSectionControllers(
+ null,
+ savedInstanceState)));
}
private List<CustomizationSectionController<?>> getSectionControllers(
@@ -272,50 +276,55 @@ public class CustomizationPickerFragment extends AppbarFragment implements
@Nullable Bundle savedInstanceState) {
final Injector injector = InjectorProvider.getInjector();
- WallpaperColorsViewModel wcViewModel = new ViewModelProvider(getActivity())
- .get(WallpaperColorsViewModel.class);
- WorkspaceViewModel workspaceViewModel = new ViewModelProvider(getActivity())
- .get(WorkspaceViewModel.class);
+ WallpaperQuickSwitchViewModel wallpaperQuickSwitchViewModel = new ViewModelProvider(
+ getActivity(),
+ WallpaperQuickSwitchViewModel.newFactory(
+ this,
+ savedInstanceState,
+ injector.getWallpaperInteractor(requireContext())))
+ .get(WallpaperQuickSwitchViewModel.class);
CustomizationSections sections = injector.getCustomizationSections(getActivity());
if (screen == null) {
return sections.getAllSectionControllers(
getActivity(),
getViewLifecycleOwner(),
- wcViewModel,
- workspaceViewModel,
+ injector.getWallpaperColorsViewModel(),
getPermissionRequester(),
getWallpaperPreviewNavigator(),
this,
savedInstanceState,
injector.getDisplayUtils(getActivity()));
} else {
- return sections.getSectionControllersForScreen(
+ return sections.getRevampedUISectionControllersForScreen(
screen,
getActivity(),
getViewLifecycleOwner(),
- wcViewModel,
- workspaceViewModel,
+ injector.getWallpaperColorsViewModel(),
getPermissionRequester(),
getWallpaperPreviewNavigator(),
this,
savedInstanceState,
injector.getCurrentWallpaperInfoFactory(requireContext()),
- injector.getDisplayUtils(getActivity()));
+ injector.getDisplayUtils(getActivity()),
+ wallpaperQuickSwitchViewModel,
+ injector.getWallpaperInteractor(requireContext()));
}
}
- protected List<CustomizationSectionController<?>> getAvailableSections(
+ /** Returns a filtered list containing only the available section controllers. */
+ protected List<CustomizationSectionController<?>> filterAvailableSections(
List<CustomizationSectionController<?>> controllers) {
return controllers.stream()
.filter(controller -> {
- if(controller.isAvailable(getContext())) {
+ if (controller.isAvailable(getContext())) {
return true;
} else {
controller.release();
Log.d(TAG, "Section is not available: " + controller);
return false;
- }})
+ }
+ })
.collect(Collectors.toList());
}
@@ -326,4 +335,15 @@ public class CustomizationPickerFragment extends AppbarFragment implements
private WallpaperPreviewNavigator getWallpaperPreviewNavigator() {
return (WallpaperPreviewNavigator) getActivity();
}
+
+ private boolean shouldUseRevampedUi() {
+ final Bundle args = getArguments();
+ if (args != null && args.containsKey(KEY_IS_USE_REVAMPED_UI)) {
+ return args.getBoolean(KEY_IS_USE_REVAMPED_UI);
+ } else {
+ throw new IllegalStateException(
+ "Must contain KEY_IS_USE_REVAMPED_UI argument, did you instantiate directly"
+ + " instead of using the newInstance function?");
+ }
+ }
}