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.CategorySectionViewHolder 25 import com.android.wallpaper.picker.category.ui.viewmodel.SectionViewModel 26 27 class CategorySectionsAdapter( 28 var items: List<SectionViewModel>, 29 val windowWidth: Int, 30 ) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { 31 onCreateViewHoldernull32 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 33 return createIndividualHolder(parent) 34 } 35 getItemCountnull36 override fun getItemCount(): Int { 37 return items.size 38 } 39 onBindViewHoldernull40 override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { 41 val section: SectionViewModel = items[position] 42 (holder as CategorySectionViewHolder?)?.bind(section) 43 } 44 createIndividualHoldernull45 private fun createIndividualHolder(parent: ViewGroup): RecyclerView.ViewHolder { 46 val layoutInflater = LayoutInflater.from(parent.context) 47 val view: View = layoutInflater.inflate(R.layout.category_section_view, parent, false) 48 49 return CategorySectionViewHolder(view, windowWidth) 50 } 51 } 52