• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.car.dialer.inject;
18 
19 import android.bluetooth.BluetoothAdapter;
20 import android.content.Context;
21 import android.content.SharedPreferences;
22 
23 import androidx.fragment.app.Fragment;
24 import androidx.preference.PreferenceManager;
25 
26 import com.android.car.dialer.ui.common.DialerBaseFragment;
27 import com.android.car.dialer.ui.common.OnItemClickedListener;
28 import com.android.car.dialer.ui.contact.ContactDetailsFragment;
29 import com.android.car.telephony.common.Contact;
30 
31 import javax.inject.Singleton;
32 
33 import dagger.Module;
34 import dagger.Provides;
35 import dagger.hilt.InstallIn;
36 import dagger.hilt.android.components.FragmentComponent;
37 import dagger.hilt.android.qualifiers.ApplicationContext;
38 import dagger.hilt.components.SingletonComponent;
39 
40 /** Dialer modules. */
41 public final class DialerModules {
42 
43     /** Application level module. */
44     @InstallIn(SingletonComponent.class)
45     @Module
46     public static final class AppModule {
47 
48         @Provides
provideBluetoothAdapter()49         static BluetoothAdapter provideBluetoothAdapter() {
50             return BluetoothAdapter.getDefaultAdapter();
51         }
52 
53         @Singleton
54         @Provides
provideSharedPreferences(@pplicationContext Context context)55         static SharedPreferences provideSharedPreferences(@ApplicationContext Context context) {
56             return PreferenceManager.getDefaultSharedPreferences(context);
57         }
58     }
59 
60     /** Module providing dependencies for fragments. */
61     @InstallIn(FragmentComponent.class)
62     @Module
63     public static final class FragmentModule {
64         @Provides
provideShowContactDetailListener(Fragment fragment)65         static OnItemClickedListener<Contact> provideShowContactDetailListener(Fragment fragment) {
66             return contact -> {
67                 Fragment contactDetailsFragment = ContactDetailsFragment.newInstance(contact);
68                 if (fragment instanceof DialerBaseFragment) {
69                     ((DialerBaseFragment) fragment).pushContentFragment(contactDetailsFragment,
70                             ContactDetailsFragment.FRAGMENT_TAG);
71                 }
72             };
73         }
74     }
75 
76     /** Do not initialize. */
DialerModules()77     private DialerModules() {
78     }
79 }
80