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-28 07:48:19 +00:00
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import code.name.monkey.retromusic.model.Song
|
2021-12-15 18:28:55 +00:00
|
|
|
import software.lavender.music.query.IntFilter
|
|
|
|
import software.lavender.music.query.LongFilter
|
|
|
|
import software.lavender.music.query.Query
|
|
|
|
import software.lavender.music.query.StringFilter
|
|
|
|
|
|
|
|
// TODO: sorting
|
|
|
|
data class SongQuery(
|
|
|
|
val id: LongFilter? = null,
|
|
|
|
val title: StringFilter? = null,
|
|
|
|
val year: IntFilter? = null,
|
|
|
|
val data: StringFilter? = null,
|
|
|
|
val dateModified: LongFilter? = null,
|
|
|
|
val albumId: LongFilter? = null,
|
|
|
|
val albumName: StringFilter? = null,
|
|
|
|
val artistId: LongFilter? = null,
|
|
|
|
val artistName: StringFilter? = null,
|
|
|
|
val composer: StringFilter? = null,
|
|
|
|
val albumArtist: StringFilter? = null
|
|
|
|
) : Query<Song> {
|
|
|
|
override fun apply(testee: Song): Boolean {
|
|
|
|
if (id != null && !id.matches(testee.id)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (title != null && !title.matches(testee.title)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (year != null && !year.matches(testee.year)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (data != null && !data.matches(testee.data)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (dateModified != null && !dateModified.matches(testee.dateModified)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (albumId != null && !albumId.matches(testee.albumId)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 08:59:40 +00:00
|
|
|
|
2018-11-28 07:48:19 +00:00
|
|
|
/**
|
|
|
|
* Created by hemanths on 10/08/17.
|
|
|
|
*/
|
2020-08-13 17:08:37 +00:00
|
|
|
interface SongRepository {
|
2018-11-28 07:48:19 +00:00
|
|
|
|
2020-08-13 17:08:37 +00:00
|
|
|
fun songs(): List<Song>
|
2020-01-29 17:25:43 +00:00
|
|
|
|
2021-12-15 18:28:55 +00:00
|
|
|
fun songs(query: SongQuery): List<Song>
|
2020-08-13 17:08:37 +00:00
|
|
|
|
|
|
|
fun songs(query: String): List<Song>
|
|
|
|
|
|
|
|
fun songsByFilePath(filePath: String): List<Song>
|
|
|
|
|
2021-12-15 18:28:55 +00:00
|
|
|
fun song(query: SongQuery): Song
|
2020-08-13 17:08:37 +00:00
|
|
|
|
2020-09-17 21:25:41 +00:00
|
|
|
fun song(songId: Long): Song
|
2020-08-13 17:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class RealSongRepository(private val context: Context) : SongRepository {
|
|
|
|
|
|
|
|
override fun songs(): List<Song> {
|
2021-12-15 18:28:55 +00:00
|
|
|
return listOf(
|
|
|
|
Song(
|
|
|
|
1,
|
2021-12-15 22:46:40 +00:00
|
|
|
"river-lake convergence",
|
2021-12-15 18:28:55 +00:00
|
|
|
1,
|
|
|
|
2021,
|
|
|
|
23723478,
|
2021-12-15 22:46:40 +00:00
|
|
|
"https://versary.town/river-lake-convergence.mp3",
|
2021-12-15 18:28:55 +00:00
|
|
|
1639589623,
|
|
|
|
1,
|
2021-12-15 22:46:40 +00:00
|
|
|
"river-lake convergence",
|
2021-12-15 18:28:55 +00:00
|
|
|
1,
|
2021-12-15 22:46:40 +00:00
|
|
|
"annieversary",
|
|
|
|
null,
|
|
|
|
"annieversary"
|
2021-12-15 18:28:55 +00:00
|
|
|
)
|
|
|
|
)
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|
2018-11-28 07:48:19 +00:00
|
|
|
|
2021-12-15 18:28:55 +00:00
|
|
|
override fun songs(query: SongQuery): List<Song> {
|
2019-08-02 08:59:40 +00:00
|
|
|
val songs = arrayListOf<Song>()
|
2021-12-15 18:28:55 +00:00
|
|
|
for (song in songs()) {
|
|
|
|
if (query.apply(song)) {
|
|
|
|
songs.add(song)
|
|
|
|
}
|
2019-08-02 08:59:40 +00:00
|
|
|
}
|
|
|
|
return songs
|
|
|
|
}
|
|
|
|
|
2021-12-15 18:28:55 +00:00
|
|
|
override fun song(query: SongQuery): Song {
|
|
|
|
val songs = arrayListOf<Song>()
|
|
|
|
for (song in songs()) {
|
|
|
|
if (query.apply(song)) {
|
|
|
|
songs.add(song)
|
|
|
|
}
|
2019-08-02 08:59:40 +00:00
|
|
|
}
|
2021-12-15 18:28:55 +00:00
|
|
|
return songs.firstOrNull() ?: Song.emptySong
|
2019-08-02 08:59:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 17:08:37 +00:00
|
|
|
override fun songs(query: String): List<Song> {
|
2021-12-15 18:28:55 +00:00
|
|
|
return songs(SongQuery(title = StringFilter(like = "%$query%")))
|
2020-08-13 17:08:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 21:25:41 +00:00
|
|
|
override fun song(songId: Long): Song {
|
2021-12-15 18:28:55 +00:00
|
|
|
return song(SongQuery(id = LongFilter(eq = songId)))
|
2020-08-13 17:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun songsByFilePath(filePath: String): List<Song> {
|
2021-12-15 18:28:55 +00:00
|
|
|
return songs(SongQuery(data = StringFilter(eq = filePath)))
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|
2018-11-28 07:48:19 +00:00
|
|
|
}
|