1 /* 2 * Copyright (C) 2021 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 package com.android.wallpaper.model 17 18 import android.content.Context 19 import android.os.Bundle 20 import androidx.fragment.app.Fragment 21 import com.android.wallpaper.picker.SectionView 22 23 /** 24 * The interface for the behavior of section in the customization picker. 25 * 26 * @param <T> the [SectionView] to create for the section </T> 27 */ 28 interface CustomizationSectionController<T : SectionView> { 29 /** Interface for customization section navigation. */ 30 interface CustomizationSectionNavigationController { 31 /** Navigates to the given `fragment`. */ navigateTonull32 fun navigateTo(fragment: Fragment?) 33 34 /** Navigates to a `fragment` that maps to the given destination ID. */ 35 fun navigateTo(destinationId: String?) 36 37 /** Navigates like [navigateTo] but without adding picker to back stack. */ 38 fun standaloneNavigateTo(destinationId: String?) 39 } 40 41 data class ViewCreationParams( 42 /** Whether the view is being created in the context of the lock screen tab of the UI. */ 43 val isOnLockScreen: Boolean = false, 44 /** 45 * Whether the view is being created in the context of a bunch of "connected" sections that 46 * are laid out side-by-side in a horizontal layout. 47 */ 48 val isConnectedHorizontallyToOtherSections: Boolean = false, 49 /** 50 * Whether the Wallpaper's engine visibility is determined by which tab is currently 51 * selected 52 */ 53 val isWallpaperVisibilityControlledByTab: Boolean = false, 54 ) 55 56 /** 57 * It means that the creation of the controller can be expensive and we should avoid recreation 58 * in conditions like the user switching between the home and lock screen. 59 */ 60 @JvmDefault 61 fun shouldRetainInstanceWhenSwitchingTabs(): Boolean { 62 return false 63 } 64 65 /** Returns `true` if the customization section is available. */ isAvailablenull66 fun isAvailable(context: Context): Boolean 67 68 /** 69 * Returns a newly created [SectionView] for the section. 70 * 71 * @param context The [Context] to inflate view. 72 * @param params Parameters for the creation of the view. 73 */ 74 @JvmDefault 75 fun createView(context: Context, params: ViewCreationParams): T { 76 return createView(context) 77 } 78 79 /** 80 * Returns a newly created [SectionView] for the section. 81 * 82 * @param context the [Context] to inflate view 83 */ createViewnull84 fun createView(context: Context): T 85 86 /** Saves the view state for configuration changes. */ 87 @JvmDefault fun onSaveInstanceState(savedInstanceState: Bundle) = Unit 88 89 /** Releases the controller. */ 90 @JvmDefault fun release() = Unit 91 92 /** Gets called when the section gets transitioned out. */ 93 @JvmDefault fun onTransitionOut() = Unit 94 } 95