1 /*
2  * Copyright 2018 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.car.media.browse;
18 
19 import androidx.annotation.LayoutRes;
20 
21 /**
22  * Possible view types that would be used by the {@link BrowseAdapter}.
23  */
24 public enum BrowseItemViewType {
25     /** A section header */
26     HEADER(com.android.car.media.R.layout.media_browse_header_item),
27     /** A grid item with a large image. */
28     GRID_ITEM(com.android.car.media.R.layout.media_browse_grid_item, 1),
29     /** A grid item a medium icon. */
30     ICON_GRID_ITEM(com.android.car.media.R.layout.media_browse_grid_icons_item, 1),
31     /** A list item with a medium image. */
32     LIST_ITEM(com.android.car.media.R.layout.media_browse_list_item),
33     /** A list item with a small icon. */
34     ICON_LIST_ITEM(com.android.car.media.R.layout.media_browse_list_icons_item),
35 
36     /** A spacer view that creates additional padding at the edges of the list, and for headers */
37     SPACER(com.android.car.media.R.layout.media_browse_spacer);
38 
39     @LayoutRes
40     private final int mLayoutId;
41     private final int mSpanSize;
42 
43     /**
44      * {@link BrowseItemViewType} that take the whole width of the {@link
45      * androidx.recyclerview.widget.RecyclerView}
46      */
BrowseItemViewType(@ayoutRes int layoutId)47     BrowseItemViewType(@LayoutRes int layoutId) {
48         mLayoutId = layoutId;
49         mSpanSize = -1;
50     }
51 
52     /**
53      * {@link BrowseItemViewType} that only takes the given number of columns.
54      */
BrowseItemViewType(@ayoutRes int layoutId, int spanSize)55     BrowseItemViewType(@LayoutRes int layoutId, int spanSize) {
56         mLayoutId = layoutId;
57         mSpanSize = spanSize;
58     }
59 
60     /**
61      * @param maxSpanSize maximum number of columns of the underlying grid
62      * @return number of columns this view wants to use.
63      */
getSpanSize(int maxSpanSize)64     public int getSpanSize(int maxSpanSize) {
65         return mSpanSize < 0 ? maxSpanSize : mSpanSize;
66     }
67 
68     /**
69      * Returns the layout that should be inflated to generate this view type.
70      */
71     @LayoutRes
getLayoutId()72     public int getLayoutId() {
73         return mLayoutId;
74     }
75 }
76