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.wallpaper.customization.ui.binder.ThemePickerCustomizationOptionsBinder
27 import com.android.wallpaper.module.DefaultPartnerProvider
28 import com.android.wallpaper.module.PartnerProvider
29 import com.android.wallpaper.module.WallpaperPreferences
30 import com.android.wallpaper.module.logging.UserEventLogger
31 import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder
32 import com.android.wallpaper.picker.preview.data.util.DefaultLiveWallpaperDownloader
33 import com.android.wallpaper.picker.preview.data.util.LiveWallpaperDownloader
34 import com.android.wallpaper.picker.preview.ui.util.DefaultImageEffectDialogUtil
35 import com.android.wallpaper.picker.preview.ui.util.ImageEffectDialogUtil
36 import com.android.wallpaper.util.converter.DefaultWallpaperModelFactory
37 import com.android.wallpaper.util.converter.WallpaperModelFactory
38 import dagger.Binds
39 import dagger.Module
40 import dagger.Provides
41 import dagger.hilt.InstallIn
42 import dagger.hilt.android.qualifiers.ApplicationContext
43 import dagger.hilt.components.SingletonComponent
44 import javax.inject.Singleton
45 
46 @Module
47 @InstallIn(SingletonComponent::class)
48 abstract class ThemePickerAppModule {
bindInjectornull49     @Binds @Singleton abstract fun bindInjector(impl: ThemePickerInjector): CustomizationInjector
50 
51     @Binds
52     @Singleton
53     abstract fun bindUserEventLogger(impl: ThemesUserEventLoggerImpl): UserEventLogger
54 
55     @Binds
56     @Singleton
57     abstract fun bindThemesUserEventLogger(impl: ThemesUserEventLoggerImpl): ThemesUserEventLogger
58 
59     @Binds
60     @Singleton
61     abstract fun bindWallpaperModelFactory(
62         impl: DefaultWallpaperModelFactory
63     ): WallpaperModelFactory
64 
65     @Binds
66     @Singleton
67     abstract fun bindLiveWallpaperDownloader(
68         impl: DefaultLiveWallpaperDownloader
69     ): LiveWallpaperDownloader
70 
71     @Binds
72     @Singleton
73     abstract fun bindPartnerProvider(impl: DefaultPartnerProvider): PartnerProvider
74 
75     @Binds
76     @Singleton
77     abstract fun bindEffectsWallpaperDialogUtil(
78         impl: DefaultImageEffectDialogUtil
79     ): ImageEffectDialogUtil
80 
81     @Binds
82     @Singleton
83     abstract fun bindCustomizationOptionsBinder(
84         impl: ThemePickerCustomizationOptionsBinder
85     ): CustomizationOptionsBinder
86 
87     companion object {
88         @Provides
89         @Singleton
90         fun provideWallpaperPreferences(
91             @ApplicationContext context: Context
92         ): WallpaperPreferences {
93             return DefaultCustomizationPreferences(context)
94         }
95 
96         @Provides
97         @Singleton
98         fun provideColorCustomizationManager(
99             @ApplicationContext context: Context
100         ): ColorCustomizationManager {
101             return ColorCustomizationManager.getInstance(context, OverlayManagerCompat(context))
102         }
103     }
104 }
105