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.picker.individual 18 19 import android.app.Activity 20 import android.view.LayoutInflater 21 import android.view.View 22 import android.view.ViewGroup 23 import androidx.recyclerview.widget.RecyclerView 24 import com.android.wallpaper.R 25 import com.android.wallpaper.model.LiveWallpaperInfo 26 import com.android.wallpaper.model.WallpaperInfo 27 28 /** 29 * CreativeCategoryAdapter subclass for a creative category wallpaper tile in the RecyclerView which 30 * internally creates the CreativeCategoryIndividualHolder instance for the tile . 31 */ 32 class CreativeCategoryAdapter( 33 var items: List<WallpaperInfo>, 34 private val activity: Activity, 35 private val tileSizePx: Int, 36 ) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { 37 onCreateViewHoldernull38 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 39 return createIndividualHolder(parent) 40 } 41 getItemCountnull42 override fun getItemCount(): Int { 43 return items.size 44 } 45 onBindViewHoldernull46 override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { 47 val wallpaperInfo = items[position] as LiveWallpaperInfo 48 wallpaperInfo.setVisibleTitle(true) 49 (holder as CreativeCategoryIndividualHolder?)?.bindWallpaper(wallpaperInfo) 50 } 51 createIndividualHoldernull52 private fun createIndividualHolder(parent: ViewGroup): RecyclerView.ViewHolder { 53 val layoutInflater = LayoutInflater.from(activity) 54 val view: View = layoutInflater.inflate(R.layout.labeled_grid_item_image, parent, false) 55 56 return CreativeCategoryIndividualHolder(activity, tileSizePx, view) 57 } 58 } 59