2020-03-26 11:58:30 +01:00
|
|
|
import 'package:flutter_audio_query/flutter_audio_query.dart';
|
2020-03-24 22:17:03 +01:00
|
|
|
import 'package:meta/meta.dart';
|
2020-03-30 22:25:57 +02:00
|
|
|
import 'package:moor/moor.dart';
|
2020-03-24 22:17:03 +01:00
|
|
|
|
|
|
|
import '../../domain/entities/album.dart';
|
|
|
|
import '../datasources/moor_music_data_source.dart';
|
|
|
|
|
|
|
|
class AlbumModel extends Album {
|
2020-06-28 10:40:53 +02:00
|
|
|
const AlbumModel({
|
2020-03-26 10:19:36 +01:00
|
|
|
this.id,
|
|
|
|
@required String title,
|
|
|
|
@required String artist,
|
|
|
|
String albumArtPath,
|
2020-06-28 21:52:10 +02:00
|
|
|
int year,
|
2020-03-26 10:19:36 +01:00
|
|
|
}) : super(
|
|
|
|
title: title,
|
|
|
|
artist: artist,
|
|
|
|
albumArtPath: albumArtPath,
|
2020-06-28 21:52:10 +02:00
|
|
|
pubYear: year,
|
2020-03-26 10:19:36 +01:00
|
|
|
);
|
2020-03-24 22:17:03 +01:00
|
|
|
|
2020-03-30 22:25:57 +02:00
|
|
|
factory AlbumModel.fromMoorAlbum(MoorAlbum moorAlbum) => AlbumModel(
|
2020-06-28 10:40:53 +02:00
|
|
|
id: moorAlbum.id,
|
2020-03-26 10:19:36 +01:00
|
|
|
title: moorAlbum.title,
|
|
|
|
artist: moorAlbum.artist,
|
|
|
|
albumArtPath: moorAlbum.albumArtPath,
|
2020-06-28 21:52:10 +02:00
|
|
|
year: moorAlbum.year,
|
2020-03-26 10:19:36 +01:00
|
|
|
);
|
|
|
|
|
2020-03-28 09:36:57 +01:00
|
|
|
factory AlbumModel.fromAlbumInfo(AlbumInfo albumInfo) {
|
|
|
|
final String _year = albumInfo.firstYear;
|
|
|
|
|
|
|
|
return AlbumModel(
|
2020-06-28 10:40:53 +02:00
|
|
|
id: int.parse(albumInfo.id),
|
2020-03-28 09:36:57 +01:00
|
|
|
title: albumInfo.title,
|
|
|
|
artist: albumInfo.artist,
|
|
|
|
albumArtPath: albumInfo.albumArt,
|
2020-06-28 21:52:10 +02:00
|
|
|
year: _year == null ? null : int.parse(_year),
|
2020-03-28 09:36:57 +01:00
|
|
|
);
|
|
|
|
}
|
2020-03-26 11:58:30 +01:00
|
|
|
|
2020-03-26 10:19:36 +01:00
|
|
|
final int id;
|
2020-03-24 22:17:03 +01:00
|
|
|
|
2020-03-30 22:25:57 +02:00
|
|
|
AlbumsCompanion toAlbumsCompanion() => AlbumsCompanion(
|
|
|
|
title: Value(title),
|
|
|
|
artist: Value(artist),
|
|
|
|
albumArtPath: Value(albumArtPath),
|
|
|
|
year: Value(pubYear),
|
2020-03-26 10:19:36 +01:00
|
|
|
);
|
2020-03-24 22:17:03 +01:00
|
|
|
}
|