1 package com.android.customization.module; 2 3 import android.app.WallpaperManager; 4 import android.os.Bundle; 5 6 import androidx.annotation.Nullable; 7 import androidx.fragment.app.FragmentActivity; 8 import androidx.lifecycle.LifecycleOwner; 9 import androidx.lifecycle.ViewModelProvider; 10 11 import com.android.customization.model.grid.GridOptionsManager; 12 import com.android.customization.model.themedicon.ThemedIconSectionController; 13 import com.android.customization.model.themedicon.ThemedIconSwitchProvider; 14 import com.android.customization.model.themedicon.domain.interactor.ThemedIconInteractor; 15 import com.android.customization.model.themedicon.domain.interactor.ThemedIconSnapshotRestorer; 16 import com.android.customization.module.logging.ThemesUserEventLogger; 17 import com.android.customization.picker.clock.ui.view.ClockViewFactory; 18 import com.android.customization.picker.clock.ui.viewmodel.ClockCarouselViewModel; 19 import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor; 20 import com.android.customization.picker.color.ui.section.ColorSectionController; 21 import com.android.customization.picker.color.ui.viewmodel.ColorPickerViewModel; 22 import com.android.customization.picker.grid.ui.section.GridSectionController; 23 import com.android.customization.picker.notifications.ui.section.NotificationSectionController; 24 import com.android.customization.picker.notifications.ui.viewmodel.NotificationSectionViewModel; 25 import com.android.customization.picker.preview.ui.section.PreviewWithClockCarouselSectionController; 26 import com.android.customization.picker.preview.ui.section.PreviewWithThemeSectionController; 27 import com.android.customization.picker.quickaffordance.ui.section.KeyguardQuickAffordanceSectionController; 28 import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel; 29 import com.android.customization.picker.settings.ui.section.ColorContrastSectionController; 30 import com.android.customization.picker.settings.ui.section.MoreSettingsSectionController; 31 import com.android.customization.picker.settings.ui.viewmodel.ColorContrastSectionViewModel; 32 import com.android.wallpaper.config.BaseFlags; 33 import com.android.wallpaper.model.CustomizationSectionController; 34 import com.android.wallpaper.model.CustomizationSectionController.CustomizationSectionNavigationController; 35 import com.android.wallpaper.model.PermissionRequester; 36 import com.android.wallpaper.model.Screen; 37 import com.android.wallpaper.model.WallpaperPreviewNavigator; 38 import com.android.wallpaper.module.CurrentWallpaperInfoFactory; 39 import com.android.wallpaper.module.CustomizationSections; 40 import com.android.wallpaper.picker.customization.data.repository.WallpaperColorsRepository; 41 import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor; 42 import com.android.wallpaper.picker.customization.ui.section.ConnectedSectionController; 43 import com.android.wallpaper.picker.customization.ui.section.WallpaperQuickSwitchSectionController; 44 import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationPickerViewModel; 45 import com.android.wallpaper.util.DisplayUtils; 46 47 import java.util.ArrayList; 48 import java.util.List; 49 50 /** {@link CustomizationSections} for the customization picker. */ 51 public final class DefaultCustomizationSections implements CustomizationSections { 52 53 private final ColorPickerViewModel.Factory mColorPickerViewModelFactory; 54 private final KeyguardQuickAffordancePickerViewModel.Factory 55 mKeyguardQuickAffordancePickerViewModelFactory; 56 private final ColorContrastSectionViewModel.Factory 57 mColorContrastSectionViewModelFactory; 58 private final NotificationSectionViewModel.Factory mNotificationSectionViewModelFactory; 59 private final BaseFlags mFlags; 60 private final ClockCarouselViewModel.Factory mClockCarouselViewModelFactory; 61 private final ClockViewFactory mClockViewFactory; 62 private final ThemedIconSnapshotRestorer mThemedIconSnapshotRestorer; 63 private final ThemedIconInteractor mThemedIconInteractor; 64 private final ColorPickerInteractor mColorPickerInteractor; 65 private final ThemesUserEventLogger mThemesUserEventLogger; 66 DefaultCustomizationSections( ColorPickerViewModel.Factory colorPickerViewModelFactory, KeyguardQuickAffordancePickerViewModel.Factory keyguardQuickAffordancePickerViewModelFactory, ColorContrastSectionViewModel.Factory colorContrastSectionViewModelFactory, NotificationSectionViewModel.Factory notificationSectionViewModelFactory, BaseFlags flags, ClockCarouselViewModel.Factory clockCarouselViewModelFactory, ClockViewFactory clockViewFactory, ThemedIconSnapshotRestorer themedIconSnapshotRestorer, ThemedIconInteractor themedIconInteractor, ColorPickerInteractor colorPickerInteractor, ThemesUserEventLogger themesUserEventLogger)67 public DefaultCustomizationSections( 68 ColorPickerViewModel.Factory colorPickerViewModelFactory, 69 KeyguardQuickAffordancePickerViewModel.Factory 70 keyguardQuickAffordancePickerViewModelFactory, 71 ColorContrastSectionViewModel.Factory colorContrastSectionViewModelFactory, 72 NotificationSectionViewModel.Factory notificationSectionViewModelFactory, 73 BaseFlags flags, 74 ClockCarouselViewModel.Factory clockCarouselViewModelFactory, 75 ClockViewFactory clockViewFactory, 76 ThemedIconSnapshotRestorer themedIconSnapshotRestorer, 77 ThemedIconInteractor themedIconInteractor, 78 ColorPickerInteractor colorPickerInteractor, 79 ThemesUserEventLogger themesUserEventLogger) { 80 mColorPickerViewModelFactory = colorPickerViewModelFactory; 81 mKeyguardQuickAffordancePickerViewModelFactory = 82 keyguardQuickAffordancePickerViewModelFactory; 83 mNotificationSectionViewModelFactory = notificationSectionViewModelFactory; 84 mFlags = flags; 85 mClockCarouselViewModelFactory = clockCarouselViewModelFactory; 86 mClockViewFactory = clockViewFactory; 87 mThemedIconSnapshotRestorer = themedIconSnapshotRestorer; 88 mThemedIconInteractor = themedIconInteractor; 89 mColorPickerInteractor = colorPickerInteractor; 90 mThemesUserEventLogger = themesUserEventLogger; 91 mColorContrastSectionViewModelFactory = colorContrastSectionViewModelFactory; 92 } 93 94 @Override getSectionControllersForScreen( Screen screen, FragmentActivity activity, LifecycleOwner lifecycleOwner, WallpaperColorsRepository wallpaperColorsRepository, PermissionRequester permissionRequester, WallpaperPreviewNavigator wallpaperPreviewNavigator, CustomizationSectionNavigationController sectionNavigationController, @Nullable Bundle savedInstanceState, CurrentWallpaperInfoFactory wallpaperInfoFactory, DisplayUtils displayUtils, CustomizationPickerViewModel customizationPickerViewModel, WallpaperInteractor wallpaperInteractor, WallpaperManager wallpaperManager, boolean isTwoPaneAndSmallWidth)95 public List<CustomizationSectionController<?>> getSectionControllersForScreen( 96 Screen screen, 97 FragmentActivity activity, 98 LifecycleOwner lifecycleOwner, 99 WallpaperColorsRepository wallpaperColorsRepository, 100 PermissionRequester permissionRequester, 101 WallpaperPreviewNavigator wallpaperPreviewNavigator, 102 CustomizationSectionNavigationController sectionNavigationController, 103 @Nullable Bundle savedInstanceState, 104 CurrentWallpaperInfoFactory wallpaperInfoFactory, 105 DisplayUtils displayUtils, 106 CustomizationPickerViewModel customizationPickerViewModel, 107 WallpaperInteractor wallpaperInteractor, 108 WallpaperManager wallpaperManager, 109 boolean isTwoPaneAndSmallWidth) { 110 List<CustomizationSectionController<?>> sectionControllers = new ArrayList<>(); 111 112 // Wallpaper section. 113 sectionControllers.add( 114 mFlags.isCustomClocksEnabled(activity) 115 ? new PreviewWithClockCarouselSectionController( 116 activity, 117 lifecycleOwner, 118 screen, 119 wallpaperInfoFactory, 120 wallpaperColorsRepository, 121 displayUtils, 122 mClockCarouselViewModelFactory, 123 mClockViewFactory, 124 wallpaperPreviewNavigator, 125 sectionNavigationController, 126 wallpaperInteractor, 127 mThemedIconInteractor, 128 mColorPickerInteractor, 129 wallpaperManager, 130 isTwoPaneAndSmallWidth, 131 customizationPickerViewModel) 132 : new PreviewWithThemeSectionController( 133 activity, 134 lifecycleOwner, 135 screen, 136 wallpaperInfoFactory, 137 wallpaperColorsRepository, 138 displayUtils, 139 wallpaperPreviewNavigator, 140 wallpaperInteractor, 141 mThemedIconInteractor, 142 mColorPickerInteractor, 143 wallpaperManager, 144 isTwoPaneAndSmallWidth, 145 customizationPickerViewModel)); 146 147 sectionControllers.add( 148 new ConnectedSectionController( 149 // Theme color section. 150 new ColorSectionController( 151 sectionNavigationController, 152 new ViewModelProvider( 153 activity, 154 mColorPickerViewModelFactory) 155 .get(ColorPickerViewModel.class), 156 lifecycleOwner), 157 // Wallpaper quick switch section. 158 new WallpaperQuickSwitchSectionController( 159 customizationPickerViewModel.getWallpaperQuickSwitchViewModel( 160 screen), 161 lifecycleOwner, 162 sectionNavigationController, 163 savedInstanceState == null), 164 /* reverseOrderWhenHorizontal= */ true)); 165 166 switch (screen) { 167 case LOCK_SCREEN: 168 // Lock screen quick affordances section. 169 sectionControllers.add( 170 new KeyguardQuickAffordanceSectionController( 171 sectionNavigationController, 172 new ViewModelProvider( 173 activity, 174 mKeyguardQuickAffordancePickerViewModelFactory) 175 .get(KeyguardQuickAffordancePickerViewModel.class), 176 lifecycleOwner)); 177 178 // Notifications section. 179 sectionControllers.add( 180 new NotificationSectionController( 181 new ViewModelProvider( 182 activity, 183 mNotificationSectionViewModelFactory) 184 .get(NotificationSectionViewModel.class), 185 lifecycleOwner)); 186 187 // More settings section. 188 sectionControllers.add(new MoreSettingsSectionController()); 189 break; 190 191 case HOME_SCREEN: 192 // Themed app icon section. 193 sectionControllers.add( 194 new ThemedIconSectionController( 195 ThemedIconSwitchProvider.getInstance(activity), 196 mThemedIconInteractor, 197 savedInstanceState, 198 mThemedIconSnapshotRestorer, 199 mThemesUserEventLogger)); 200 201 // Color contrast section 202 if (mFlags.isColorContrastControlEnabled()) { 203 sectionControllers.add( 204 new ColorContrastSectionController(new ViewModelProvider(activity, 205 mColorContrastSectionViewModelFactory) 206 .get(ColorContrastSectionViewModel.class), lifecycleOwner)); 207 } 208 // App grid section. 209 sectionControllers.add( 210 new GridSectionController( 211 GridOptionsManager.getInstance(activity), 212 sectionNavigationController, 213 lifecycleOwner, 214 /* isRevampedUiEnabled= */ true)); 215 break; 216 } 217 218 return sectionControllers; 219 } 220 } 221