Package-level declarations

Media timeline and operations.

Timeline

This section provides methods for constructing a timeline and various functionality for media.

val photoManager: PhotoManager
val timeline: Timeline = photoManager.timeline

Media List

val timeline: Timeline

lifecycleScope.launch(Dispatchers.IO) {
// timeline.createFlow - Media list
// timeline.createPagingFlow - Paginated media list
// timeline.createMediaFlowByIds - Media list by ids
// timeline.createSectionFlow - Media list with createdAt in range
// timeline.createMonthlySectionsGroupedByYearsFlow - Sorted list of months and the number of photos in each of them
}

Filtered Media List

To work with a filtered list, you need to set the filter parameters and use one of the Filtered methods.

val timeline: Timeline
val filter = TimelineFilter(
byUploadStatus = ByUploadStatus.UPLOADED,
byMediaType = ByMediaType.PHOTOS,
byCatalog = ByCatalog.NOT_SET,
byOther = ByOther.FAVORITES
)

lifecycleScope.launch(Dispatchers.IO) {
timeline.setFilter(
userId = 0L,
filter = filter
)
}

// To get a filtered list, use one of the methods given
lifecycleScope.launch(Dispatchers.IO) {
// timeline.createFilteredFlow - Filtered media list
// timeline.createFilteredPagingFlow - Paginated filtered media list
// timeline.createFilteredSectionFlow - Media whose creation date is in the specified range
}

// To track the current filter
lifecycleScope.launch(Dispatchers.IO) {
timeline.createFilterFlow(userId = 0L).collect { filter -> // filter: TimelineFilter
// Handle it...
}
}

Media Operations

You can get various information about media and perform operations.

val timeline: Timeline

lifecycleScope.launch(Dispatchers.IO) {

// Get media list from database
val mediaItems: List<MediaItems> = timeline.getMediaItemsByIds(mediaIds = setOf(1L, 2L, 3L))

// Get media content meta
val mediaContent: MediaItemContent = timeline.getMediaContent

// Get media resource link
val mediaResourceLink: String? = timeline.getMediaBackendUrl(mediaId = 0L)

val result: OperationResult = timeline.deleteMedia(mediaId = 0L)
}


// Fetch media from backend and create flow
lifecycleScope.launch(Dispatchers.IO) {
fetchMediaAndCreateFlow(
userId = 0L,
mediaBackendIds = setOf("1", "2", "3")
).collect { mediaList -> // mediaList: List<MediaItem>
// Handle it...
}
}

Favorites

The Favorites feature allows you to manage your favorite media list by adding and removing files. When added to the Favorites list, media files also become part of various collections.

val timeline: Timeline

lifecycleScope.launch(Dispatchers.IO) {
timeline.addToFavorite(mediaIds = setOf(1L, 2L, 3L))
timeline.deleteFromFavorite(mediaIds = setOf(1L, 2L, 3L))
}

Extensions

Media files can contain various additional information. For example, life photos (photos and videos). For such cases, the concept of extensions is used. To obtain information about a media file's extensions, use the following code example.

val timeline: Timeline

lifecycleScope.launch(Dispatchers.IO) {
val extension: MediaExtensionItem = timeline.getMediaExtension(
mediaId = 0L,
type = MediaExtensionType.LIVE_PHOTO
)

val extensions: List<getMediaExtensions> = timeline.getMediaExtensios(mediaId = 0L)
}

Get Similar Media

val timeline: Timeline

lifecycleScope.launch(Dispatchers.IO) {
timeline.fetchSimilarMedia(mediaId = 0L)
createSimilarMediaFlow(mediaId = 0L).collect { mediaList -> // mediaList: List<MediaItem>
// Handle it...
}
}

Move To Another User

You can move or copy media to another user (Family, Private, Main).

val timeline: Timeline
var result: OperationResult

lifecycleScope.launch(Dispatchers.IO) {
result = timeline.copyToAnotherUser(tragetUserId = 0L, mediaIds = setOf(1L, 2L, 3L))
result = timeline.moveToAnotherUser(tragetUserId = 0L, mediaIds = setOf(1L, 2L, 3L))
}

Download

val timeline: Timeline

lifecycleScope.launch(Dispatchers.IO) {
timeline.enqueueToDownload(
mediaIds = setOf(1L, 2L, 3L),
priority = DownloadPriority.HIGH
)
}

Types

Link copied to clipboard
data class MonthSectionInfo(val timestamp: Long, val photoCount: Int) : Parcelable
Link copied to clipboard
interface Timeline
Link copied to clipboard
data class TimelineFilter(val byUploadStatus: TimelineFilter.ByUploadStatus, val byMediaType: TimelineFilter.ByMediaType, val byCatalog: TimelineFilter.ByCatalog, val byOther: TimelineFilter.ByOther)
Link copied to clipboard
data class YearSectionInfo(val timestamp: Long, val monthSections: List<MonthSectionInfo>) : Parcelable