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.events.RegisteredEventClass 23 import com.android.photopicker.core.features.FeatureManager 24 import com.android.photopicker.core.features.FeatureRegistration 25 import com.android.photopicker.core.features.FeatureToken 26 import com.android.photopicker.core.features.Location 27 import com.android.photopicker.core.features.LocationParams 28 import com.android.photopicker.core.features.PhotopickerUiFeature 29 import com.android.photopicker.core.features.Priority 30 import com.android.photopicker.core.navigation.Route 31 32 /** Feature class for the Photopicker's selection bar. */ 33 class SelectionBarFeature : PhotopickerUiFeature { 34 35 companion object Registration : FeatureRegistration { 36 override val TAG: String = "PhotopickerSelectionBarFeature" 37 38 // The selection bar is only shown when in multi-select mode. For single select, 39 // the activity ends as soon as the first Media is selected, so this feature is 40 // disabled to prevent it's animation for playing when the selection changes. isEnablednull41 override fun isEnabled(config: PhotopickerConfiguration) = config.selectionLimit > 1 42 43 override fun build(featureManager: FeatureManager) = SelectionBarFeature() 44 } 45 46 override fun registerLocations(): List<Pair<Location, Int>> { 47 return listOf(Pair(Location.SELECTION_BAR, Priority.HIGH.priority)) 48 } 49 registerNavigationRoutesnull50 override fun registerNavigationRoutes(): Set<Route> { 51 return emptySet() 52 } 53 54 override val token = FeatureToken.SELECTION_BAR.token 55 56 /** Events consumed by the selection bar */ 57 override val eventsConsumed = setOf<RegisteredEventClass>() 58 59 /** Events produced by the selection bar */ 60 override val eventsProduced = setOf<RegisteredEventClass>() 61 62 @Composable composenull63 override fun compose(location: Location, modifier: Modifier, params: LocationParams) { 64 when (location) { 65 Location.SELECTION_BAR -> SelectionBar(modifier, params) 66 else -> {} 67 } 68 } 69 } 70