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.alwaysdisabledfeature 18 19 import androidx.compose.material3.Text 20 import androidx.compose.runtime.Composable 21 import androidx.compose.runtime.getValue 22 import androidx.compose.runtime.setValue 23 import androidx.compose.ui.Modifier 24 import com.android.photopicker.core.configuration.PhotopickerConfiguration 25 import com.android.photopicker.core.events.RegisteredEventClass 26 import com.android.photopicker.core.features.FeatureManager 27 import com.android.photopicker.core.features.FeatureRegistration 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 /** 36 * Test [PhotopickerUiFeature] that is always disabled, no matter what it tries, but always tries to 37 * render it's message to [Location.COMPOSE_TOP], to no avail. 38 */ 39 class AlwaysDisabledFeature : PhotopickerUiFeature { 40 41 companion object Registration : FeatureRegistration { 42 override val TAG: String = "AlwaysDisabledFeature" 43 isEnablednull44 override fun isEnabled( 45 config: PhotopickerConfiguration, 46 deferredPrefetchResultsMap: Map<PrefetchResultKey, Deferred<Any?>>, 47 ) = false 48 49 override fun build(featureManager: FeatureManager) = AlwaysDisabledFeature() 50 51 val UI_STRING = "Can anyone hear me? :(" 52 } 53 54 override val token = TAG 55 56 /** Events consumed by the Photo grid */ 57 override val eventsConsumed = emptySet<RegisteredEventClass>() 58 59 /** Events produced by the Photo grid */ 60 override val eventsProduced = emptySet<RegisteredEventClass>() 61 62 override fun registerLocations(): List<Pair<Location, Int>> { 63 return listOf(Pair(Location.COMPOSE_TOP, Priority.REGISTRATION_ORDER.priority)) 64 } 65 66 @Composable composenull67 override fun compose(location: Location, modifier: Modifier, params: LocationParams) { 68 when (location) { 69 Location.COMPOSE_TOP -> composeTop() 70 else -> {} 71 } 72 } 73 74 @Composable composeTopnull75 private fun composeTop() { 76 Text(UI_STRING) 77 } 78 } 79