2020-03-26 11:58:30 +01:00
|
|
|
import 'package:flutter_audio_query/flutter_audio_query.dart';
|
|
|
|
|
|
|
|
import '../models/album_model.dart';
|
2020-08-08 19:02:03 +02:00
|
|
|
import '../models/artist_model.dart';
|
2020-04-11 14:27:49 +02:00
|
|
|
import '../models/song_model.dart';
|
2020-03-26 11:58:30 +01:00
|
|
|
import 'local_music_fetcher_contract.dart';
|
|
|
|
|
|
|
|
class LocalMusicFetcherImpl implements LocalMusicFetcher {
|
|
|
|
LocalMusicFetcherImpl(this.flutterAudioQuery);
|
|
|
|
|
|
|
|
final FlutterAudioQuery flutterAudioQuery;
|
|
|
|
|
2020-08-08 19:02:03 +02:00
|
|
|
@override
|
|
|
|
Future<List<ArtistModel>> getArtists() async {
|
|
|
|
final List<ArtistInfo> artistInfoList =
|
|
|
|
await flutterAudioQuery.getArtists();
|
|
|
|
return artistInfoList
|
|
|
|
.map((ArtistInfo artistInfo) => ArtistModel.fromArtistInfo(artistInfo))
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
|
2020-03-26 11:58:30 +01:00
|
|
|
@override
|
|
|
|
Future<List<AlbumModel>> getAlbums() async {
|
|
|
|
final List<AlbumInfo> albumInfoList = await flutterAudioQuery.getAlbums();
|
|
|
|
return albumInfoList
|
|
|
|
.map((AlbumInfo albumInfo) => AlbumModel.fromAlbumInfo(albumInfo))
|
|
|
|
.toList();
|
|
|
|
}
|
2020-04-03 13:55:15 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<List<SongModel>> getSongs() async {
|
|
|
|
final List<SongInfo> songInfoList = await flutterAudioQuery.getSongs();
|
|
|
|
return songInfoList
|
2020-06-28 10:40:53 +02:00
|
|
|
.where((songInfo) => songInfo.isMusic)
|
2020-04-03 13:55:15 +02:00
|
|
|
.map((SongInfo songInfo) => SongModel.fromSongInfo(songInfo))
|
|
|
|
.toList();
|
|
|
|
}
|
2020-03-26 11:58:30 +01:00
|
|
|
}
|