1 /* 2 * Copyright 2023 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.util.converter 18 19 import android.content.Context 20 import com.android.wallpaper.model.CreativeWallpaperInfo 21 import com.android.wallpaper.model.LiveWallpaperInfo 22 import com.android.wallpaper.model.WallpaperInfo 23 import com.android.wallpaper.picker.data.StaticWallpaperData 24 import com.android.wallpaper.picker.data.WallpaperModel 25 import com.android.wallpaper.util.converter.WallpaperModelFactory.Companion.getCommonWallpaperData 26 import com.android.wallpaper.util.converter.WallpaperModelFactory.Companion.getCreativeWallpaperData 27 import com.android.wallpaper.util.converter.WallpaperModelFactory.Companion.getImageWallpaperData 28 import com.android.wallpaper.util.converter.WallpaperModelFactory.Companion.getLiveWallpaperData 29 import javax.inject.Inject 30 import javax.inject.Singleton 31 32 @Singleton 33 class DefaultWallpaperModelFactory @Inject constructor() : WallpaperModelFactory { 34 getWallpaperModelnull35 override fun getWallpaperModel(context: Context, wallpaperInfo: WallpaperInfo): WallpaperModel { 36 return if (wallpaperInfo is LiveWallpaperInfo) { 37 WallpaperModel.LiveWallpaperModel( 38 commonWallpaperData = wallpaperInfo.getCommonWallpaperData(context), 39 liveWallpaperData = wallpaperInfo.getLiveWallpaperData(context), 40 creativeWallpaperData = 41 (wallpaperInfo as? CreativeWallpaperInfo)?.getCreativeWallpaperData(), 42 internalLiveWallpaperData = null, 43 ) 44 } else { 45 WallpaperModel.StaticWallpaperModel( 46 commonWallpaperData = wallpaperInfo.getCommonWallpaperData(context), 47 staticWallpaperData = 48 StaticWallpaperData( 49 asset = wallpaperInfo.getAsset(context), 50 cropHints = wallpaperInfo.wallpaperCropHints, 51 ), 52 imageWallpaperData = wallpaperInfo.getImageWallpaperData(), 53 networkWallpaperData = null, 54 downloadableWallpaperData = null, 55 ) 56 } 57 } 58 } 59