ObjectAdapter


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

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

Constants

const 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 functions

abstract Any?
get(position: Int)

Returns the item for the given position.

Long
getId(position: Int)

Returns the id for the given position.

Presenter?

Returns the Presenter for the given item from the adapter.

PresenterSelector

Returns the presenter selector for this ObjectAdapter.

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.

Unit
notifyItemRangeChanged(positionStart: Int, itemCount: Int)

Notifies UI that some items has changed.

Unit
notifyItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?)

Notifies UI that some items has changed.

Unit

Registers a DataObserver for data change notifications.

Unit
setHasStableIds(hasStableIds: Boolean)

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

Unit

Sets the presenter selector.

abstract Int

Returns the number of items in the adapter.

Unit

Unregisters all DataObservers for this ObjectAdapter.

Unit

Unregisters a DataObserver for data change notifications.

Protected functions

Unit

Notifies UI that the underlying data has changed.

Unit
notifyItemMoved(fromPosition: Int, toPosition: Int)

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

Unit
notifyItemRangeInserted(positionStart: Int, itemCount: Int)

Notifies UI that new items has been inserted.

Unit
notifyItemRangeRemoved(positionStart: Int, itemCount: Int)

Notifies UI that some items that has been removed.

Unit

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

Unit

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

Constants

NO_ID

Added in 1.1.0
const val NO_ID = -1: Int

Indicates that an id has not been set.

Public constructors

ObjectAdapter

Added in 1.1.0
ObjectAdapter()

Constructs an adapter.

ObjectAdapter

Added in 1.1.0
ObjectAdapter(presenter: Presenter)

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

ObjectAdapter

Added in 1.1.0
ObjectAdapter(presenterSelector: PresenterSelector)

Constructs an adapter with the given PresenterSelector.

Public functions

get

Added in 1.1.0
abstract fun get(position: Int): Any?

Returns the item for the given position.

getId

Added in 1.1.0
fun getId(position: Int): Long

Returns the id for the given position.

getPresenter

Added in 1.1.0
fun getPresenter(item: Any): Presenter?

Returns the Presenter for the given item from the adapter.

getPresenterSelector

Added in 1.1.0
fun getPresenterSelector(): PresenterSelector

Returns the presenter selector for this ObjectAdapter.

hasStableIds

Added in 1.1.0
fun hasStableIds(): Boolean

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
fun isImmediateNotifySupported(): Boolean

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

notifyItemRangeChanged

Added in 1.1.0
fun notifyItemRangeChanged(positionStart: Int, itemCount: Int): Unit

Notifies UI that some items has changed.

Parameters
positionStart: Int

Starting position of the changed items.

itemCount: Int

Total number of items that changed.

notifyItemRangeChanged

Added in 1.1.0
fun notifyItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?): Unit

Notifies UI that some items has changed.

Parameters
positionStart: Int

Starting position of the changed items.

itemCount: Int

Total number of items that changed.

payload: Any?

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

registerObserver

Added in 1.1.0
fun registerObserver(observer: ObjectAdapter.DataObserver): Unit

Registers a DataObserver for data change notifications.

setHasStableIds

Added in 1.1.0
fun setHasStableIds(hasStableIds: Boolean): Unit

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

setPresenterSelector

Added in 1.1.0
fun setPresenterSelector(presenterSelector: PresenterSelector): Unit

Sets the presenter selector. May not be null.

size

Added in 1.1.0
abstract fun size(): Int

Returns the number of items in the adapter.

unregisterAllObservers

Added in 1.1.0
fun unregisterAllObservers(): Unit

Unregisters all DataObservers for this ObjectAdapter.

unregisterObserver

Added in 1.1.0
fun unregisterObserver(observer: ObjectAdapter.DataObserver): Unit

Unregisters a DataObserver for data change notifications.

Protected functions

notifyChanged

Added in 1.1.0
protected fun notifyChanged(): Unit

Notifies UI that the underlying data has changed.

notifyItemMoved

Added in 1.1.0
protected fun notifyItemMoved(fromPosition: Int, toPosition: Int): Unit

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

Parameters
fromPosition: Int

Previous position of the item.

toPosition: Int

New position of the item.

notifyItemRangeInserted

Added in 1.1.0
protected fun notifyItemRangeInserted(positionStart: Int, itemCount: Int): Unit

Notifies UI that new items has been inserted.

Parameters
positionStart: Int

Position where new items has been inserted.

itemCount: Int

Count of the new items has been inserted.

notifyItemRangeRemoved

Added in 1.1.0
protected fun notifyItemRangeRemoved(positionStart: Int, itemCount: Int): Unit

Notifies UI that some items that has been removed.

Parameters
positionStart: Int

Starting position of the removed items.

itemCount: Int

Total number of items that has been removed.

onHasStableIdsChanged

Added in 1.1.0
protected fun onHasStableIdsChanged(): Unit

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

onPresenterSelectorChanged

Added in 1.1.0
protected fun onPresenterSelectorChanged(): Unit

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