Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.customization.module; |
| 17 | |
George Lin | a2b70df | 2022-09-15 18:37:54 +0000 | [diff] [blame] | 18 | import static com.android.wallpaper.picker.PreviewFragment.ARG_FULL_SCREEN; |
| 19 | import static com.android.wallpaper.picker.PreviewFragment.ARG_PREVIEW_MODE; |
| 20 | import static com.android.wallpaper.picker.PreviewFragment.ARG_TESTING_MODE_ENABLED; |
| 21 | import static com.android.wallpaper.picker.PreviewFragment.ARG_VIEW_AS_HOME; |
| 22 | import static com.android.wallpaper.picker.PreviewFragment.ARG_WALLPAPER; |
| 23 | |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 24 | import android.app.Activity; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 25 | import android.content.Context; |
Chuck Liao | 4a777fb | 2020-08-15 04:15:46 +0800 | [diff] [blame] | 26 | import android.content.Intent; |
| 27 | import android.net.Uri; |
George Lin | a2b70df | 2022-09-15 18:37:54 +0000 | [diff] [blame] | 28 | import android.os.Bundle; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 29 | |
| 30 | import androidx.fragment.app.Fragment; |
Santiago Etchebehere | 43b2518 | 2019-05-24 11:37:15 -0700 | [diff] [blame] | 31 | import androidx.fragment.app.FragmentActivity; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 32 | |
Santiago Etchebehere | 43b2518 | 2019-05-24 11:37:15 -0700 | [diff] [blame] | 33 | import com.android.customization.model.theme.OverlayManagerCompat; |
| 34 | import com.android.customization.model.theme.ThemeBundleProvider; |
| 35 | import com.android.customization.model.theme.ThemeManager; |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 36 | import com.android.customization.picker.quickaffordance.data.repository.KeyguardQuickAffordancePickerRepository; |
| 37 | import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor; |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 38 | import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordanceSnapshotRestorer; |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 39 | import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel; |
| 40 | import com.android.systemui.shared.quickaffordance.data.content.KeyguardQuickAffordanceProviderClient; |
| 41 | import com.android.systemui.shared.quickaffordance.data.content.KeyguardQuickAffordanceProviderClientImpl; |
Alejandro Nijamkin | 9825cdb | 2022-12-15 16:42:42 -0800 | [diff] [blame] | 42 | import com.android.wallpaper.config.BaseFlags; |
George Lin | a2b70df | 2022-09-15 18:37:54 +0000 | [diff] [blame] | 43 | import com.android.wallpaper.model.LiveWallpaperInfo; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 44 | import com.android.wallpaper.model.WallpaperInfo; |
Chihhang Chuang | 8d14e8a | 2021-06-15 14:03:18 +0800 | [diff] [blame] | 45 | import com.android.wallpaper.module.CustomizationSections; |
Alejandro Nijamkin | 839e75c | 2022-12-02 15:50:52 -0800 | [diff] [blame] | 46 | import com.android.wallpaper.module.FragmentFactory; |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 47 | import com.android.wallpaper.module.WallpaperPicker2Injector; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 48 | import com.android.wallpaper.module.WallpaperPreferences; |
Chihhang Chuang | eecf85e | 2021-06-14 13:48:57 +0800 | [diff] [blame] | 49 | import com.android.wallpaper.picker.CustomizationPickerActivity; |
George Lin | a2b70df | 2022-09-15 18:37:54 +0000 | [diff] [blame] | 50 | import com.android.wallpaper.picker.ImagePreviewFragment; |
| 51 | import com.android.wallpaper.picker.LivePreviewFragment; |
Santiago Etchebehere | 57778a2 | 2019-11-08 14:09:56 -0800 | [diff] [blame] | 52 | import com.android.wallpaper.picker.PreviewFragment; |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 53 | import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer; |
| 54 | |
| 55 | import java.util.Map; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 56 | |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 57 | import kotlinx.coroutines.Dispatchers; |
| 58 | |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 59 | /** |
| 60 | * A concrete, real implementation of the dependency provider. |
| 61 | */ |
| 62 | public class ThemePickerInjector extends WallpaperPicker2Injector |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 63 | implements CustomizationInjector { |
Chihhang Chuang | 8d14e8a | 2021-06-15 14:03:18 +0800 | [diff] [blame] | 64 | private CustomizationSections mCustomizationSections; |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 65 | private ThemesUserEventLogger mUserEventLogger; |
| 66 | private WallpaperPreferences mPrefs; |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 67 | private KeyguardQuickAffordancePickerInteractor mKeyguardQuickAffordancePickerInteractor; |
| 68 | private KeyguardQuickAffordancePickerViewModel.Factory |
| 69 | mKeyguardQuickAffordancePickerViewModelFactory; |
Alejandro Nijamkin | 8c86a4b | 2022-12-14 16:15:31 -0800 | [diff] [blame] | 70 | private KeyguardQuickAffordanceProviderClient mKeyguardQuickAffordanceProviderClient; |
Alejandro Nijamkin | 839e75c | 2022-12-02 15:50:52 -0800 | [diff] [blame] | 71 | private FragmentFactory mFragmentFactory; |
Alejandro Nijamkin | 9825cdb | 2022-12-15 16:42:42 -0800 | [diff] [blame] | 72 | private BaseFlags mFlags; |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 73 | private KeyguardQuickAffordanceSnapshotRestorer mKeyguardQuickAffordanceSnapshotRestorer; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 74 | |
| 75 | @Override |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 76 | public CustomizationSections getCustomizationSections(Activity activity) { |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 77 | if (mCustomizationSections == null) { |
Alejandro Nijamkin | 0eb2cc2 | 2022-12-19 10:55:57 -0800 | [diff] [blame] | 78 | mCustomizationSections = new DefaultCustomizationSections( |
| 79 | mKeyguardQuickAffordancePickerInteractor, |
| 80 | mKeyguardQuickAffordancePickerViewModelFactory); |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 81 | } |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 82 | return mCustomizationSections; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 85 | @Override |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 86 | public Intent getDeepLinkRedirectIntent(Context context, Uri uri) { |
| 87 | Intent intent = new Intent(); |
| 88 | intent.setClass(context, CustomizationPickerActivity.class); |
| 89 | intent.setData(uri); |
| 90 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 91 | return intent; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | @Override |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 95 | public String getDownloadableIntentAction() { |
| 96 | return null; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public Fragment getPreviewFragment( |
Clément Julliard | fe83976 | 2019-05-02 07:13:56 -0700 | [diff] [blame] | 101 | Context context, |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 102 | WallpaperInfo wallpaperInfo, |
| 103 | int mode, |
Ching-Sung Li | 3e5a805 | 2020-06-06 12:10:46 +0800 | [diff] [blame] | 104 | boolean viewAsHome, |
Ching-Sung Li | d833350 | 2021-11-11 22:31:30 +0800 | [diff] [blame] | 105 | boolean viewFullScreen, |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 106 | boolean testingModeEnabled) { |
George Lin | a2b70df | 2022-09-15 18:37:54 +0000 | [diff] [blame] | 107 | Bundle args = new Bundle(); |
| 108 | args.putParcelable(ARG_WALLPAPER, wallpaperInfo); |
| 109 | args.putInt(ARG_PREVIEW_MODE, mode); |
| 110 | args.putBoolean(ARG_VIEW_AS_HOME, viewAsHome); |
| 111 | args.putBoolean(ARG_FULL_SCREEN, viewFullScreen); |
| 112 | args.putBoolean(ARG_TESTING_MODE_ENABLED, testingModeEnabled); |
| 113 | PreviewFragment fragment = wallpaperInfo instanceof LiveWallpaperInfo |
| 114 | ? new LivePreviewFragment() : new ImagePreviewFragment(); |
| 115 | fragment.setArguments(args); |
| 116 | return fragment; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | @Override |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 120 | public synchronized ThemesUserEventLogger getUserEventLogger(Context context) { |
| 121 | if (mUserEventLogger == null) { |
| 122 | mUserEventLogger = new StatsLogUserEventLogger(context); |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 123 | } |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 124 | return mUserEventLogger; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | @Override |
George Lin | d99462a | 2022-09-20 17:42:21 +0000 | [diff] [blame] | 128 | public synchronized WallpaperPreferences getPreferences(Context context) { |
| 129 | if (mPrefs == null) { |
| 130 | mPrefs = new DefaultCustomizationPreferences(context.getApplicationContext()); |
| 131 | } |
| 132 | return mPrefs; |
| 133 | } |
| 134 | |
| 135 | // |
| 136 | // Functions from {@link CustomizationInjector} |
| 137 | // |
| 138 | @Override |
| 139 | public CustomizationPreferences getCustomizationPreferences(Context context) { |
| 140 | return (CustomizationPreferences) getPreferences(context); |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Santiago Etchebehere | 43b2518 | 2019-05-24 11:37:15 -0700 | [diff] [blame] | 143 | @Override |
| 144 | public ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, |
Santiago Etchebehere | 1754f33 | 2020-04-09 19:17:19 -0700 | [diff] [blame] | 145 | OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) { |
| 146 | return new ThemeManager(provider, activity, overlayManagerCompat, logger); |
Santiago Etchebehere | 43b2518 | 2019-05-24 11:37:15 -0700 | [diff] [blame] | 147 | } |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 148 | |
| 149 | @Override |
| 150 | public KeyguardQuickAffordancePickerInteractor getKeyguardQuickAffordancePickerInteractor( |
| 151 | Context context) { |
| 152 | if (mKeyguardQuickAffordancePickerInteractor == null) { |
| 153 | final KeyguardQuickAffordanceProviderClient client = |
Alejandro Nijamkin | 8c86a4b | 2022-12-14 16:15:31 -0800 | [diff] [blame] | 154 | getKeyguardQuickAffordancePickerProviderClient(context); |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 155 | mKeyguardQuickAffordancePickerInteractor = new KeyguardQuickAffordancePickerInteractor( |
| 156 | new KeyguardQuickAffordancePickerRepository(client, Dispatchers.getIO()), |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 157 | client, |
| 158 | () -> getKeyguardQuickAffordanceSnapshotRestorer(context)); |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 159 | } |
| 160 | return mKeyguardQuickAffordancePickerInteractor; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Returns a {@link KeyguardQuickAffordancePickerViewModel.Factory}. |
| 165 | */ |
| 166 | public KeyguardQuickAffordancePickerViewModel.Factory |
| 167 | getKeyguardQuickAffordancePickerViewModelFactory(Context context) { |
| 168 | if (mKeyguardQuickAffordancePickerViewModelFactory == null) { |
| 169 | mKeyguardQuickAffordancePickerViewModelFactory = |
| 170 | new KeyguardQuickAffordancePickerViewModel.Factory( |
| 171 | context, |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 172 | getKeyguardQuickAffordancePickerInteractor(context), |
| 173 | getUndoInteractor(context)); |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 174 | } |
| 175 | return mKeyguardQuickAffordancePickerViewModelFactory; |
| 176 | } |
Alejandro Nijamkin | 839e75c | 2022-12-02 15:50:52 -0800 | [diff] [blame] | 177 | |
| 178 | @Override |
| 179 | public FragmentFactory getFragmentFactory() { |
| 180 | if (mFragmentFactory == null) { |
| 181 | mFragmentFactory = new ThemePickerFragmentFactory(); |
| 182 | } |
| 183 | return mFragmentFactory; |
| 184 | } |
Alejandro Nijamkin | 8c86a4b | 2022-12-14 16:15:31 -0800 | [diff] [blame] | 185 | |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 186 | @Override |
| 187 | public BaseFlags getFlags() { |
| 188 | if (mFlags == null) { |
| 189 | mFlags = new BaseFlags() {}; |
| 190 | } |
| 191 | |
| 192 | return mFlags; |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public Map<Integer, SnapshotRestorer> getSnapshotRestorers(Context context) { |
| 197 | final Map<Integer, SnapshotRestorer> restorers = super.getSnapshotRestorers(context); |
| 198 | restorers.put( |
| 199 | KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER, |
| 200 | getKeyguardQuickAffordanceSnapshotRestorer(context)); |
| 201 | return restorers; |
| 202 | } |
| 203 | |
Alejandro Nijamkin | 8c86a4b | 2022-12-14 16:15:31 -0800 | [diff] [blame] | 204 | /** Returns the {@link KeyguardQuickAffordanceProviderClient}. */ |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 205 | protected KeyguardQuickAffordanceProviderClient getKeyguardQuickAffordancePickerProviderClient( |
Alejandro Nijamkin | 8c86a4b | 2022-12-14 16:15:31 -0800 | [diff] [blame] | 206 | Context context) { |
| 207 | if (mKeyguardQuickAffordanceProviderClient == null) { |
| 208 | mKeyguardQuickAffordanceProviderClient = |
| 209 | new KeyguardQuickAffordanceProviderClientImpl(context, Dispatchers.getIO()); |
| 210 | } |
| 211 | |
| 212 | return mKeyguardQuickAffordanceProviderClient; |
| 213 | } |
Alejandro Nijamkin | 9825cdb | 2022-12-15 16:42:42 -0800 | [diff] [blame] | 214 | |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 215 | protected KeyguardQuickAffordanceSnapshotRestorer getKeyguardQuickAffordanceSnapshotRestorer( |
| 216 | Context context) { |
| 217 | if (mKeyguardQuickAffordanceSnapshotRestorer == null) { |
| 218 | mKeyguardQuickAffordanceSnapshotRestorer = new KeyguardQuickAffordanceSnapshotRestorer( |
| 219 | getKeyguardQuickAffordancePickerInteractor(context), |
| 220 | getKeyguardQuickAffordancePickerProviderClient(context)); |
Alejandro Nijamkin | 9825cdb | 2022-12-15 16:42:42 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 223 | return mKeyguardQuickAffordanceSnapshotRestorer; |
Alejandro Nijamkin | 9825cdb | 2022-12-15 16:42:42 -0800 | [diff] [blame] | 224 | } |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame^] | 225 | |
| 226 | private static final int KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER = |
| 227 | WallpaperPicker2Injector.MIN_SNAPSHOT_RESTORER_KEY; |
| 228 | |
| 229 | /** |
| 230 | * When this injector is overridden, this is the minimal value that should be used by restorers |
| 231 | * returns in {@link #getSnapshotRestorers(Context)}. |
| 232 | */ |
| 233 | protected static final int MIN_SNAPSHOT_RESTORER_KEY = |
| 234 | KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER + 1; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 235 | } |