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