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 package com.android.wallpaper.picker.preview.ui.view.adapters
17 
18 import android.view.LayoutInflater
19 import android.view.View
20 import android.view.ViewGroup
21 import androidx.recyclerview.widget.RecyclerView
22 import com.android.wallpaper.R
23 
24 /** This adapter provides preview views for the small preview fragment */
25 class SinglePreviewPagerAdapter(
26     private val onBindViewHolder: (ViewHolder, Int) -> Unit,
27 ) : RecyclerView.Adapter<SinglePreviewPagerAdapter.ViewHolder>() {
28 
onCreateViewHoldernull29     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
30         val view =
31             LayoutInflater.from(parent.context)
32                 .inflate(R.layout.small_preview_handheld_card_view, parent, false)
33 
34         view.setPadding(
35             0,
36             parent.resources.getDimension(R.dimen.small_preview_preview_top_padding).toInt(),
37             0,
38             parent.resources.getDimension(R.dimen.small_preview_preview_bottom_padding).toInt(),
39         )
40         return ViewHolder(view)
41     }
42 
onBindViewHoldernull43     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
44         onBindViewHolder.invoke(holder, position)
45     }
46 
getItemCountnull47     override fun getItemCount(): Int = PREVIEW_PAGER_ITEM_COUNT
48 
49     inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
50 
51     companion object {
52         const val PREVIEW_PAGER_ITEM_COUNT = 2
53     }
54 }
55