• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.features.selectionbar
18 
19 import androidx.compose.runtime.Composable
20 import androidx.compose.ui.Modifier
21 import com.android.photopicker.core.configuration.PhotopickerConfiguration
22 import com.android.photopicker.core.configuration.PhotopickerRuntimeEnv
23 import com.android.photopicker.core.events.Event
24 import com.android.photopicker.core.events.RegisteredEventClass
25 import com.android.photopicker.core.features.FeatureManager
26 import com.android.photopicker.core.features.FeatureRegistration
27 import com.android.photopicker.core.features.FeatureToken
28 import com.android.photopicker.core.features.Location
29 import com.android.photopicker.core.features.LocationParams
30 import com.android.photopicker.core.features.PhotopickerUiFeature
31 import com.android.photopicker.core.features.PrefetchResultKey
32 import com.android.photopicker.core.features.Priority
33 import com.android.photopicker.core.navigation.Route
34 import kotlinx.coroutines.Deferred
35 
36 /** Feature class for the Photopicker's selection bar. */
37 class SelectionBarFeature : PhotopickerUiFeature {
38 
39     companion object Registration : FeatureRegistration {
40         override val TAG: String = "PhotopickerSelectionBarFeature"
41 
42         // The selection bar is only shown when in multi-select mode. For single select,
43         // the activity ends as soon as the first Media is selected, so this feature is
44         // disabled to prevent it's animation for playing when the selection changes.
isEnablednull45         override fun isEnabled(
46             config: PhotopickerConfiguration,
47             deferredPrefetchResultsMap: Map<PrefetchResultKey, Deferred<Any?>>,
48         ): Boolean {
49             if (config.runtimeEnv == PhotopickerRuntimeEnv.ACTIVITY) {
50                 return config.selectionLimit > 1
51             }
52             // This is static enablement of feature. It will be hidden in collapsed
53             // mode for embedded at runtime.
54             return config.runtimeEnv == PhotopickerRuntimeEnv.EMBEDDED
55         }
56 
buildnull57         override fun build(featureManager: FeatureManager) = SelectionBarFeature()
58     }
59 
60     override fun registerLocations(): List<Pair<Location, Int>> {
61         return listOf(Pair(Location.SELECTION_BAR, Priority.HIGH.priority))
62     }
63 
registerNavigationRoutesnull64     override fun registerNavigationRoutes(): Set<Route> {
65         return emptySet()
66     }
67 
68     override val token = FeatureToken.SELECTION_BAR.token
69 
70     /** Events consumed by the selection bar */
71     override val eventsConsumed = setOf<RegisteredEventClass>()
72 
73     /** Events produced by the selection bar */
74     override val eventsProduced =
75         setOf<RegisteredEventClass>(Event.LogPhotopickerUIEvent::class.java)
76 
77     @Composable
composenull78     override fun compose(location: Location, modifier: Modifier, params: LocationParams) {
79         when (location) {
80             Location.SELECTION_BAR -> SelectionBar(modifier, params)
81             else -> {}
82         }
83     }
84 }
85