2019-03-03 09:20:15 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2020-08-13 17:08:37 +00:00
|
|
|
package code.name.monkey.retromusic.repository
|
2018-11-30 01:06:16 +00:00
|
|
|
|
|
|
|
import code.name.monkey.retromusic.model.Album
|
|
|
|
import code.name.monkey.retromusic.model.Artist
|
|
|
|
import code.name.monkey.retromusic.model.Song
|
2020-06-06 18:57:28 +00:00
|
|
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
2021-12-15 18:28:55 +00:00
|
|
|
import software.lavender.music.query.LongFilter
|
2018-11-30 01:06:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by hemanths on 16/08/17.
|
|
|
|
*/
|
2020-08-13 17:08:37 +00:00
|
|
|
interface LastAddedRepository {
|
|
|
|
fun recentSongs(): List<Song>
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-08-13 17:08:37 +00:00
|
|
|
fun recentAlbums(): List<Album>
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-08-13 17:08:37 +00:00
|
|
|
fun recentArtists(): List<Artist>
|
|
|
|
}
|
|
|
|
|
|
|
|
class RealLastAddedRepository(
|
|
|
|
private val songRepository: RealSongRepository,
|
|
|
|
private val albumRepository: RealAlbumRepository,
|
|
|
|
private val artistRepository: RealArtistRepository
|
|
|
|
) : LastAddedRepository {
|
|
|
|
override fun recentSongs(): List<Song> {
|
2021-12-15 18:28:55 +00:00
|
|
|
// TODO: sort by date added, descending
|
|
|
|
return songRepository.songs(SongQuery(dateModified = LongFilter(gt = PreferenceUtil.lastAddedCutoff)))
|
2020-08-13 17:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun recentAlbums(): List<Album> {
|
|
|
|
return albumRepository.splitIntoAlbums(recentSongs())
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun recentArtists(): List<Artist> {
|
|
|
|
return artistRepository.splitIntoArtists(recentAlbums())
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|
|
|
|
}
|