1 /* 2 * Copyright (C) 2023 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.wallpaper.modules 17 18 import android.content.Context 19 import com.android.customization.model.color.ColorCustomizationManager 20 import com.android.customization.model.theme.OverlayManagerCompat 21 import com.android.customization.module.CustomizationInjector 22 import com.android.customization.module.DefaultCustomizationPreferences 23 import com.android.customization.module.ThemePickerInjector 24 import com.android.customization.module.logging.ThemesUserEventLogger 25 import com.android.customization.module.logging.ThemesUserEventLoggerImpl 26 import com.android.customization.picker.clock.data.repository.ClockPickerRepository 27 import com.android.customization.picker.clock.data.repository.ClockPickerRepositoryImpl 28 import com.android.customization.picker.clock.data.repository.ClockRegistryProvider 29 import com.android.customization.picker.color.data.repository.ColorPickerRepository 30 import com.android.customization.picker.color.data.repository.ColorPickerRepositoryImpl 31 import com.android.systemui.shared.clocks.ClockRegistry 32 import com.android.systemui.shared.customization.data.content.CustomizationProviderClient 33 import com.android.systemui.shared.customization.data.content.CustomizationProviderClientImpl 34 import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository 35 import com.android.systemui.shared.settings.data.repository.SecureSettingsRepositoryImpl 36 import com.android.systemui.shared.settings.data.repository.SystemSettingsRepository 37 import com.android.systemui.shared.settings.data.repository.SystemSettingsRepositoryImpl 38 import com.android.wallpaper.customization.ui.binder.ThemePickerCustomizationOptionsBinder 39 import com.android.wallpaper.customization.ui.binder.ThemePickerToolbarBinder 40 import com.android.wallpaper.effects.DefaultEffectsController 41 import com.android.wallpaper.effects.EffectsController 42 import com.android.wallpaper.module.DefaultPartnerProvider 43 import com.android.wallpaper.module.PartnerProvider 44 import com.android.wallpaper.module.WallpaperPreferences 45 import com.android.wallpaper.module.logging.UserEventLogger 46 import com.android.wallpaper.picker.category.domain.interactor.CategoriesLoadingStatusInteractor 47 import com.android.wallpaper.picker.category.domain.interactor.CategoryInteractor 48 import com.android.wallpaper.picker.category.domain.interactor.CreativeCategoryInteractor 49 import com.android.wallpaper.picker.category.domain.interactor.ThirdPartyCategoryInteractor 50 import com.android.wallpaper.picker.category.domain.interactor.implementations.CategoryInteractorImpl 51 import com.android.wallpaper.picker.category.domain.interactor.implementations.CreativeCategoryInteractorImpl 52 import com.android.wallpaper.picker.category.domain.interactor.implementations.DefaultCategoriesLoadingStatusInteractor 53 import com.android.wallpaper.picker.category.domain.interactor.implementations.ThirdPartyCategoryInteractorImpl 54 import com.android.wallpaper.picker.category.ui.view.providers.IndividualPickerFactory 55 import com.android.wallpaper.picker.category.ui.view.providers.implementation.DefaultIndividualPickerFactory 56 import com.android.wallpaper.picker.category.wrapper.DefaultWallpaperCategoryWrapper 57 import com.android.wallpaper.picker.category.wrapper.WallpaperCategoryWrapper 58 import com.android.wallpaper.picker.common.preview.ui.binder.ThemePickerWorkspaceCallbackBinder 59 import com.android.wallpaper.picker.common.preview.ui.binder.WorkspaceCallbackBinder 60 import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder 61 import com.android.wallpaper.picker.customization.ui.binder.ToolbarBinder 62 import com.android.wallpaper.picker.di.modules.BackgroundDispatcher 63 import com.android.wallpaper.picker.di.modules.MainDispatcher 64 import com.android.wallpaper.picker.preview.ui.util.DefaultImageEffectDialogUtil 65 import com.android.wallpaper.picker.preview.ui.util.ImageEffectDialogUtil 66 import com.android.wallpaper.util.converter.DefaultWallpaperModelFactory 67 import com.android.wallpaper.util.converter.WallpaperModelFactory 68 import dagger.Binds 69 import dagger.Module 70 import dagger.Provides 71 import dagger.hilt.InstallIn 72 import dagger.hilt.android.qualifiers.ApplicationContext 73 import dagger.hilt.components.SingletonComponent 74 import javax.inject.Singleton 75 import kotlinx.coroutines.CoroutineDispatcher 76 import kotlinx.coroutines.CoroutineScope 77 78 @Module 79 @InstallIn(SingletonComponent::class) 80 abstract class ThemePickerAppModule { 81 82 @Binds 83 @Singleton bindClockPickerRepositorynull84 abstract fun bindClockPickerRepository(impl: ClockPickerRepositoryImpl): ClockPickerRepository 85 86 @Binds 87 @Singleton 88 abstract fun bindColorPickerRepository(impl: ColorPickerRepositoryImpl): ColorPickerRepository 89 90 @Binds 91 @Singleton 92 abstract fun bindCreativeCategoryInteractor( 93 impl: CreativeCategoryInteractorImpl 94 ): CreativeCategoryInteractor 95 96 @Binds 97 @Singleton 98 abstract fun bindWallpaperCategoryWrapper( 99 impl: DefaultWallpaperCategoryWrapper 100 ): WallpaperCategoryWrapper 101 102 @Binds 103 @Singleton 104 abstract fun bindCustomizationInjector(impl: ThemePickerInjector): CustomizationInjector 105 106 @Binds 107 @Singleton 108 abstract fun bindCustomizationOptionsBinder( 109 impl: ThemePickerCustomizationOptionsBinder 110 ): CustomizationOptionsBinder 111 112 @Binds 113 @Singleton 114 abstract fun bindEffectsController(impl: DefaultEffectsController): EffectsController 115 116 @Binds 117 @Singleton 118 abstract fun bindGoogleCategoryInteractor(impl: CategoryInteractorImpl): CategoryInteractor 119 120 @Binds 121 @Singleton 122 abstract fun bindImageEffectDialogUtil( 123 impl: DefaultImageEffectDialogUtil 124 ): ImageEffectDialogUtil 125 126 @Binds 127 @Singleton 128 abstract fun bindIndividualPickerFactoryFragment( 129 impl: DefaultIndividualPickerFactory 130 ): IndividualPickerFactory 131 132 @Binds 133 @Singleton 134 abstract fun bindLoadingStatusInteractor( 135 impl: DefaultCategoriesLoadingStatusInteractor 136 ): CategoriesLoadingStatusInteractor 137 138 @Binds 139 @Singleton 140 abstract fun bindPartnerProvider(impl: DefaultPartnerProvider): PartnerProvider 141 142 @Binds 143 @Singleton 144 abstract fun bindThemesUserEventLogger(impl: ThemesUserEventLoggerImpl): ThemesUserEventLogger 145 146 @Binds 147 @Singleton 148 abstract fun bindThirdPartyCategoryInteractor( 149 impl: ThirdPartyCategoryInteractorImpl 150 ): ThirdPartyCategoryInteractor 151 152 @Binds @Singleton abstract fun bindToolbarBinder(impl: ThemePickerToolbarBinder): ToolbarBinder 153 154 @Binds 155 @Singleton 156 abstract fun bindUserEventLogger(impl: ThemesUserEventLoggerImpl): UserEventLogger 157 158 @Binds 159 @Singleton 160 abstract fun bindWallpaperModelFactory( 161 impl: DefaultWallpaperModelFactory 162 ): WallpaperModelFactory 163 164 @Binds 165 @Singleton 166 abstract fun bindWallpaperPreferences( 167 impl: DefaultCustomizationPreferences 168 ): WallpaperPreferences 169 170 @Binds 171 @Singleton 172 abstract fun bindWorkspaceCallbackBinder( 173 impl: ThemePickerWorkspaceCallbackBinder 174 ): WorkspaceCallbackBinder 175 176 companion object { 177 178 @Provides 179 @Singleton 180 fun provideClockRegistry( 181 @ApplicationContext context: Context, 182 @MainDispatcher mainScope: CoroutineScope, 183 @MainDispatcher mainDispatcher: CoroutineDispatcher, 184 @BackgroundDispatcher bgDispatcher: CoroutineDispatcher, 185 ): ClockRegistry { 186 return ClockRegistryProvider( 187 context = context, 188 coroutineScope = mainScope, 189 mainDispatcher = mainDispatcher, 190 backgroundDispatcher = bgDispatcher, 191 ) 192 .get() 193 } 194 195 @Provides 196 @Singleton 197 fun provideColorCustomizationManager( 198 @ApplicationContext context: Context 199 ): ColorCustomizationManager { 200 return ColorCustomizationManager.getInstance(context, OverlayManagerCompat(context)) 201 } 202 203 @Provides 204 @Singleton 205 fun provideCustomizationProviderClient( 206 @ApplicationContext context: Context, 207 @BackgroundDispatcher bgDispatcher: CoroutineDispatcher, 208 ): CustomizationProviderClient { 209 return CustomizationProviderClientImpl(context, bgDispatcher) 210 } 211 212 @Provides 213 @Singleton 214 fun provideSecureSettingsRepository( 215 @ApplicationContext context: Context, 216 @BackgroundDispatcher bgDispatcher: CoroutineDispatcher, 217 ): SecureSettingsRepository { 218 return SecureSettingsRepositoryImpl(context.contentResolver, bgDispatcher) 219 } 220 221 @Provides 222 @Singleton 223 fun provideSystemSettingsRepository( 224 @ApplicationContext context: Context, 225 @BackgroundDispatcher bgDispatcher: CoroutineDispatcher, 226 ): SystemSettingsRepository { 227 return SystemSettingsRepositoryImpl(context.contentResolver, bgDispatcher) 228 } 229 } 230 } 231