1 /* <lambda>null2 * Copyright (C) 2025 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.domain.interactor.implementations 18 19 import com.android.wallpaper.picker.category.data.repository.WallpaperCategoryRepository 20 import com.android.wallpaper.picker.category.domain.interactor.OnDeviceWallpapersInteractor 21 import com.android.wallpaper.picker.data.WallpaperModel 22 import javax.inject.Inject 23 import javax.inject.Singleton 24 import kotlinx.coroutines.flow.Flow 25 import kotlinx.coroutines.flow.combine 26 import kotlinx.coroutines.flow.filter 27 import kotlinx.coroutines.flow.flatMapLatest 28 29 /** 30 * This class provides a [Flow] which emits on device wallpapers for WallpaperPicker2. This includes 31 * both on-device and system categories. 32 */ 33 @Singleton 34 class DefaultOnDeviceWallpapersInteractor 35 @Inject 36 constructor(private val defaultWallpaperCategoryRepository: WallpaperCategoryRepository) : 37 OnDeviceWallpapersInteractor { 38 39 override val defaultWallpapers: Flow<List<WallpaperModel>> = 40 defaultWallpaperCategoryRepository.isDefaultCategoriesFetched 41 .filter { it } 42 .flatMapLatest { 43 combine( 44 defaultWallpaperCategoryRepository.onDeviceCategory, 45 defaultWallpaperCategoryRepository.systemCategories, 46 ) { onDeviceCategory, systemCategories -> 47 val finalList = 48 onDeviceCategory?.let { systemCategories + it } ?: systemCategories 49 val cmf = 50 finalList.flatMap { categoryModel -> 51 categoryModel?.collectionCategoryData?.wallpaperModels ?: emptyList() 52 } 53 return@combine cmf 54 } 55 } 56 } 57