public class TileAdapter extends RecyclerView.Adapter<TileAdapter.Holder> implements TileQueryHelper.TileStateListener
Modifier and Type | Class and Description |
---|---|
class |
TileAdapter.Holder |
Modifier and Type | Field and Description |
---|---|
static long |
MOVE_DURATION |
Constructor and Description |
---|
TileAdapter(Context context) |
Modifier and Type | Method and Description |
---|---|
int |
getItemCount()
Returns the total number of items in the data set held by the adapter.
|
RecyclerView.ItemDecoration |
getItemDecoration() |
ItemTouchHelper |
getItemTouchHelper() |
int |
getItemViewType(int position)
Return the view type of the item at
position for the purposes
of view recycling. |
GridLayoutManager.SpanSizeLookup |
getSizeLookup() |
void |
onBindViewHolder(TileAdapter.Holder holder,
int position)
Called by RecyclerView to display the data at the specified position.
|
TileAdapter.Holder |
onCreateViewHolder(ViewGroup parent,
int viewType)
Called when RecyclerView needs a new
RecyclerView.ViewHolder of the given type to represent
an item. |
boolean |
onFailedToRecycleView(TileAdapter.Holder holder)
Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled
due to its transient state.
|
void |
onTilesChanged(List<TileQueryHelper.TileInfo> tiles) |
void |
saveSpecs(QSTileHost host) |
void |
setHost(QSTileHost host) |
void |
setTileSpecs(List<String> currentSpecs) |
bindViewHolder, createViewHolder, getItemId, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onDetachedFromRecyclerView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserver
public static final long MOVE_DURATION
public TileAdapter(Context context)
public void setHost(QSTileHost host)
public ItemTouchHelper getItemTouchHelper()
public RecyclerView.ItemDecoration getItemDecoration()
public void saveSpecs(QSTileHost host)
public void onTilesChanged(List<TileQueryHelper.TileInfo> tiles)
onTilesChanged
in interface TileQueryHelper.TileStateListener
public int getItemViewType(int position)
RecyclerView.Adapter
position
for the purposes
of view recycling.
The default implementation of this method returns 0, making the assumption of a single view type for the adapter. Unlike ListView adapters, types need not be contiguous. Consider using id resources to uniquely identify item view types.
getItemViewType
in class RecyclerView.Adapter<TileAdapter.Holder>
position
- position to queryposition
. Type codes need not be contiguous.public TileAdapter.Holder onCreateViewHolder(ViewGroup parent, int viewType)
RecyclerView.Adapter
RecyclerView.ViewHolder
of the given type to represent
an item.
This new ViewHolder should be constructed with a new View that can represent the items of the given type. You can either create a new View manually or inflate it from an XML layout file.
The new ViewHolder will be used to display items of the adapter using
#onBindViewHolder(ViewHolder, int, List)
. Since it will be re-used to display
different items in the data set, it is a good idea to cache references to sub views of
the View to avoid unnecessary View.findViewById(int)
calls.
onCreateViewHolder
in class RecyclerView.Adapter<TileAdapter.Holder>
parent
- The ViewGroup into which the new View will be added after it is bound to
an adapter position.viewType
- The view type of the new View.RecyclerView.Adapter.getItemViewType(int)
,
#onBindViewHolder(ViewHolder, int)
public int getItemCount()
RecyclerView.Adapter
getItemCount
in class RecyclerView.Adapter<TileAdapter.Holder>
public boolean onFailedToRecycleView(TileAdapter.Holder holder)
RecyclerView.Adapter
true
so that
the View can be recycled. Keep in mind that the View in question is already removed from
the RecyclerView.
In some cases, it is acceptable to recycle a View although it has transient state. Most
of the time, this is a case where the transient state will be cleared in
#onBindViewHolder(ViewHolder, int)
call when View is rebound to a new position.
For this reason, RecyclerView leaves the decision to the Adapter and uses the return
value of this method to decide whether the View should be recycled or not.
Note that when all animations are created by RecyclerView.ItemAnimator
, you
should never receive this callback because RecyclerView keeps those Views as children
until their animations are complete. This callback is useful when children of the item
views create animations which may not be easy to implement using an RecyclerView.ItemAnimator
.
You should never fix this issue by calling
holder.itemView.setHasTransientState(false);
unless you've previously called
holder.itemView.setHasTransientState(true);
. Each
View.setHasTransientState(true)
call must be matched by a
View.setHasTransientState(false)
call, otherwise, the state of the View
may become inconsistent. You should always prefer to end or cancel animations that are
triggering the transient state instead of handling it manually.
onFailedToRecycleView
in class RecyclerView.Adapter<TileAdapter.Holder>
holder
- The ViewHolder containing the View that could not be recycled due to its
transient state.true
, RecyclerView will ignore the transient state of
the View and recycle it regardless. If this method returns false
,
RecyclerView will check the View's transient state again before giving a final decision.
Default implementation returns false.public void onBindViewHolder(TileAdapter.Holder holder, int position)
RecyclerView.Adapter
RecyclerView.ViewHolder.itemView
to reflect the item at the given
position.
Note that unlike ListView
, RecyclerView will not call this method
again if the position of the item changes in the data set unless the item itself is
invalidated or the new position cannot be determined. For this reason, you should only
use the position
parameter while acquiring the related data item inside
this method and should not keep a copy of it. If you need the position of an item later
on (e.g. in a click listener), use RecyclerView.ViewHolder.getAdapterPosition()
which will
have the updated adapter position.
Override #onBindViewHolder(ViewHolder, int, List)
instead if Adapter can
handle efficient partial bind.
onBindViewHolder
in class RecyclerView.Adapter<TileAdapter.Holder>
holder
- The ViewHolder which should be updated to represent the contents of the
item at the given position in the data set.position
- The position of the item within the adapter's data set.public GridLayoutManager.SpanSizeLookup getSizeLookup()