X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FAlbums.kt;h=a38e9dd63a05c6965cac7552296eea0bc0ae111a;hb=8e2e2aa6f1c7c4e9b4b994caee11677d4cd41403;hp=f1c7d3b3a38cb0ffa6fd578bd21003151b6fe095;hpb=16f9a6667147ae402155c333fdd6ceb50f7bb7ec;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt b/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt index f1c7d3b..a38e9dd 100644 --- a/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt +++ b/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt @@ -1,5 +1,5 @@ /** - * Sone - Albums.kt - Copyright © 2019 David ‘Bombe’ Roden + * Sone - Albums.kt - Copyright © 2019–2020 David ‘Bombe’ Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,4 +20,19 @@ package net.pterodactylus.sone.data /** Returns all images contained in this album and all its albums. */ val Album.allImages: Collection get() = - images + albums.flatMap { it.allImages } + images + albums.flatMap(Album::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) + } +}