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 import android.app.Activity
18 import android.view.View
19 import androidx.recyclerview.widget.RecyclerView
20 import com.android.wallpaper.R
21 import com.android.wallpaper.model.WallpaperInfo
22 import com.android.wallpaper.picker.individual.CreativeCategoryAdapter
23 import com.android.wallpaper.picker.individual.MarginItemDecoration
24 
25 /**
26  * CreativeCategoryHolder subclass for a creative category wallpaper tile in the individual
27  * wallpaper picker grid. This helps us create a different view for the creative category tiles in
28  * the individual picker.
29  */
30 class CreativeCategoryHolder(private val mActivity: Activity, itemView: View) :
31     RecyclerView.ViewHolder(itemView) {
32     private var recyclerViewCreativeCategory: RecyclerView
33     private var adapter: CreativeCategoryAdapter? = null
34 
35     init {
36         recyclerViewCreativeCategory = itemView.requireViewById(R.id.recyclerview_container)
37         recyclerViewCreativeCategory.addItemDecoration(
38             MarginItemDecoration(
39                 mActivity.resources.getInteger(R.integer.creative_category_individual_item_padding)
40             )
41         )
42     }
43 
bindnull44     fun bind(items: List<WallpaperInfo>, height: Int) {
45         if (adapter == null) {
46             adapter = CreativeCategoryAdapter(items, mActivity, height)
47             recyclerViewCreativeCategory.adapter = adapter
48         } else {
49             adapter?.items = items
50             adapter?.notifyDataSetChanged()
51         }
52     }
53 }
54