• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
38     data class ViewCreationParams(
39         /** Whether the view is being created in the context of the lock screen tab of the UI. */
40         val isOnLockScreen: Boolean = false,
41         /**
42          * Whether the view is being created in the context of a bunch of "connected" sections that
43          * are laid out side-by-side in a horizontal layout.
44          */
45         val isConnectedHorizontallyToOtherSections: Boolean = false,
46     )
47 
48     /**
49      * It means that the creation of the controller can be expensive and we should avoid recreation
50      * in conditions like the user switching between the home and lock screen.
51      */
52     @JvmDefault
53     fun shouldRetainInstanceWhenSwitchingTabs(): Boolean {
54         return false
55     }
56 
57     /** Returns `true` if the customization section is available. */
isAvailablenull58     fun isAvailable(context: Context): Boolean
59 
60     /**
61      * Returns a newly created [SectionView] for the section.
62      *
63      * @param context The [Context] to inflate view.
64      * @param params Parameters for the creation of the view.
65      */
66     @JvmDefault
67     fun createView(context: Context, params: ViewCreationParams): T {
68         return createView(context)
69     }
70 
71     /**
72      * Returns a newly created [SectionView] for the section.
73      *
74      * @param context the [Context] to inflate view
75      */
createViewnull76     fun createView(context: Context): T
77 
78     /** Saves the view state for configuration changes. */
79     @JvmDefault fun onSaveInstanceState(savedInstanceState: Bundle) = Unit
80 
81     /** Releases the controller. */
82     @JvmDefault fun release() = Unit
83 
84     /** Gets called when the section gets transitioned out. */
85     @JvmDefault fun onTransitionOut() = Unit
86 
87     /** Notifies when the screen was switched. */
88     @JvmDefault fun onScreenSwitched(isOnLockScreen: Boolean) = Unit
89 }
90