1 /*
<lambda>null2  * 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.testing
18 
19 import android.content.ComponentName
20 import android.content.pm.ActivityInfo
21 import android.content.pm.ResolveInfo
22 import com.android.wallpaper.picker.category.domain.interactor.ThirdPartyCategoryInteractor
23 import com.android.wallpaper.picker.data.category.CategoryModel
24 import com.android.wallpaper.picker.data.category.CommonCategoryData
25 import com.android.wallpaper.picker.data.category.ThirdPartyCategoryData
26 import javax.inject.Inject
27 import javax.inject.Singleton
28 import kotlinx.coroutines.flow.Flow
29 import kotlinx.coroutines.flow.flow
30 
31 @Singleton
32 class FakeThirdPartyCategoryInteractor @Inject constructor() : ThirdPartyCategoryInteractor {
33     override val categories: Flow<List<CategoryModel>> = flow {
34         // stubbing the list of single section categories
35         val categoryModels =
36             generateCategoryData().map { pair ->
37                 CategoryModel(
38                     /* commonCategoryData = */ pair.first,
39                     /* thirdPartyCategoryData = */ pair.second,
40                     /* imageCategoryData = */ null,
41                     /* collectionCategoryData = */ null,
42                 )
43             }
44 
45         // Emit the list of categories
46         emit(categoryModels)
47     }
48 
49     override fun refreshThirdPartyAppCategories() {
50         TODO("Not yet implemented")
51     }
52 
53     private fun generateCategoryData(): List<Pair<CommonCategoryData, ThirdPartyCategoryData>> {
54         val biktokResolveInfo = ResolveInfo()
55         val biktokComponentName =
56             ComponentName("com.zhiliaoapp.musically", "com.ss.android.ugc.aweme.main.MainActivity")
57 
58         biktokResolveInfo.activityInfo =
59             ActivityInfo().apply {
60                 packageName = biktokComponentName.packageName
61                 name = biktokComponentName.className
62             }
63 
64         val binstragramResolveInfo = ResolveInfo()
65         val binstagramComponentName =
66             ComponentName("com.instagram.android", "com.instagram.mainactivity.MainActivity")
67 
68         binstragramResolveInfo.activityInfo =
69             ActivityInfo().apply {
70                 packageName = binstagramComponentName.packageName
71                 name = binstagramComponentName.className
72             }
73 
74         val dataList =
75             listOf(
76                 Pair(
77                     CommonCategoryData("Biktok", "biktok", 1),
78                     ThirdPartyCategoryData(
79                         /* resolveInfo = */ biktokResolveInfo,
80                         /* defaultDrawable = */ null,
81                     ),
82                 ),
83                 Pair(
84                     CommonCategoryData("Binstagram", "binstagram", 2),
85                     ThirdPartyCategoryData(
86                         /* resolveInfo = */ binstragramResolveInfo,
87                         /* defaultDrawable = */ null,
88                     ),
89                 ),
90             )
91         return dataList
92     }
93 }
94