• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (C) 2022 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.settingslib.spa.framework.common
18  
19  import android.util.Log
20  
21  private const val TAG = "SppRepository"
22  
23  class SettingsPageProviderRepository(
24      allPageProviders: List<SettingsPageProvider>,
25      private val rootPages: List<SettingsPage> = emptyList(),
26  ) {
27      // Map of page name to its provider.
28      private val pageProviderMap: Map<String, SettingsPageProvider>
29  
30      init {
<lambda>null31          pageProviderMap = allPageProviders.associateBy { it.name }
32          Log.d(TAG, "Initialize Completed: ${pageProviderMap.size} spp")
33      }
34  
getDefaultStartPagenull35      fun getDefaultStartPage(): String {
36          return if (rootPages.isEmpty()) "" else rootPages[0].buildRoute()
37      }
38  
getAllRootPagesnull39      fun getAllRootPages(): Collection<SettingsPage> {
40          return rootPages
41      }
42  
getAllProvidersnull43      fun getAllProviders(): Collection<SettingsPageProvider> {
44          return pageProviderMap.values
45      }
46  
getProviderOrNullnull47      fun getProviderOrNull(name: String): SettingsPageProvider? {
48          return pageProviderMap[name]
49      }
50  }
51