52 lines
1.7 KiB
Kotlin
52 lines
1.7 KiB
Kotlin
/*
|
|
* Copyright (c) 2019 Hemanth Savarala.
|
|
*
|
|
* Licensed under the GNU General Public License v3
|
|
*
|
|
* This is free software: you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details.
|
|
*/
|
|
|
|
package code.name.monkey.retromusic.repository
|
|
|
|
import code.name.monkey.retromusic.model.Album
|
|
import code.name.monkey.retromusic.model.Artist
|
|
import code.name.monkey.retromusic.model.Song
|
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
|
import software.lavender.music.query.LongFilter
|
|
|
|
/**
|
|
* Created by hemanths on 16/08/17.
|
|
*/
|
|
interface LastAddedRepository {
|
|
fun recentSongs(): List<Song>
|
|
|
|
fun recentAlbums(): List<Album>
|
|
|
|
fun recentArtists(): List<Artist>
|
|
}
|
|
|
|
class RealLastAddedRepository(
|
|
private val songRepository: RealSongRepository,
|
|
private val albumRepository: RealAlbumRepository,
|
|
private val artistRepository: RealArtistRepository
|
|
) : LastAddedRepository {
|
|
override fun recentSongs(): List<Song> {
|
|
// TODO: sort by date added, descending
|
|
return songRepository.songs(SongQuery(dateModified = LongFilter(gt = PreferenceUtil.lastAddedCutoff)))
|
|
}
|
|
|
|
override fun recentAlbums(): List<Album> {
|
|
return albumRepository.splitIntoAlbums(recentSongs())
|
|
}
|
|
|
|
override fun recentArtists(): List<Artist> {
|
|
return artistRepository.splitIntoArtists(recentAlbums())
|
|
}
|
|
}
|