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 fun shouldRetainInstanceWhenSwitchingTabs(): Boolean { 61 return false 62 } 63 64 /** Returns `true` if the customization section is available. */ isAvailablenull65 fun isAvailable(context: Context): Boolean 66 67 /** 68 * Returns a newly created [SectionView] for the section. 69 * 70 * @param context The [Context] to inflate view. 71 * @param params Parameters for the creation of the view. 72 */ 73 fun createView(context: Context, params: ViewCreationParams): T { 74 return createView(context) 75 } 76 77 /** 78 * Returns a newly created [SectionView] for the section. 79 * 80 * @param context the [Context] to inflate view 81 */ createViewnull82 fun createView(context: Context): T 83 84 /** Saves the view state for configuration changes. */ 85 fun onSaveInstanceState(savedInstanceState: Bundle) = Unit 86 87 /** Releases the controller. */ 88 fun release() = Unit 89 90 /** Gets called when the section gets transitioned out. */ 91 fun onTransitionOut() = Unit 92 } 93