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.overflowmenu 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 kotlinx.coroutines.Deferred 34 35 /** Feature class for the Photopicker's overflow menu. */ 36 class OverflowMenuFeature : PhotopickerUiFeature { 37 38 companion object Registration : FeatureRegistration { 39 override val TAG: String = "PhotopickerOverflowMenuFeature" 40 isEnablednull41 override fun isEnabled( 42 config: PhotopickerConfiguration, 43 deferredPrefetchResultsMap: Map<PrefetchResultKey, Deferred<Any?>>, 44 ) = config.runtimeEnv != PhotopickerRuntimeEnv.EMBEDDED 45 46 override fun build(featureManager: FeatureManager) = OverflowMenuFeature() 47 } 48 49 override fun registerLocations(): List<Pair<Location, Int>> { 50 return listOf(Pair(Location.OVERFLOW_MENU, Priority.HIGH.priority)) 51 } 52 53 override val token = FeatureToken.OVERFLOW_MENU.token 54 55 /** Events consumed by the OverflowMenu */ 56 override val eventsConsumed = setOf<RegisteredEventClass>() 57 58 /** Events produced by the OverflowMenu */ 59 override val eventsProduced = 60 setOf<RegisteredEventClass>(Event.LogPhotopickerUIEvent::class.java) 61 62 @Composable composenull63 override fun compose(location: Location, modifier: Modifier, params: LocationParams) { 64 when (location) { 65 Location.OVERFLOW_MENU -> OverflowMenu(modifier) 66 else -> {} 67 } 68 } 69 } 70