1 /*
2  * Copyright (C) 2017 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.tv.menu;
18 
19 import android.support.annotation.NonNull;
20 import com.android.tv.R;
21 import com.android.tv.data.api.Channel;
22 
23 /** A class for the items in channels row. */
24 public class ChannelsRowItem {
25     /** The item ID for guide item */
26     public static final int GUIDE_ITEM_ID = -1;
27     /** The item ID for setup item */
28     public static final int SETUP_ITEM_ID = -2;
29     /** The item ID for DVR item */
30     public static final int DVR_ITEM_ID = -3;
31     /** The item ID for app link item */
32     public static final int APP_LINK_ITEM_ID = -4;
33     /** The item ID for channel up item */
34     public static final int UP_ID = -5;
35     /** The item ID for app link item */
36     public static final int DOWN_ID = -6;
37 
38     /** The item which represents the guide. */
39     public static final ChannelsRowItem GUIDE_ITEM =
40             new ChannelsRowItem(GUIDE_ITEM_ID, R.layout.menu_card_guide);
41     /** The item which represents the setup. */
42     public static final ChannelsRowItem SETUP_ITEM =
43             new ChannelsRowItem(SETUP_ITEM_ID, R.layout.menu_card_setup);
44     /** The item which represents the DVR. */
45     public static final ChannelsRowItem DVR_ITEM =
46             new ChannelsRowItem(DVR_ITEM_ID, R.layout.menu_card_dvr);
47     /** The item which represents the app link. */
48     public static final ChannelsRowItem APP_LINK_ITEM =
49             new ChannelsRowItem(APP_LINK_ITEM_ID, R.layout.menu_card_app_link);
50 
51     /** The item which represents the channel up. */
52     public static final ChannelsRowItem UP_ITEM = new ChannelsRowItem(UP_ID, R.layout.menu_card_up);
53     /** The item which represents the channel down. */
54     public static final ChannelsRowItem DOWN_ITEM =
55             new ChannelsRowItem(DOWN_ID, R.layout.menu_card_down);
56 
57     private final long mItemId;
58     @NonNull private Channel mChannel;
59     private final int mLayoutId;
60 
ChannelsRowItem(@onNull Channel channel, int layoutId)61     public ChannelsRowItem(@NonNull Channel channel, int layoutId) {
62         this(channel.getId(), layoutId);
63         mChannel = channel;
64     }
65 
ChannelsRowItem(long itemId, int layoutId)66     private ChannelsRowItem(long itemId, int layoutId) {
67         mItemId = itemId;
68         mLayoutId = layoutId;
69     }
70 
71     /** Returns the channel for this item. */
72     @NonNull
getChannel()73     public Channel getChannel() {
74         return mChannel;
75     }
76 
77     /** Sets the channel. */
setChannel(@onNull Channel channel)78     public void setChannel(@NonNull Channel channel) {
79         mChannel = channel;
80     }
81 
82     /** Returns the layout resource ID to represent this item. */
getLayoutId()83     public int getLayoutId() {
84         return mLayoutId;
85     }
86 
87     /** Returns the unique ID for this item. */
getItemId()88     public long getItemId() {
89         return mItemId;
90     }
91 
92     @Override
toString()93     public String toString() {
94         return "ChannelsRowItem{"
95                 + "itemId="
96                 + mItemId
97                 + ", layoutId="
98                 + mLayoutId
99                 + ", channel="
100                 + mChannel
101                 + "}";
102     }
103 }
104