• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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 
18 package com.android.customization.picker.color.ui.binder
19 
20 import androidx.lifecycle.LifecycleOwner
21 import com.android.customization.picker.color.ui.view.ColorOptionIconView2
22 import com.android.customization.picker.color.ui.viewmodel.ColorOptionIconViewModel
23 import com.android.wallpaper.picker.customization.ui.binder.ColorUpdateBinder
24 import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewModel
25 
26 object ColorOptionIconBinder2 {
27 
28     interface Binding {
29         /** Destroys the color update binding, in spite of lifecycle state. */
30         fun destroy()
31     }
32 
33     fun bind(
34         view: ColorOptionIconView2,
35         viewModel: ColorOptionIconViewModel,
36         darkTheme: Boolean,
37         colorUpdateViewModel: ColorUpdateViewModel,
38         shouldAnimateColor: () -> Boolean,
39         lifecycleOwner: LifecycleOwner,
40     ): Binding {
41         val binding =
42             ColorUpdateBinder.bind(
43                 setColor = { color -> view.bindStrokeColor(color) },
44                 color = colorUpdateViewModel.colorPrimary,
45                 shouldAnimate = shouldAnimateColor,
46                 lifecycleOwner = lifecycleOwner,
47             )
48         if (darkTheme) {
49             view.bindColor(
50                 viewModel.darkThemeColor0,
51                 viewModel.darkThemeColor1,
52                 viewModel.darkThemeColor2,
53                 viewModel.darkThemeColor3,
54             )
55         } else {
56             view.bindColor(
57                 viewModel.lightThemeColor0,
58                 viewModel.lightThemeColor1,
59                 viewModel.lightThemeColor2,
60                 viewModel.lightThemeColor3,
61             )
62         }
63         return object : Binding {
64             override fun destroy() {
65                 binding.destroy()
66             }
67         }
68     }
69 }
70