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.config.BaseFlags 26 import com.android.wallpaper.model.CustomizationSectionController 27 import com.android.wallpaper.picker.CategorySelectorFragment 28 import com.android.wallpaper.picker.category.ui.view.CategoriesFragment 29 import com.android.wallpaper.picker.customization.ui.binder.WallpaperQuickSwitchSectionBinder 30 import com.android.wallpaper.picker.customization.ui.viewmodel.WallpaperQuickSwitchViewModel 31 32 /** Controls a section that lets the user switch wallpapers quickly. */ 33 class WallpaperQuickSwitchSectionController( 34 private val viewModel: WallpaperQuickSwitchViewModel, 35 private val lifecycleOwner: LifecycleOwner, 36 private val navigator: CustomizationSectionController.CustomizationSectionNavigationController, 37 private val isThumbnailFadeAnimationEnabled: Boolean, 38 ) : CustomizationSectionController<WallpaperQuickSwitchView> { 39 isAvailablenull40 override fun isAvailable(context: Context): Boolean { 41 return true 42 } 43 44 @SuppressLint("InflateParams") // We don't care that the parent is null. createViewnull45 override fun createView(context: Context): WallpaperQuickSwitchView { 46 val view = 47 LayoutInflater.from(context) 48 .inflate( 49 R.layout.wallpaper_quick_switch_section, 50 /* parent= */ null, 51 ) as WallpaperQuickSwitchView 52 WallpaperQuickSwitchSectionBinder.bind( 53 view = view, 54 viewModel = viewModel, 55 lifecycleOwner = lifecycleOwner, 56 isThumbnailFadeAnimationEnabled = isThumbnailFadeAnimationEnabled, 57 onNavigateToFullWallpaperSelector = { 58 if (BaseFlags.get().isWallpaperCategoryRefactoringEnabled()) { 59 navigator.navigateTo(CategoriesFragment()) 60 } else { 61 navigator.navigateTo(CategorySelectorFragment()) 62 } 63 }, 64 ) 65 return view 66 } 67 } 68