1 /*
2  * Copyright 2024 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 package com.android.photopicker.core.features
18 
19 import com.android.photopicker.core.configuration.PhotopickerConfiguration
20 
21 /**
22  * This registration interface represents the registration contract between [FeatureManager] and
23  * Individual feature implementors. It provides hooks for FeatureManager to check if a feature
24  * should be considered enabled for a given Configuration state, and provides a factory to build an
25  * instance of the feature. (Features should not try to instantiate themselves)
26  *
27  * For most features, implementing this as a Companion object (named Registration) on the Feature's
28  * base Class should be the best pattern to follow:
29  * ```
30  * class MyPhotopickerFeature : PhotopickerFeature {
31  *    companion object Registration { ... }
32  * }
33  * ```
34  */
35 interface FeatureRegistration {
36 
37     /** Enforces that all features define a logging tag. This does not need to be unique. */
38     val TAG: String
39 
40     /**
41      * Called everytime the [PhotopickerConfiguration] of the activity is changed. This will be
42      * called infrequently, (usually just once) as is used by the [FeatureManager] to determine if
43      * the base feature class should be instantiated in the current session, with the provided
44      * configuration.
45      *
46      * In the event of a configuration change, this will be called again with the new configuration,
47      * and will help determine if the feature should be kept in activity scope, or dereferenced.
48      *
49      * @return Whether the Feature that this FeatureRegistration represents should be enabled with
50      *   the given configuration.
51      */
isEnablednull52     fun isEnabled(config: PhotopickerConfiguration): Boolean = false
53 
54     /**
55      * An exposed factory method for instantiating the registered feature. This is eventually called
56      * by the [FeatureManager] during initialization, or possibly upon configuration change.
57      *
58      * @return an instance of the PhotopickerFeature
59      */
60     fun build(featureManager: FeatureManager): PhotopickerFeature
61 }
62