1 /*
2  * Copyright (C) 2022 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.quickaffordance.ui.section
19 
20 import android.content.Context
21 import android.view.LayoutInflater
22 import androidx.lifecycle.LifecycleOwner
23 import com.android.customization.picker.quickaffordance.ui.binder.KeyguardQuickAffordanceSectionViewBinder
24 import com.android.customization.picker.quickaffordance.ui.fragment.KeyguardQuickAffordancePickerFragment
25 import com.android.customization.picker.quickaffordance.ui.view.KeyguardQuickAffordanceSectionView
26 import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel
27 import com.android.themepicker.R
28 import com.android.wallpaper.config.BaseFlags
29 import com.android.wallpaper.model.CustomizationSectionController
30 import com.android.wallpaper.model.CustomizationSectionController.CustomizationSectionNavigationController as NavigationController
31 
32 class KeyguardQuickAffordanceSectionController(
33     private val navigationController: NavigationController,
34     private val viewModel: KeyguardQuickAffordancePickerViewModel,
35     private val lifecycleOwner: LifecycleOwner,
36 ) : CustomizationSectionController<KeyguardQuickAffordanceSectionView> {
37 
isAvailablenull38     override fun isAvailable(context: Context): Boolean {
39         return BaseFlags.get().isKeyguardQuickAffordanceEnabled(context)
40     }
41 
createViewnull42     override fun createView(context: Context): KeyguardQuickAffordanceSectionView {
43         val view =
44             LayoutInflater.from(context)
45                 .inflate(
46                     R.layout.keyguard_quick_affordance_section_view,
47                     null,
48                 ) as KeyguardQuickAffordanceSectionView
49         KeyguardQuickAffordanceSectionViewBinder.bind(
50             view = view,
51             viewModel = viewModel,
52             lifecycleOwner = lifecycleOwner,
53         ) {
54             navigationController.navigateTo(KeyguardQuickAffordancePickerFragment.newInstance())
55         }
56         return view
57     }
58 }
59