• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.support.annotation.NonNull;
20 import android.support.annotation.Nullable;
21 import android.view.View;
22 
23 import com.android.car.media.common.MediaItemMetadata;
24 
25 import java.util.Objects;
26 
27 /**
28  * Information necessary to update a {@link BrowseViewHolder}
29  */
30 class BrowseViewData {
31     /** {@link com.android.car.media.common.MediaItemMetadata} associated with this item */
32     public final MediaItemMetadata mMediaItem;
33     /** View type associated with this item */
34     @NonNull public final BrowseItemViewType mViewType;
35     /** Current state of this item */
36     public final BrowseAdapter.State mState;
37     /** Text associated with this item */
38     public final CharSequence mText;
39     /** Click listener to set for this item */
40     public final View.OnClickListener mOnClickListener;
41 
42     /**
43      * Creates a {@link BrowseViewData} for a particular {@link MediaItemMetadata}.
44      *
45      * @param mediaItem {@link MediaItemMetadata} metadata
46      * @param viewType view type to use to represent this item
47      * @param state current item state
48      * @param onClickListener optional {@link android.view.View.OnClickListener}
49      */
BrowseViewData(MediaItemMetadata mediaItem, @NonNull BrowseItemViewType viewType, @NonNull BrowseAdapter.State state, View.OnClickListener onClickListener)50     BrowseViewData(MediaItemMetadata mediaItem, @NonNull BrowseItemViewType viewType,
51             @NonNull BrowseAdapter.State state, View.OnClickListener onClickListener) {
52         mMediaItem = mediaItem;
53         mViewType = viewType;
54         mState = state;
55         mText = null;
56         mOnClickListener = onClickListener;
57     }
58 
59     /**
60      * Creates a {@link BrowseViewData} for a given text (normally used for headers or footers)
61      * @param text text to set
62      * @param viewType view type to use
63      * @param onClickListener optional {@link android.view.View.OnClickListener}
64      */
BrowseViewData(@onNull CharSequence text, @NonNull BrowseItemViewType viewType, View.OnClickListener onClickListener)65     BrowseViewData(@NonNull CharSequence text, @NonNull BrowseItemViewType viewType,
66             View.OnClickListener onClickListener) {
67         mText = text;
68         mViewType = viewType;
69         mMediaItem = null;
70         mState = null;
71         mOnClickListener = onClickListener;
72     }
73 
74     @Override
equals(Object o)75     public boolean equals(Object o) {
76         if (this == o) return true;
77         if (o == null || getClass() != o.getClass()) return false;
78         BrowseViewData item = (BrowseViewData) o;
79         return Objects.equals(mMediaItem, item.mMediaItem) &&
80                 mState == item.mState &&
81                 mViewType == item.mViewType;
82     }
83 
84     @Override
hashCode()85     public int hashCode() {
86         return Objects.hash(mMediaItem, mState, mViewType);
87     }
88 }
89