• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.search.model
18 
19 /** Holds search state info for all user profiles on the device. */
20 data class GlobalSearchStateInfo(
21     // Map of all available profiles to the provider authorities that have search feature
22     // enabled. If no providers have search enabled, tha value in map should be an empty string.
23     // If the information is unknown for a given profile, the value in map should be null.
24     val providersWithSearchEnabled: Map<Int, List<String>?>,
25     val currentUserId: Int,
26 ) {
27     val state: GlobalSearchState =
28         when {
29             // Check if search is enabled in current profile
30             providersWithSearchEnabled[currentUserId]?.isNotEmpty() ?: false ->
31                 GlobalSearchState.ENABLED
32 
33             // Check if search is enabled in any other profile
34             providersWithSearchEnabled.values.any { providers ->
35                 providers?.isNotEmpty() ?: false
36             } -> GlobalSearchState.ENABLED_IN_OTHER_PROFILES_ONLY
37 
38             // Check if there is missing information
39             providersWithSearchEnabled.values.any { providers -> providers == null } ->
40                 GlobalSearchState.UNKNOWN
41 
42             // If we have all information and search is not enabled in any profile,
43             // search is disabled.
44             else -> GlobalSearchState.DISABLED
45         }
46 }
47