-
- All Implemented Interfaces:
-
android.view.View.OnClickListener,android.view.View.OnLongClickListener,android.view.View.OnTouchListener,eu.davidea.flexibleadapter.helpers.ItemTouchHelperCallback.ViewHolderCallback
public abstract class FlexibleViewHolder extends ContentViewHolder implements View.OnClickListener, View.OnLongClickListener, View.OnTouchListener, ItemTouchHelperCallback.ViewHolderCallback
Helper Class that implements: - Single tap - Long tap - Touch for Drag and Swipe.
You must extend and implement this class for the own ViewHolder.
-
-
Constructor Summary
Constructors Constructor Description FlexibleViewHolder(View view, FlexibleAdapter adapter)Default constructor. FlexibleViewHolder(View view, FlexibleAdapter adapter, boolean stickyHeader)Constructor to configure the sticky behaviour of a view.
-
Method Summary
Modifier and Type Method Description voidonClick(View view)booleanonLongClick(View view)booleanonTouch(View view, MotionEvent event)Should be used only by the Handle View! voidsetFullSpan(boolean enabled)Support for StaggeredGridLayoutManager. voidtoggleActivation()Allows to change and see the activation status on the itemView and to perform animationon inner views. floatgetActivationElevation()Allows to set elevation while the view is activated. voidscrollAnimators(@NonNull() List<Animator> animators, int position, boolean isForward)This method is automatically called by FlexibleAdapter to animate the View while the useractively scrolls the list (forward or backward). voidonActionStateChanged(int position, int actionState)Here we handle the event of when the {@code ItemTouchHelper}first registers an itemas being moved or swiped.voidonItemReleased(int position)Here we handle the event of when the ItemTouchHelper has completed the move or swipe. final booleanisDraggable()final booleanisSwipeable()ViewgetFrontView()ViewgetRearLeftView()ViewgetRearRightView()-
Methods inherited from class eu.davidea.viewholders.ContentViewHolder
getContentView, getFlexibleAdapterPosition, setBackupPosition -
Methods inherited from class androidx.recyclerview.widget.RecyclerView.ViewHolder
getAbsoluteAdapterPosition, getAdapterPosition, getBindingAdapter, getBindingAdapterPosition, getItemId, getItemViewType, getLayoutPosition, getOldPosition, getPosition, isRecyclable, setIsRecyclable, toString -
Methods inherited from class android.view.View.OnClickListener
onClick -
Methods inherited from class android.view.View.OnLongClickListener
onLongClick, onLongClickUseDefaultHapticFeedback -
Methods inherited from class android.view.View.OnTouchListener
onTouch -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
FlexibleViewHolder
FlexibleViewHolder(View view, FlexibleAdapter adapter)
Default constructor.- Parameters:
view- The View being hosted in this ViewHolderadapter- Adapter instance of type FlexibleAdapter
-
FlexibleViewHolder
FlexibleViewHolder(View view, FlexibleAdapter adapter, boolean stickyHeader)
Constructor to configure the sticky behaviour of a view.- Parameters:
view- The View being hosted in this ViewHolderadapter- Adapter instance of type FlexibleAdapterstickyHeader- true if the View can be a Sticky Header, false otherwise
-
-
Method Detail
-
onLongClick
@CallSuper() boolean onLongClick(View view)
-
onTouch
boolean onTouch(View view, MotionEvent event)
Should be used only by the Handle View!
-
setFullSpan
void setFullSpan(boolean enabled)
Support for StaggeredGridLayoutManager.
- Parameters:
enabled- true to enable full span size, false to disable
-
toggleActivation
@CallSuper() void toggleActivation()
Allows to change and see the activation status on the itemView and to perform animationon inner views.
Important note! the selected background is visible if you added
Alternatively, to set a background at runtime, you can use the new{@code android:background="?attr/selectableItemBackground"}in the item layout ANDcustomized the file{@code style.xml}.{@code DrawableUtils}from UI extension.Note: This method must be called every time we want the activation state visibleon the itemView, for instance: after a Click (to add the item to the selection list) orafter a LongClick (to activate the ActionMode) or during dragging (to show that we enabledthe Drag).
If you follow the above instructions, it's not necessary to invalidate this view with{@code notifyItemChanged}: In this way{@code bindViewHolder}won't be called and innerviews can animate without interruptions, eventually you will see the animation runningon those inner views at the same time of selection activation.
-
getActivationElevation
float getActivationElevation()
Allows to set elevation while the view is activated.
Override to return desired value of elevation on this itemView.
Note: returned value must be in Pixel.
-
scrollAnimators
void scrollAnimators(@NonNull() List<Animator> animators, int position, boolean isForward)
This method is automatically called by FlexibleAdapter to animate the View while the useractively scrolls the list (forward or backward).
Implement your logic for different animators based on position, selection and/ordirection.
Use can take one of the predefined Animator from package UI class{@code AnimatorHelper}or create your own Animator(s), then add it to the list of animators.- Parameters:
animators- NonNull list of animators, which you should add new animatorsposition- can be used to differentiate the Animators based on positionsisForward- can be used to separate animation from top/bottom or from left/right scrolling
-
onActionStateChanged
@CallSuper() void onActionStateChanged(int position, int actionState)
Here we handle the event of when the
{@code ItemTouchHelper}first registers an itemas being moved or swiped.In this implementation, View activation is automatically handled if dragged: The Itemwill be added to the selection list if not selected yet and mode MULTI is activated.
- Parameters:
position- the position of the item touchedactionState- one of ACTION_STATE_SWIPE orACTION_STATE_DRAG.
-
onItemReleased
@CallSuper() void onItemReleased(int position)
Here we handle the event of when the ItemTouchHelper has completed the move or swipe.
In this implementation, View activation is automatically handled.
In case of Drag, the state will be cleared depends by current selection mode!- Parameters:
position- the position of the item released
-
isDraggable
final boolean isDraggable()
-
isSwipeable
final boolean isSwipeable()
-
getFrontView
View getFrontView()
-
getRearLeftView
View getRearLeftView()
-
getRearRightView
View getRearRightView()
-
-
-
-