1 /*
2  * Copyright (C) 2024 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 
17 package com.android.wallpaper.picker.di.modules
18 
19 import android.content.Context
20 import com.android.wallpaper.R
21 import com.android.wallpaper.picker.preview.data.repository.ImageEffectsRepository
22 import com.android.wallpaper.picker.preview.data.repository.ImageEffectsRepositoryImpl
23 import com.android.wallpaper.util.PreviewUtils
24 import dagger.Binds
25 import dagger.Module
26 import dagger.Provides
27 import dagger.hilt.InstallIn
28 import dagger.hilt.android.components.ActivityRetainedComponent
29 import dagger.hilt.android.qualifiers.ApplicationContext
30 import dagger.hilt.android.scopes.ActivityRetainedScoped
31 import javax.inject.Qualifier
32 
33 @Qualifier @Retention(AnnotationRetention.BINARY) annotation class LockScreenPreviewUtils
34 
35 @Qualifier @Retention(AnnotationRetention.BINARY) annotation class HomeScreenPreviewUtils
36 
37 @Module
38 @InstallIn(ActivityRetainedComponent::class)
39 abstract class SharedActivityRetainedModule {
40 
41     @Binds
bindImageEffectsRepositorynull42     abstract fun bindImageEffectsRepository(
43         impl: ImageEffectsRepositoryImpl
44     ): ImageEffectsRepository
45 
46     companion object {
47 
48         @HomeScreenPreviewUtils
49         @ActivityRetainedScoped
50         @Provides
51         fun provideHomeScreenPreviewUtils(
52             @ApplicationContext appContext: Context,
53         ): PreviewUtils {
54             return PreviewUtils(
55                 context = appContext,
56                 authorityMetadataKey =
57                     appContext.getString(
58                         R.string.grid_control_metadata_name,
59                     ),
60             )
61         }
62 
63         @LockScreenPreviewUtils
64         @ActivityRetainedScoped
65         @Provides
66         fun provideLockScreenPreviewUtils(
67             @ApplicationContext appContext: Context,
68         ): PreviewUtils {
69             return PreviewUtils(
70                 context = appContext,
71                 authority =
72                     appContext.getString(
73                         R.string.lock_screen_preview_provider_authority,
74                     ),
75             )
76         }
77     }
78 }
79