X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FAlbums.kt;h=da71d628941f61de5c3dc3e39635e13b3a47f949;hp=0c79a842897b66ee25853a231f6361c39fceb68e;hb=509b81185b3a1e82bb78308640d0d7b6b741d3e0;hpb=438378deab1514f0f608d975ef65f5b7aea44ccb diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt b/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt index 0c79a84..da71d62 100644 --- a/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt +++ b/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt @@ -21,3 +21,18 @@ package net.pterodactylus.sone.data val Album.allImages: Collection get() = images + albums.flatMap { it.allImages } + +/** + * Returns this album and all albums contained in this album (recursively). + * A child album is always listed after its parent. + */ +val Album.allAlbums: List + get() = + listOf(this) + albums.flatMap(Album::allAlbums) + +@get:JvmName("notEmpty") +val notEmpty: (Album) -> Boolean = { album -> + album.allImages.let { images -> + images.isNotEmpty() && images.any(Image::isInserted) + } +}