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.snackbar 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.Event 23 import com.android.photopicker.core.events.RegisteredEventClass 24 import com.android.photopicker.core.features.FeatureManager 25 import com.android.photopicker.core.features.FeatureRegistration 26 import com.android.photopicker.core.features.FeatureToken 27 import com.android.photopicker.core.features.Location 28 import com.android.photopicker.core.features.LocationParams 29 import com.android.photopicker.core.features.PhotopickerUiFeature 30 import com.android.photopicker.core.features.Priority 31 import com.android.photopicker.core.navigation.Route 32 33 /** Feature class for the Photopicker's snackbar. */ 34 class SnackbarFeature : PhotopickerUiFeature { 35 36 companion object Registration : FeatureRegistration { 37 override val TAG: String = "PhotopickerSnackbarFeature" 38 isEnablednull39 override fun isEnabled(config: PhotopickerConfiguration) = true 40 41 override fun build(featureManager: FeatureManager) = SnackbarFeature() 42 } 43 44 override fun registerLocations(): List<Pair<Location, Int>> { 45 return listOf(Pair(Location.SNACK_BAR, Priority.HIGH.priority)) 46 } 47 registerNavigationRoutesnull48 override fun registerNavigationRoutes(): Set<Route> { 49 return emptySet() 50 } 51 52 override val token = FeatureToken.SNACK_BAR.token 53 54 /** Events consumed by the selection bar */ 55 override val eventsConsumed = setOf<RegisteredEventClass>(Event.ShowSnackbarMessage::class.java) 56 57 /** Events produced by the selection bar */ 58 override val eventsProduced = setOf<RegisteredEventClass>() 59 60 @Composable composenull61 override fun compose(location: Location, modifier: Modifier, params: LocationParams) { 62 when (location) { 63 Location.SNACK_BAR -> Snackbar(modifier) 64 else -> {} 65 } 66 } 67 } 68