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 import android.view.ViewGroup;
21 
22 /** Holder for a group of items displayed in a single row of the {@link ChooserGridAdapter}. */
23 public final class SingleRowViewHolder extends ItemGroupViewHolder {
24     private final ViewGroup mRow;
25 
SingleRowViewHolder(ViewGroup row, int cellCount, int viewType)26     public SingleRowViewHolder(ViewGroup row, int cellCount, int viewType) {
27         super(cellCount, row, viewType);
28 
29         this.mRow = row;
30     }
31 
32     /** Get the group of all views in this holder. */
getViewGroup()33     public ViewGroup getViewGroup() {
34         return mRow;
35     }
36 
37     /**
38      * Get the group of views for the row containing the specified cell index.
39      * TODO: unclear if that's what this `index` meant. It doesn't matter for our "single row"
40      * holders, and it doesn't look like this is an override from some other interface; maybe we can
41      * just remove?
42      */
getRowByIndex(int index)43     public ViewGroup getRowByIndex(int index) {
44         return mRow;
45     }
46 
47     /** Get the group of views for the specified {@code rowNumber}, if any. */
getRow(int rowNumber)48     public ViewGroup getRow(int rowNumber) {
49         if (rowNumber == 0) {
50             return mRow;
51         }
52         return null;
53     }
54 
55     /**
56      * @param index the index of the cell to add the view into.
57      * @param v the view to add into the cell.
58      */
addView(int index, View v)59     public ViewGroup addView(int index, View v) {
60         mRow.addView(v);
61         mCells[index] = v;
62 
63         return mRow;
64     }
65 
66     /**
67      * @param i the index of the cell containing the view to modify.
68      * @param visibility the new visibility to set on the view with the specified index.
69      */
setViewVisibility(int i, int visibility)70     public void setViewVisibility(int i, int visibility) {
71         getView(i).setVisibility(visibility);
72     }
73 }
74