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  */
17 
18 package com.android.systemui.complication.dagger
19 
20 import android.view.LayoutInflater
21 import android.view.View
22 import android.widget.TextClock
23 import com.android.internal.util.Preconditions
24 import com.android.systemui.res.R
25 import com.android.systemui.complication.DreamClockTimeComplication
26 import com.android.systemui.complication.DreamClockTimeComplication.DreamClockTimeViewHolder
27 import dagger.Module
28 import dagger.Provides
29 import dagger.Subcomponent
30 import javax.inject.Named
31 import javax.inject.Scope
32 
33 /** Responsible for generating dependencies for the [DreamClockTimeComplication]. */
34 @Subcomponent(
35     modules = [DreamClockTimeComplicationComponent.DreamClockTimeComplicationModule::class]
36 )
37 @DreamClockTimeComplicationComponent.DreamClockTimeComplicationScope
38 interface DreamClockTimeComplicationComponent {
39     /** Scope of the clock complication. */
40     @MustBeDocumented
41     @Retention(AnnotationRetention.RUNTIME)
42     @Scope
43     annotation class DreamClockTimeComplicationScope
44 
45     /** Factory that generates a component for the clock complication. */
46     @Subcomponent.Factory
47     interface Factory {
createnull48         fun create(): DreamClockTimeComplicationComponent
49     }
50 
51     /** Creates a view holder for the clock complication. */
52     fun getViewHolder(): DreamClockTimeViewHolder
53 
54     /** Module for providing injected values within the clock complication scope. */
55     @Module
56     interface DreamClockTimeComplicationModule {
57         companion object {
58             const val DREAM_CLOCK_TIME_COMPLICATION_VIEW = "clock_time_complication_view"
59             private const val TAG_WEIGHT = "'wght' "
60             private const val WEIGHT = 400
61 
62             /** Provides the complication view. */
63             @Provides
64             @DreamClockTimeComplicationScope
65             @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW)
66             fun provideComplicationView(layoutInflater: LayoutInflater): View {
67                 val view =
68                     Preconditions.checkNotNull(
69                         layoutInflater.inflate(
70                             R.layout.dream_overlay_complication_clock_time,
71                             /* root = */ null,
72                             /* attachToRoot = */ false,
73                         ) as TextClock,
74                         "R.layout.dream_overlay_complication_clock_time did not properly inflate"
75                     )
76                 view.setFontVariationSettings(TAG_WEIGHT + WEIGHT)
77                 return view
78             }
79         }
80     }
81 }
82