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.wallpaper.picker.customization.ui.section
19 
20 import android.annotation.SuppressLint
21 import android.content.Context
22 import android.view.LayoutInflater
23 import androidx.lifecycle.LifecycleOwner
24 import com.android.wallpaper.R
25 import com.android.wallpaper.model.CustomizationSectionController
26 import com.android.wallpaper.picker.CategorySelectorFragment
27 import com.android.wallpaper.picker.customization.ui.binder.WallpaperQuickSwitchSectionBinder
28 import com.android.wallpaper.picker.customization.ui.viewmodel.WallpaperQuickSwitchViewModel
29 
30 /** Controls a section that lets the user switch wallpapers quickly. */
31 class WallpaperQuickSwitchSectionController(
32     private val viewModel: WallpaperQuickSwitchViewModel,
33     private val lifecycleOwner: LifecycleOwner,
34     private val navigator: CustomizationSectionController.CustomizationSectionNavigationController,
35     private val isThumbnailFadeAnimationEnabled: Boolean,
36 ) : CustomizationSectionController<WallpaperQuickSwitchView> {
37 
isAvailablenull38     override fun isAvailable(context: Context): Boolean {
39         return true
40     }
41 
42     @SuppressLint("InflateParams") // We don't care that the parent is null.
createViewnull43     override fun createView(context: Context): WallpaperQuickSwitchView {
44         val view =
45             LayoutInflater.from(context)
46                 .inflate(
47                     R.layout.wallpaper_quick_switch_section,
48                     /* parent= */ null,
49                 ) as WallpaperQuickSwitchView
50         WallpaperQuickSwitchSectionBinder.bind(
51             view = view,
52             viewModel = viewModel,
53             lifecycleOwner = lifecycleOwner,
54             isThumbnailFadeAnimationEnabled = isThumbnailFadeAnimationEnabled,
55             onNavigateToFullWallpaperSelector = {
56                 navigator.navigateTo(CategorySelectorFragment())
57             },
58         )
59         return view
60     }
61 }
62