1 /* 2 * 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.picker.category.ui.view.adapter 18 19 import android.view.LayoutInflater 20 import android.view.View 21 import android.view.ViewGroup 22 import androidx.recyclerview.widget.RecyclerView 23 import com.android.wallpaper.R 24 import com.android.wallpaper.picker.category.ui.view.viewholder.TileViewHolder 25 import com.android.wallpaper.picker.category.ui.viewmodel.TileViewModel 26 27 /** This binds individual wallpaper category tiles to [WallpaperTileView] */ 28 class CategoryAdapter(var items: List<TileViewModel>, val columns: Int, val windowWidth: Int) : 29 RecyclerView.Adapter<RecyclerView.ViewHolder>() { onCreateViewHoldernull30 override fun onCreateViewHolder(parent: ViewGroup, p1: Int): RecyclerView.ViewHolder { 31 return createIndividualHolder(parent) 32 } 33 getItemCountnull34 override fun getItemCount(): Int { 35 return items.size 36 } 37 onBindViewHoldernull38 override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, position: Int) { 39 val tile: TileViewModel = items[position] 40 (viewHolder as TileViewHolder?)?.bind( 41 tile, 42 viewHolder.itemView.context, 43 columns, 44 items.size, 45 windowWidth 46 ) 47 } 48 createIndividualHoldernull49 private fun createIndividualHolder(parent: ViewGroup): RecyclerView.ViewHolder { 50 val layoutInflater = LayoutInflater.from(parent.context) 51 val view: View = layoutInflater.inflate(R.layout.category_tile, parent, false) 52 53 return TileViewHolder(view) 54 } 55 } 56