MediaContentViewModel

class MediaContentViewModel(    source: LiveData<List<IviMediaItem>>,     mediaService: MediaServiceApi,     @WorkerThread mediaItemMatcher: MediaItemMatcher,     onItemClickAction: ClickAction,     isLoading: LiveData<Boolean> = ImmutableLiveData(false),     layoutPolicy: LiveData<LayoutPolicy> = ImmutableLiveData(LinearLayoutPolicy()),     groupByHeaders: LiveData<Boolean> = ImmutableLiveData(true),     dispatcher: CoroutineDispatcher = Dispatchers.Default)

ViewModel for displaying media items. Provides a list of MediaGroupItem which is updated according to input LiveData parameters.

Parameters

source

A list of incoming IviMediaItem, which is transformed into items.

mediaService

A media service that is used to get MediaServiceState: information about the currently active item, source, and playback state.

mediaItemMatcher

Used to match an item to the currently active item. This is needed to determine the MediaEntryGroupItem.ItemState.

onItemClickAction

An action that should be called when clicking an item from items list.

isLoading

If true, an empty list if items is returned. This is used to reduce visual glitches during content loading.

layoutPolicy

Used to determine ListGroupItem.ItemType for items.

groupByHeaders

If true, the items would be grouped by ItemType.HEADER based on the IviMediaItem.groupTitleHint.

dispatcher

A dispatcher which is used during items mapping. Could be substituted for testing purposes.

Constructors

Link copied to clipboard
fun MediaContentViewModel(    source: LiveData<List<IviMediaItem>>,     mediaService: MediaServiceApi,     @WorkerThread mediaItemMatcher: MediaItemMatcher,     onItemClickAction: ClickAction,     isLoading: LiveData<Boolean> = ImmutableLiveData(false),     layoutPolicy: LiveData<LayoutPolicy> = ImmutableLiveData(LinearLayoutPolicy()),     groupByHeaders: LiveData<Boolean> = ImmutableLiveData(true),     dispatcher: CoroutineDispatcher = Dispatchers.Default)

Properties

Link copied to clipboard
val hasActiveItems: LiveData<Boolean>

Whether any of items is currently MediaEntryGroupItem.isActive.

Link copied to clipboard
val hasHeaders: LiveData<Boolean>

Whether any of items is currently of ItemType.HEADER type.

Link copied to clipboard
val hasItems: LiveData<Boolean>
Link copied to clipboard
val items: LiveData<List<MediaGroupItem>>

List of items to be displayed by MediaContentView.