blob: a33541c5bee55c8dd3e752d059291d8190afa128 [file] [log] [blame]
Santiago Etchebehereab639852019-02-26 10:42:44 -08001/*
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 */
16package com.android.customization.module;
17
George Lina2b70df2022-09-15 18:37:54 +000018import static com.android.wallpaper.picker.PreviewFragment.ARG_FULL_SCREEN;
19import static com.android.wallpaper.picker.PreviewFragment.ARG_PREVIEW_MODE;
20import static com.android.wallpaper.picker.PreviewFragment.ARG_TESTING_MODE_ENABLED;
21import static com.android.wallpaper.picker.PreviewFragment.ARG_VIEW_AS_HOME;
22import static com.android.wallpaper.picker.PreviewFragment.ARG_WALLPAPER;
23
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080024import android.app.Activity;
Santiago Etchebehereab639852019-02-26 10:42:44 -080025import android.content.Context;
Chuck Liao4a777fb2020-08-15 04:15:46 +080026import android.content.Intent;
27import android.net.Uri;
George Lina2b70df2022-09-15 18:37:54 +000028import android.os.Bundle;
Santiago Etchebehereab639852019-02-26 10:42:44 -080029
30import androidx.fragment.app.Fragment;
Santiago Etchebehere43b25182019-05-24 11:37:15 -070031import androidx.fragment.app.FragmentActivity;
Santiago Etchebehereab639852019-02-26 10:42:44 -080032
Santiago Etchebehere43b25182019-05-24 11:37:15 -070033import com.android.customization.model.theme.OverlayManagerCompat;
34import com.android.customization.model.theme.ThemeBundleProvider;
35import com.android.customization.model.theme.ThemeManager;
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080036import com.android.customization.picker.quickaffordance.data.repository.KeyguardQuickAffordancePickerRepository;
37import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor;
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -080038import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordanceSnapshotRestorer;
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080039import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel;
40import com.android.systemui.shared.quickaffordance.data.content.KeyguardQuickAffordanceProviderClient;
41import com.android.systemui.shared.quickaffordance.data.content.KeyguardQuickAffordanceProviderClientImpl;
Alejandro Nijamkin9825cdb2022-12-15 16:42:42 -080042import com.android.wallpaper.config.BaseFlags;
George Lina2b70df2022-09-15 18:37:54 +000043import com.android.wallpaper.model.LiveWallpaperInfo;
Santiago Etchebehereab639852019-02-26 10:42:44 -080044import com.android.wallpaper.model.WallpaperInfo;
Chihhang Chuang8d14e8a2021-06-15 14:03:18 +080045import com.android.wallpaper.module.CustomizationSections;
Alejandro Nijamkin839e75c2022-12-02 15:50:52 -080046import com.android.wallpaper.module.FragmentFactory;
George Lind99462a2022-09-20 17:42:21 +000047import com.android.wallpaper.module.WallpaperPicker2Injector;
Santiago Etchebehereab639852019-02-26 10:42:44 -080048import com.android.wallpaper.module.WallpaperPreferences;
Chihhang Chuangeecf85e2021-06-14 13:48:57 +080049import com.android.wallpaper.picker.CustomizationPickerActivity;
George Lina2b70df2022-09-15 18:37:54 +000050import com.android.wallpaper.picker.ImagePreviewFragment;
51import com.android.wallpaper.picker.LivePreviewFragment;
Santiago Etchebehere57778a22019-11-08 14:09:56 -080052import com.android.wallpaper.picker.PreviewFragment;
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -080053import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer;
54
55import java.util.Map;
Santiago Etchebehereab639852019-02-26 10:42:44 -080056
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080057import kotlinx.coroutines.Dispatchers;
58
George Lind99462a2022-09-20 17:42:21 +000059/**
60 * A concrete, real implementation of the dependency provider.
61 */
62public class ThemePickerInjector extends WallpaperPicker2Injector
Santiago Etchebehereab639852019-02-26 10:42:44 -080063 implements CustomizationInjector {
Chihhang Chuang8d14e8a2021-06-15 14:03:18 +080064 private CustomizationSections mCustomizationSections;
George Lind99462a2022-09-20 17:42:21 +000065 private ThemesUserEventLogger mUserEventLogger;
66 private WallpaperPreferences mPrefs;
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080067 private KeyguardQuickAffordancePickerInteractor mKeyguardQuickAffordancePickerInteractor;
68 private KeyguardQuickAffordancePickerViewModel.Factory
69 mKeyguardQuickAffordancePickerViewModelFactory;
Alejandro Nijamkin8c86a4b2022-12-14 16:15:31 -080070 private KeyguardQuickAffordanceProviderClient mKeyguardQuickAffordanceProviderClient;
Alejandro Nijamkin839e75c2022-12-02 15:50:52 -080071 private FragmentFactory mFragmentFactory;
Alejandro Nijamkin9825cdb2022-12-15 16:42:42 -080072 private BaseFlags mFlags;
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -080073 private KeyguardQuickAffordanceSnapshotRestorer mKeyguardQuickAffordanceSnapshotRestorer;
Santiago Etchebehereab639852019-02-26 10:42:44 -080074
75 @Override
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080076 public CustomizationSections getCustomizationSections(Activity activity) {
George Lind99462a2022-09-20 17:42:21 +000077 if (mCustomizationSections == null) {
Alejandro Nijamkin0eb2cc22022-12-19 10:55:57 -080078 mCustomizationSections = new DefaultCustomizationSections(
79 mKeyguardQuickAffordancePickerInteractor,
80 mKeyguardQuickAffordancePickerViewModelFactory);
Santiago Etchebehereab639852019-02-26 10:42:44 -080081 }
George Lind99462a2022-09-20 17:42:21 +000082 return mCustomizationSections;
Santiago Etchebehereab639852019-02-26 10:42:44 -080083 }
84
Santiago Etchebehereab639852019-02-26 10:42:44 -080085 @Override
George Lind99462a2022-09-20 17:42:21 +000086 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 Etchebehereab639852019-02-26 10:42:44 -080092 }
93
94 @Override
George Lind99462a2022-09-20 17:42:21 +000095 public String getDownloadableIntentAction() {
96 return null;
Santiago Etchebehereab639852019-02-26 10:42:44 -080097 }
98
99 @Override
100 public Fragment getPreviewFragment(
Clément Julliardfe839762019-05-02 07:13:56 -0700101 Context context,
Santiago Etchebehereab639852019-02-26 10:42:44 -0800102 WallpaperInfo wallpaperInfo,
103 int mode,
Ching-Sung Li3e5a8052020-06-06 12:10:46 +0800104 boolean viewAsHome,
Ching-Sung Lid8333502021-11-11 22:31:30 +0800105 boolean viewFullScreen,
Santiago Etchebehereab639852019-02-26 10:42:44 -0800106 boolean testingModeEnabled) {
George Lina2b70df2022-09-15 18:37:54 +0000107 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 Etchebehereab639852019-02-26 10:42:44 -0800117 }
118
119 @Override
George Lind99462a2022-09-20 17:42:21 +0000120 public synchronized ThemesUserEventLogger getUserEventLogger(Context context) {
121 if (mUserEventLogger == null) {
122 mUserEventLogger = new StatsLogUserEventLogger(context);
Santiago Etchebehereab639852019-02-26 10:42:44 -0800123 }
George Lind99462a2022-09-20 17:42:21 +0000124 return mUserEventLogger;
Santiago Etchebehereab639852019-02-26 10:42:44 -0800125 }
126
127 @Override
George Lind99462a2022-09-20 17:42:21 +0000128 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 Etchebehereab639852019-02-26 10:42:44 -0800141 }
142
Santiago Etchebehere43b25182019-05-24 11:37:15 -0700143 @Override
144 public ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity,
Santiago Etchebehere1754f332020-04-09 19:17:19 -0700145 OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) {
146 return new ThemeManager(provider, activity, overlayManagerCompat, logger);
Santiago Etchebehere43b25182019-05-24 11:37:15 -0700147 }
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -0800148
149 @Override
150 public KeyguardQuickAffordancePickerInteractor getKeyguardQuickAffordancePickerInteractor(
151 Context context) {
152 if (mKeyguardQuickAffordancePickerInteractor == null) {
153 final KeyguardQuickAffordanceProviderClient client =
Alejandro Nijamkin8c86a4b2022-12-14 16:15:31 -0800154 getKeyguardQuickAffordancePickerProviderClient(context);
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -0800155 mKeyguardQuickAffordancePickerInteractor = new KeyguardQuickAffordancePickerInteractor(
156 new KeyguardQuickAffordancePickerRepository(client, Dispatchers.getIO()),
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -0800157 client,
158 () -> getKeyguardQuickAffordanceSnapshotRestorer(context));
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -0800159 }
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 Nijamkinc27b1d32022-12-21 15:27:35 -0800172 getKeyguardQuickAffordancePickerInteractor(context),
Alejandro Nijamkin2fe5f2d2022-12-22 15:24:22 -0800173 getUndoInteractor(context),
174 getCurrentWallpaperInfoFactory(context));
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -0800175 }
176 return mKeyguardQuickAffordancePickerViewModelFactory;
177 }
Alejandro Nijamkin839e75c2022-12-02 15:50:52 -0800178
179 @Override
180 public FragmentFactory getFragmentFactory() {
181 if (mFragmentFactory == null) {
182 mFragmentFactory = new ThemePickerFragmentFactory();
183 }
184 return mFragmentFactory;
185 }
Alejandro Nijamkin8c86a4b2022-12-14 16:15:31 -0800186
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -0800187 @Override
188 public BaseFlags getFlags() {
189 if (mFlags == null) {
190 mFlags = new BaseFlags() {};
191 }
192
193 return mFlags;
194 }
195
196 @Override
197 public Map<Integer, SnapshotRestorer> getSnapshotRestorers(Context context) {
198 final Map<Integer, SnapshotRestorer> restorers = super.getSnapshotRestorers(context);
199 restorers.put(
200 KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER,
201 getKeyguardQuickAffordanceSnapshotRestorer(context));
202 return restorers;
203 }
204
Alejandro Nijamkin8c86a4b2022-12-14 16:15:31 -0800205 /** Returns the {@link KeyguardQuickAffordanceProviderClient}. */
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -0800206 protected KeyguardQuickAffordanceProviderClient getKeyguardQuickAffordancePickerProviderClient(
Alejandro Nijamkin8c86a4b2022-12-14 16:15:31 -0800207 Context context) {
208 if (mKeyguardQuickAffordanceProviderClient == null) {
209 mKeyguardQuickAffordanceProviderClient =
210 new KeyguardQuickAffordanceProviderClientImpl(context, Dispatchers.getIO());
211 }
212
213 return mKeyguardQuickAffordanceProviderClient;
214 }
Alejandro Nijamkin9825cdb2022-12-15 16:42:42 -0800215
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -0800216 protected KeyguardQuickAffordanceSnapshotRestorer getKeyguardQuickAffordanceSnapshotRestorer(
217 Context context) {
218 if (mKeyguardQuickAffordanceSnapshotRestorer == null) {
219 mKeyguardQuickAffordanceSnapshotRestorer = new KeyguardQuickAffordanceSnapshotRestorer(
220 getKeyguardQuickAffordancePickerInteractor(context),
221 getKeyguardQuickAffordancePickerProviderClient(context));
Alejandro Nijamkin9825cdb2022-12-15 16:42:42 -0800222 }
223
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -0800224 return mKeyguardQuickAffordanceSnapshotRestorer;
Alejandro Nijamkin9825cdb2022-12-15 16:42:42 -0800225 }
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -0800226
227 private static final int KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER =
228 WallpaperPicker2Injector.MIN_SNAPSHOT_RESTORER_KEY;
229
230 /**
231 * When this injector is overridden, this is the minimal value that should be used by restorers
232 * returns in {@link #getSnapshotRestorers(Context)}.
233 */
234 protected static final int MIN_SNAPSHOT_RESTORER_KEY =
235 KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER + 1;
Santiago Etchebehereab639852019-02-26 10:42:44 -0800236}