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.

Constructs an adapter with the given PresenterSelector.

Public methods

abstract @Nullable Object
get(int position)

Returns the item for the given position.

long
getId(int position)

Returns the id for the given position.

final @Nullable Presenter

Returns the Presenter for the given item from the adapter.

final @NonNull 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)

Notifies UI that some items has changed.

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

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

Added in 1.1.0
public static final int NO_ID = -1

Indicates that an id has not been set.

Public constructors

ObjectAdapter

Added in 1.1.0
public ObjectAdapter()

Constructs an adapter.

ObjectAdapter

Added in 1.1.0
public ObjectAdapter(@NonNull Presenter presenter)

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

ObjectAdapter

Added in 1.1.0
public ObjectAdapter(@NonNull PresenterSelector presenterSelector)

Constructs an adapter with the given PresenterSelector.

Public methods

get

Added in 1.1.0
public abstract @Nullable Object get(int position)

Returns the item for the given position.

getId

Added in 1.1.0
public long getId(int position)

Returns the id for the given position.

getPresenter

Added in 1.1.0
public final @Nullable Presenter getPresenter(@NonNull Object item)

Returns the Presenter for the given item from the adapter.

getPresenterSelector

Added in 1.1.0
public final @NonNull PresenterSelector getPresenterSelector()

Returns the presenter selector for this ObjectAdapter.

hasStableIds

Added in 1.1.0
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

Added in 1.1.0
public boolean isImmediateNotifySupported()

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

notifyItemRangeChanged

Added in 1.1.0
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.

notifyItemRangeChanged

Added in 1.1.0
public final void notifyItemRangeChanged(
    int positionStart,
    int itemCount,
    @Nullable 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.

@Nullable Object payload

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

registerObserver

Added in 1.1.0
public final void registerObserver(@NonNull ObjectAdapter.DataObserver observer)

Registers a DataObserver for data change notifications.

setHasStableIds

Added in 1.1.0
public final void setHasStableIds(boolean hasStableIds)

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

setPresenterSelector

Added in 1.1.0
public final void setPresenterSelector(@NonNull PresenterSelector presenterSelector)

Sets the presenter selector. May not be null.

size

Added in 1.1.0
public abstract int size()

Returns the number of items in the adapter.

unregisterAllObservers

Added in 1.1.0
public final void unregisterAllObservers()

Unregisters all DataObservers for this ObjectAdapter.

unregisterObserver

Added in 1.1.0
public final void unregisterObserver(@NonNull ObjectAdapter.DataObserver observer)

Unregisters a DataObserver for data change notifications.

Protected methods

notifyChanged

Added in 1.1.0
protected final void notifyChanged()

Notifies UI that the underlying data has changed.

notifyItemMoved

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
protected void onHasStableIdsChanged()

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

onPresenterSelectorChanged

Added in 1.1.0
protected void onPresenterSelectorChanged()

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