1 /* 2 * Copyright (C) 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.wallpaper.picker.category.wrapper 18 19 import com.android.wallpaper.model.Category 20 import com.android.wallpaper.picker.category.data.repository.WallpaperCategoryRepository 21 import javax.inject.Inject 22 import javax.inject.Singleton 23 24 @Singleton 25 class DefaultWallpaperCategoryWrapper 26 @Inject 27 constructor(private var defaultWallpaperCategoryRepository: WallpaperCategoryRepository) : 28 WallpaperCategoryWrapper { 29 30 private var categoryMap: Map<String, Category>? = null 31 getCategoriesnull32 override suspend fun getCategories( 33 forceRefreshLiveWallpaperCategories: Boolean 34 ): List<Category> { 35 val systemCategories = defaultWallpaperCategoryRepository.getSystemFetchedCategories() 36 val thirdPartyCategory = defaultWallpaperCategoryRepository.getThirdPartyFetchedCategories() 37 val myPhotosCategory = defaultWallpaperCategoryRepository.getMyPhotosFetchedCategory() 38 val onDeviceCategory = defaultWallpaperCategoryRepository.getOnDeviceFetchedCategories() 39 val thirdPartyLiveWallpaperFetchedCategory = 40 defaultWallpaperCategoryRepository.getThirdPartyLiveWallpaperFetchedCategories() 41 42 val onDeviceCategories = onDeviceCategory?.let { listOf(it) } ?: emptyList() 43 val myPhotosCategories = myPhotosCategory?.let { listOf(it) } ?: emptyList() 44 45 return myPhotosCategories + 46 onDeviceCategories + 47 thirdPartyCategory + 48 systemCategories + 49 thirdPartyLiveWallpaperFetchedCategory 50 } 51 getCategorynull52 override fun getCategory( 53 categories: List<Category>, 54 collectionId: String, 55 forceRefreshLiveWallpaperCategories: Boolean, 56 ): Category? { 57 if (categoryMap == null) { 58 categoryMap = categories.associateBy { it.collectionId } 59 } 60 return categoryMap?.get(collectionId) 61 } 62 refreshLiveWallpaperCategoriesnull63 override suspend fun refreshLiveWallpaperCategories() { 64 TODO("Not yet implemented") 65 } 66 } 67