|
16 | 16 |
|
17 | 17 | package com.ahamed.multiviewadapter; |
18 | 18 |
|
19 | | -import android.support.annotation.RestrictTo; |
20 | | -import android.support.v7.widget.RecyclerView.ViewHolder; |
21 | 19 | import android.view.View; |
22 | | -import com.ahamed.multiviewadapter.listener.ItemActionListener; |
23 | 20 |
|
24 | | -public class BaseViewHolder<M> extends ViewHolder |
25 | | - implements View.OnClickListener, View.OnLongClickListener { |
26 | | - |
27 | | - private M item; |
28 | | - private OnItemClickListener<M> itemClickListener; |
29 | | - private OnItemLongClickListener<M> itemLongClickListener; |
30 | | - private ItemActionListener actionListener; |
| 21 | +@Deprecated public class BaseViewHolder<M> extends ItemViewHolder<M> { |
31 | 22 |
|
32 | 23 | public BaseViewHolder(View itemView) { |
33 | 24 | super(itemView); |
34 | | - itemView.setOnClickListener(this); |
35 | | - itemView.setOnLongClickListener(this); |
36 | | - } |
37 | | - |
38 | | - @RestrictTo(RestrictTo.Scope.LIBRARY) @Override public final void onClick(View view) { |
39 | | - if (null == itemClickListener) return; |
40 | | - itemClickListener.onItemClick(view, getItem()); |
41 | | - } |
42 | | - |
43 | | - @RestrictTo(RestrictTo.Scope.LIBRARY) @Override public final boolean onLongClick(View view) { |
44 | | - return null != itemLongClickListener && itemLongClickListener.onItemLongClick(view, getItem()); |
45 | | - } |
46 | | - |
47 | | - final void setItemActionListener(ItemActionListener actionListener) { |
48 | | - this.actionListener = actionListener; |
49 | | - } |
50 | | - |
51 | | - final void setItem(M item) { |
52 | | - this.item = item; |
53 | | - } |
54 | | - |
55 | | - //////////////////////////////////////// |
56 | | - ///////// Public Methods /////////////// |
57 | | - //////////////////////////////////////// |
58 | | - |
59 | | - /** |
60 | | - * Returns the item object bounded by this {@link BaseViewHolder} |
61 | | - * |
62 | | - * @return item bounded by this {@link BaseViewHolder} |
63 | | - */ |
64 | | - public final M getItem() { |
65 | | - return item; |
66 | | - } |
67 | | - |
68 | | - /** |
69 | | - * Can be called by the child view holders to toggle the selection. |
70 | | - */ |
71 | | - protected final void toggleItemSelection() { |
72 | | - actionListener.onItemSelectionToggled(getAdapterPosition()); |
73 | | - } |
74 | | - |
75 | | - /** |
76 | | - * Can be called by the child view holders to toggle the {@link BaseViewHolder}'s expansion |
77 | | - * status. |
78 | | - */ |
79 | | - protected final void toggleItemExpansion() { |
80 | | - actionListener.onItemExpansionToggled(getAdapterPosition()); |
81 | | - } |
82 | | - |
83 | | - /** |
84 | | - * Can be called by the child view holders to toggle the {@link DataGroupManager}'s expansion |
85 | | - * status. |
86 | | - */ |
87 | | - protected final void toggleGroupExpansion() { |
88 | | - actionListener.onGroupExpansionToggled(getAdapterPosition()); |
89 | | - } |
90 | | - |
91 | | - /** |
92 | | - * Register a callback to be invoked when this {@link BaseViewHolder} is clicked. If this {@link |
93 | | - * BaseViewHolder} is not clickable, it becomes clickable. |
94 | | - * |
95 | | - * @param itemClickListener The callback that will run |
96 | | - */ |
97 | | - protected final void setItemClickListener(OnItemClickListener<M> itemClickListener) { |
98 | | - this.itemClickListener = itemClickListener; |
99 | | - } |
100 | | - |
101 | | - /** |
102 | | - * Register a callback to be invoked when this {@link BaseViewHolder} is clicked and held. If this |
103 | | - * {@link BaseViewHolder} is not long clickable, it becomes long clickable. |
104 | | - * |
105 | | - * @param itemLongClickListener The callback that will run |
106 | | - */ |
107 | | - protected final void setItemLongClickListener(OnItemLongClickListener<M> itemLongClickListener) { |
108 | | - this.itemLongClickListener = itemLongClickListener; |
109 | | - } |
110 | | - |
111 | | - /** |
112 | | - * @return boolean value indicating whether the viewholder is selected or not. |
113 | | - * @see BaseViewHolder#toggleItemSelection() |
114 | | - */ |
115 | | - public final boolean isItemSelected() { |
116 | | - return actionListener.isItemSelected(getAdapterPosition()); |
117 | | - } |
118 | | - |
119 | | - /** |
120 | | - * @return boolean value indicating whether the viewholder is expanded or not. |
121 | | - * @see BaseViewHolder#toggleItemExpansion() |
122 | | - */ |
123 | | - public final boolean isItemExpanded() { |
124 | | - return actionListener.isItemExpanded(getAdapterPosition()); |
125 | | - } |
126 | | - |
127 | | - /** |
128 | | - * @return boolean value indicating whether the adapter is in context mode or not. |
129 | | - * @see RecyclerAdapter#startActionMode() () |
130 | | - * @see RecyclerAdapter#stopActionMode() () |
131 | | - */ |
132 | | - public final boolean isInActionMode() { |
133 | | - return actionListener.isAdapterInActionMode(); |
134 | | - } |
135 | | - |
136 | | - /** |
137 | | - * Returns the swipe directions for the provided ViewHolder. |
138 | | - * Default implementation returns the swipe directions as 0. |
139 | | - * This method can be overridden by child classes to provide valid swipe direction flags. |
140 | | - * |
141 | | - * @return A binary OR of direction flags. |
142 | | - */ |
143 | | - public int getSwipeDirections() { |
144 | | - return 0; |
145 | | - } |
146 | | - |
147 | | - /** |
148 | | - * Returns the drag directions for the provided ViewHolder. Default implementation returns the |
149 | | - * drag directions as 0. |
150 | | - * This method can be overridden by child classes to provide valid drag direction flags. |
151 | | - * |
152 | | - * @return A binary OR of direction flags. |
153 | | - */ |
154 | | - public int getDragDirections() { |
155 | | - return 0; |
156 | | - } |
157 | | - |
158 | | - /** |
159 | | - * The method lets the user to start dragging the viewholder |
160 | | - */ |
161 | | - public final void startDrag() { |
162 | | - actionListener.onStartDrag(this); |
163 | | - } |
164 | | - |
165 | | - /** |
166 | | - * Interface definition for a callback to be invoked when a {@link BaseViewHolder} is clicked. |
167 | | - */ |
168 | | - public interface OnItemClickListener<M> { |
169 | | - /** |
170 | | - * Called when a {@link BaseViewHolder} has been clicked. |
171 | | - * |
172 | | - * @param view The view that was clicked. |
173 | | - * @param item Item that is bounded by the {@link BaseViewHolder} |
174 | | - */ |
175 | | - void onItemClick(View view, M item); |
176 | | - } |
177 | | - |
178 | | - /** |
179 | | - * Interface definition for a callback to be invoked when a {@link BaseViewHolder} has been |
180 | | - * clicked and held. |
181 | | - */ |
182 | | - public interface OnItemLongClickListener<M> { |
183 | | - /** |
184 | | - * Called when a {@link BaseViewHolder} has been clicked and held. |
185 | | - * |
186 | | - * @param view The view that was clicked and held. |
187 | | - * @param item Item that is bounded by the {@link BaseViewHolder} |
188 | | - * @return true if the callback consumed the long click, false otherwise. |
189 | | - */ |
190 | | - boolean onItemLongClick(View view, M item); |
191 | 25 | } |
192 | 26 | } |
0 commit comments