1 /* 2 * Copyright (C) 2022 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.intentresolver.grid; 18 19 import android.view.View; 20 21 import androidx.annotation.Nullable; 22 23 import com.android.intentresolver.ChooserListAdapter; 24 import com.android.intentresolver.ResolverListAdapter; 25 26 import java.util.function.Consumer; 27 28 /** 29 * Used to bind types of individual item including 30 * {@link ChooserGridAdapter#VIEW_TYPE_NORMAL}, 31 * {@link ChooserGridAdapter#VIEW_TYPE_CONTENT_PREVIEW}, 32 * {@link ChooserGridAdapter#VIEW_TYPE_PROFILE}, 33 * and {@link ChooserGridAdapter#VIEW_TYPE_AZ_LABEL}. 34 */ 35 public final class ItemViewHolder extends ViewHolderBase { 36 private final ResolverListAdapter.ViewHolder mWrappedViewHolder; 37 38 private int mListPosition = ChooserListAdapter.NO_POSITION; 39 ItemViewHolder( View itemView, int viewType, @Nullable Consumer<Integer> onClick, @Nullable Consumer<Integer> onLongClick)40 public ItemViewHolder( 41 View itemView, 42 int viewType, 43 @Nullable Consumer<Integer> onClick, 44 @Nullable Consumer<Integer> onLongClick) { 45 super(itemView, viewType); 46 mWrappedViewHolder = new ResolverListAdapter.ViewHolder(itemView); 47 48 if (onClick != null) { 49 itemView.setOnClickListener(v -> onClick.accept(mListPosition)); 50 } 51 52 if (onLongClick != null) { 53 itemView.setOnLongClickListener(v -> { 54 onLongClick.accept(mListPosition); 55 return true; 56 }); 57 } 58 } 59 setListPosition(int listPosition)60 public void setListPosition(int listPosition) { 61 mListPosition = listPosition; 62 } 63 } 64