Feed

data class Feed<T : Any>(val tabs: List<Tab>, val getPagedData: suspend (Tab?) -> Feed.Data<T>)

Represents a feed of multiple T items, Used in various contexts like home, library, etc.

Feeds without Tabs

  • The simplest way to create a feed is to show a list of T items, you can just do the following to convert a list of T items to a Feed:

val feed = listOf<T>().toFeed()
  • If you want to show a feed that loads more stuff when scrolled to end, you need to use the PagedData class. This class allows you to load more items as the user scrolls. And You can use the following to convert a PagedData to a feed:

val feed = pagedData.toFeed()

Feeds with Tabs

Feeds can have multiple Tab items, each representing a different category. When a tab is selected, the getPagedData is called with the selected tab to retrieve a pair of PagedData and Buttons. If the tabs list is empty, the getPagedData will be called with null. An example of a feed with tabs:

val feed = Feed(
listOf("Tab1", "Tab2").map { Tab(it, it) }
) { tab ->
val pagedData = when (tab?.id) {
"Tab1" -> loadPagedDataForTab1()
"Tab2" -> loadPagedDataForTab2()
else -> throw IllegalArgumentException("Unknown tab")
}
pagedData.toFeedData()
}

Buttons And Background

Feeds can also have Buttons shown below the tabs. Echo automatically handles searching and filtering depending on the data provided in the items. You can provide a custom track list to be used when play/shuffle button is clicked. You can send the buttons as null, if you want echo to use the default buttons for the feed. Use the Buttons.EMPTY to force a feed to have no buttons.

An example of converting PagedData to Feed.Data with Buttons:

val feedData = pagedData.toFeedData(
buttons = Feed.Buttons(showPlayAndShuffle = true),
background = "https://example.com/background.jpg".toImageHolder()
)

See also

Constructors

Link copied to clipboard
constructor(tabs: List<Tab>, getPagedData: suspend (Tab?) -> Feed.Data<T>)

Types

Link copied to clipboard
data class Buttons(val showSearch: Boolean = true, val showSort: Boolean = true, val showPlayAndShuffle: Boolean = false, val customTrackList: List<Track>? = null)

A data class representing the buttons that can be shown in the feed.

Link copied to clipboard
object Companion
Link copied to clipboard
data class Data<T : Any>(val pagedData: PagedData<T>, val buttons: Feed.Buttons? = null, val background: ImageHolder? = null)

Represents the loaded data of the Feed.

Properties

Link copied to clipboard
val getPagedData: suspend (Tab?) -> Feed.Data<T>

to retrieve the shelves with Buttons for a given tab

Link copied to clipboard
val notSortTabs: <Error class: unknown class>

A list of Tab items that are not sort tabs. These tabs are used to load data in the feed and are not considered for sorting.

Link copied to clipboard
val tabs: List<Tab>

The list of tabs in the feed.

Functions

Link copied to clipboard
suspend fun <T : Any> Feed<T>.loadAll(): <Error class: unknown class>

Convenience function to load all items in the Feed. Please use sparringly.

Link copied to clipboard
suspend fun <T : Any> Feed<T>.pagedDataOfFirst(): <Error class: unknown class>

Convenience function to load all items in the Feed for the firstOrNull Tab.