package org.moire.ultrasonic.adapters import java.util.HashSet import org.moire.ultrasonic.domain.Identifiable import org.moire.ultrasonic.domain.MusicDirectory import org.moire.ultrasonic.util.Settings.shouldUseFolderForArtistName import org.moire.ultrasonic.util.Util.getGrandparent class AlbumHeader( var entries: List, var name: String? ) : Identifiable { var isAllVideo: Boolean private set var totalDuration: Long private set var childCount = 0 private val _artists: MutableSet private val _grandParents: MutableSet private val _genres: MutableSet private val _years: MutableSet val artists: Set get() = _artists val grandParents: Set get() = _grandParents val genres: Set get() = _genres val years: Set get() = _years private fun processGrandParents(entry: MusicDirectory.Child) { val grandParent = getGrandparent(entry.path) if (grandParent != null) { _grandParents.add(grandParent) } } @Suppress("NestedBlockDepth") private fun processEntries(list: List) { entries = list childCount = entries.size for (entry in entries) { if (!entry.isVideo) { isAllVideo = false } if (!entry.isDirectory) { if (shouldUseFolderForArtistName) { processGrandParents(entry) } if (entry.artist != null) { val duration = entry.duration if (duration != null) { totalDuration += duration.toLong() } _artists.add(entry.artist!!) } if (entry.genre != null) { _genres.add(entry.genre!!) } if (entry.year != null) { _years.add(entry.year!!) } } } } init { _artists = HashSet() _grandParents = HashSet() _genres = HashSet() _years = HashSet() isAllVideo = true totalDuration = 0 processEntries(entries) } override val id: String get() = "HEADER" override val longId: Long get() = -1L }