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.customization.picker.color.ui.section
19 
20 import android.content.Context
21 import android.view.LayoutInflater
22 import androidx.lifecycle.LifecycleOwner
23 import com.android.customization.picker.color.ui.binder.ColorSectionViewBinder
24 import com.android.customization.picker.color.ui.fragment.ColorPickerFragment
25 import com.android.customization.picker.color.ui.view.ColorSectionView
26 import com.android.customization.picker.color.ui.viewmodel.ColorPickerViewModel
27 import com.android.themepicker.R
28 import com.android.wallpaper.model.CustomizationSectionController
29 import com.android.wallpaper.model.CustomizationSectionController.CustomizationSectionNavigationController as NavigationController
30 
31 class ColorSectionController(
32     private val navigationController: NavigationController,
33     private val viewModel: ColorPickerViewModel,
34     private val lifecycleOwner: LifecycleOwner
35 ) : CustomizationSectionController<ColorSectionView> {
36 
isAvailablenull37     override fun isAvailable(context: Context): Boolean {
38         return true
39     }
40 
createViewnull41     override fun createView(context: Context): ColorSectionView {
42         return createView(context, CustomizationSectionController.ViewCreationParams())
43     }
44 
createViewnull45     override fun createView(
46         context: Context,
47         params: CustomizationSectionController.ViewCreationParams
48     ): ColorSectionView {
49         @SuppressWarnings("It is fine to inflate with null parent for our need.")
50         val view =
51             LayoutInflater.from(context)
52                 .inflate(
53                     R.layout.color_section_view,
54                     null,
55                 ) as ColorSectionView
56         ColorSectionViewBinder.bind(
57             view = view,
58             viewModel = viewModel,
59             lifecycleOwner = lifecycleOwner,
60             navigationOnClick = {
61                 navigationController.navigateTo(ColorPickerFragment.newInstance())
62             },
63             isConnectedHorizontallyToOtherSections = params.isConnectedHorizontallyToOtherSections,
64         )
65         return view
66     }
67 }
68