FakeMusicCatalogBuilder

class FakeMusicCatalogBuilder(val id: String, title: String? = null, playable: Boolean, browsable: Boolean)

Test catalog to perform tests with the FakeMusic media source.

This class is used to define a DSL to generate a customized item hierarchy, representing a media source's media item browsing tree: a media catalog. Its purpose is to tailor the FakeMusic media source's contents for running a specific test.

Once created with the FakeMusicCatalogBuilder.define function, a catalog is ready to be passed to the FakeMusicMediaSourceController.setCatalog to be applied to the FakeMusic media source.

All types of media content can be created with the various functions in FakeMusicCatalogBuilder.

An example of such hierarchy follows:

var myTestPlaylist: List<IviMediaItem> = emptyList()
var myTestSong: IviMediaItem? = null
var myTestIds: List<String> = emptyList()
FakeMusicCatalogBuilder.define(context) {
category("category", "Moods") {
icon = FakeMusicCatalogIcon.MOOD
playlist("pl", "some playlist") {
playable(MY_ID_1, "stairway to heaven") { metadata ->
metadata.withDurationMs(100_000L)
metadata.withArtist("LED zeppelin")
metadata.withBrowsableHint(ContentStyle.CATEGORY_GRID)
}
playable(MY_ID_2, "immigrant song") { metadata ->
metadata.withDurationMs(50_000L)
metadata.withArtist("LCD zeppelin")
metadata.withUserRating(IviMediaRating(Type.THUMBS, RATING_THUMB_DOWN))
}
myTestSong = playable("id", "title") { metadata ->
metadata.withWriter("me")
}
myTestPlaylist = generateTracks(10)
}
browsable("album", "Album") {
playable("track1", "Track One") { it.withDurationMs(1_000L) }
playable("track2", "Track Two") { it.withDurationMs(20_000L) }
myTestIds = childIds
}
}
category("another category", "Unknown") {
playable("mistery", "Mistery Song") { it.withDurationMs(200_000_000L) }
}
}

In the example it is shown how the variables myTestPlaylist and myTestSong can be used to retrieve the contents of the catalog while being created, to help comparing test results with the expected catalog contents. In the same way, myTestIds holds the IviMediaItem.id of all items created up to that moment inside a certain parent item.

It is allowed to generate all sorts of invalid contents, such as empty root items, non-browsable items containing items, invalid metadata.

Constructors

Link copied to clipboard
fun FakeMusicCatalogBuilder(id: String, title: String? = null, playable: Boolean, browsable: Boolean)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Retrieve the ID of all children which are directly contained in this item.

Link copied to clipboard
val count: Int

Retrieve how many children are directly contained in this item.

Link copied to clipboard

Specifies an icon for this FakeMusicCatalogBuilder.

Link copied to clipboard
val id: String

Functions

Link copied to clipboard
fun browsable(id: String, title: String?, contents: ItemBuilderConfig = {}): IviMediaItem

Create a browsable only media item.

Link copied to clipboard

Convert this item to a FakeMusicCatalogItem for export to the FakeMusic media source.

Link copied to clipboard
fun category(id: String, title: String, icon: FakeMusicCatalogIcon = FakeMusicCatalogIcon.FEATURED, contents: ItemBuilderConfig): IviMediaItem

Add a category to the catalog.

Link copied to clipboard
fun generateTracks(count: Int, idPrefix: String = "-track-", titlePrefix: String = "Track ", trackDuration: Duration = DEFAULT_GENERATED_TRACK_DURATION, metadata: (builder: IviMediaItemBuilder) -> Unit = {}): List<IviMediaItem>

Generate count playable media items as children of this item.

Link copied to clipboard
fun item(id: String, title: String?, contents: ItemBuilderConfig = {}): IviMediaItem

Create a media item which is not playable nor browsable.

Link copied to clipboard
fun playable(id: String, title: String?, contents: ItemBuilderConfig = {}): IviMediaItem

Create a playable only media item.

Link copied to clipboard
fun playlist(id: String, title: String?, contents: ItemBuilderConfig = {}): IviMediaItem

Create a browsable and playable media item.