Stay organized with collections Save and categorize content based on your preferences.

ObjectAdapter

public abstract class ObjectAdapter


Base class adapter to be used in leanback activities. Provides access to a data model and is decoupled from the presentation of the items via PresenterSelector.

Summary

Nested types

public abstract class ObjectAdapter.DataObserver

A DataObserver can be notified when an ObjectAdapter's underlying data changes.

Constants

static final int
NO_ID = -1

Indicates that an id has not been set.

Public constructors

Constructs an adapter.

Constructs an adapter that uses the given Presenter for all items.

ObjectAdapter(PresenterSelector presenterSelector)

Constructs an adapter with the given PresenterSelector.

Public methods

abstract Object
get(int position)

Returns the item for the given position.

long
getId(int position)

Returns the id for the given position.

final Presenter

Returns the Presenter for the given item from the adapter.

final PresenterSelector

Returns the presenter selector for this ObjectAdapter.

final boolean

Returns true if the item ids are stable across changes to the underlying data.

boolean

Returns true if the adapter pairs each underlying data change with a call to notify and false otherwise.

final void
notifyItemRangeChanged(int positionStart, int itemCount, Object payload)

Notifies UI that some items has changed.

final void
notifyItemRangeChanged(int positionStart, int itemCount)

Notifies UI that some items has changed.

final void

Registers a DataObserver for data change notifications.

final void
setHasStableIds(boolean hasStableIds)

Sets whether the item ids are stable across changes to the underlying data.

final void

Sets the presenter selector.

abstract int

Returns the number of items in the adapter.

final void

Unregisters all DataObservers for this ObjectAdapter.

final void

Unregisters a DataObserver for data change notifications.

Protected methods

final void

Notifies UI that the underlying data has changed.

final void
notifyItemMoved(int fromPosition, int toPosition)

Notifies UI that item at fromPosition has been moved to toPosition.

final void
notifyItemRangeInserted(int positionStart, int itemCount)

Notifies UI that new items has been inserted.

final void
notifyItemRangeRemoved(int positionStart, int itemCount)

Notifies UI that some items that has been removed.

void

Called when setHasStableIds is called and the status of stable ids has changed.

void

Called when setPresenterSelector is called and the PresenterSelector differs from the previous one.

Constants

NO_ID

public static final int NO_ID = -1

Indicates that an id has not been set.

Public constructors

ObjectAdapter

public ObjectAdapter()

Constructs an adapter.

ObjectAdapter

public ObjectAdapter(Presenter presenter)

Constructs an adapter that uses the given Presenter for all items.

ObjectAdapter

public ObjectAdapter(PresenterSelector presenterSelector)

Constructs an adapter with the given PresenterSelector.

Public methods

get

public abstract Object get(int position)

Returns the item for the given position.

getId

public long getId(int position)

Returns the id for the given position.

getPresenter

public final Presenter getPresenter(Object item)

Returns the Presenter for the given item from the adapter.

getPresenterSelector

public final PresenterSelector getPresenterSelector()

Returns the presenter selector for this ObjectAdapter.

hasStableIds

public final boolean hasStableIds()

Returns true if the item ids are stable across changes to the underlying data. When this is true, clients of the ObjectAdapter can use getId to correlate Objects across changes.

isImmediateNotifySupported

public boolean isImmediateNotifySupported()

Returns true if the adapter pairs each underlying data change with a call to notify and false otherwise.

notifyItemRangeChanged

public final void notifyItemRangeChanged(int positionStart, int itemCount, Object payload)

Notifies UI that some items has changed.

Parameters
int positionStart

Starting position of the changed items.

int itemCount

Total number of items that changed.

Object payload

Optional parameter, use null to identify a "full" update.

notifyItemRangeChanged

public final void notifyItemRangeChanged(int positionStart, int itemCount)

Notifies UI that some items has changed.

Parameters
int positionStart

Starting position of the changed items.

int itemCount

Total number of items that changed.

registerObserver

public final void registerObserver(ObjectAdapter.DataObserver observer)

Registers a DataObserver for data change notifications.

setHasStableIds

public final void setHasStableIds(boolean hasStableIds)

Sets whether the item ids are stable across changes to the underlying data.

setPresenterSelector

public final void setPresenterSelector(PresenterSelector presenterSelector)

Sets the presenter selector. May not be null.

size

public abstract int size()

Returns the number of items in the adapter.

unregisterAllObservers

public final void unregisterAllObservers()

Unregisters all DataObservers for this ObjectAdapter.

unregisterObserver

public final void unregisterObserver(ObjectAdapter.DataObserver observer)

Unregisters a DataObserver for data change notifications.

Protected methods

notifyChanged

protected final void notifyChanged()

Notifies UI that the underlying data has changed.

notifyItemMoved

protected final void notifyItemMoved(int fromPosition, int toPosition)

Notifies UI that item at fromPosition has been moved to toPosition.

Parameters
int fromPosition

Previous position of the item.

int toPosition

New position of the item.

notifyItemRangeInserted

protected final void notifyItemRangeInserted(int positionStart, int itemCount)

Notifies UI that new items has been inserted.

Parameters
int positionStart

Position where new items has been inserted.

int itemCount

Count of the new items has been inserted.

notifyItemRangeRemoved

protected final void notifyItemRangeRemoved(int positionStart, int itemCount)

Notifies UI that some items that has been removed.

Parameters
int positionStart

Starting position of the removed items.

int itemCount

Total number of items that has been removed.

onHasStableIdsChanged

protected void onHasStableIdsChanged()

Called when setHasStableIds is called and the status of stable ids has changed.

onPresenterSelectorChanged

protected void onPresenterSelectorChanged()

Called when setPresenterSelector is called and the PresenterSelector differs from the previous one.