Fix albums/artists sorting by date of adding to favorites

This commit is contained in:
kilowatt 2020-10-25 12:32:23 +03:00
parent df3b7d3d63
commit 2a19f7b2fa
3 changed files with 23 additions and 11 deletions

View file

@ -195,8 +195,9 @@ class Album {
bool library;
AlbumType type;
String releaseDate;
String favoriteDate;
Album({this.id, this.title, this.art, this.artists, this.tracks, this.fans, this.offline, this.library, this.type, this.releaseDate});
Album({this.id, this.title, this.art, this.artists, this.tracks, this.fans, this.offline, this.library, this.type, this.releaseDate, this.favoriteDate});
String get artistString => artists.map<String>((art) => art.name).join(', ');
Duration get duration => Duration(seconds: tracks.fold(0, (v, t) => v += t.duration.inSeconds));
@ -218,7 +219,8 @@ class Album {
fans: json['NB_FAN'],
library: library,
type: type,
releaseDate: json['DIGITAL_RELEASE_DATE']??json['PHYSICAL_RELEASE_DATE']
releaseDate: json['DIGITAL_RELEASE_DATE']??json['PHYSICAL_RELEASE_DATE'],
favoriteDate: json['DATE_FAVORITE']
);
}
Map<String, dynamic> toSQL({off = false}) => {
@ -231,7 +233,8 @@ class Album {
'offline': off?1:0,
'library': (library??false)?1:0,
'type': AlbumType.values.indexOf(type),
'releaseDate': releaseDate
'releaseDate': releaseDate,
'favoriteDate': favoriteDate
};
factory Album.fromSQL(Map<String, dynamic> data) => Album(
id: data['id'],
@ -247,7 +250,8 @@ class Album {
offline: (data['offline'] == 1) ? true:false,
library: (data['library'] == 1) ? true:false,
type: AlbumType.values[data['type']],
releaseDate: data['releaseDate']
releaseDate: data['releaseDate'],
favoriteDate: data['favoriteDate']
);
factory Album.fromJson(Map<String, dynamic> json) => _$AlbumFromJson(json);
@ -266,8 +270,9 @@ class Artist {
bool offline;
bool library;
bool radio;
String favoriteDate;
Artist({this.id, this.name, this.albums, this.albumCount, this.topTracks, this.picture, this.fans, this.offline, this.library, this.radio});
Artist({this.id, this.name, this.albums, this.albumCount, this.topTracks, this.picture, this.fans, this.offline, this.library, this.radio, this.favoriteDate});
String get fansString => NumberFormat.compact().format(fans);
@ -292,6 +297,7 @@ class Artist {
topTracks: (topJson['data']??[]).map<Track>((dynamic data) => Track.fromPrivateJson(data)).toList(),
library: library,
radio: _radio,
favoriteDate: json['DATE_FAVORITE']
);
}
Map<String, dynamic> toSQL({off = false}) => {
@ -304,7 +310,8 @@ class Artist {
'albumCount': this.albumCount??(this.albums??[]).length,
'offline': off?1:0,
'library': (library??false)?1:0,
'radio': radio?1:0
'radio': radio?1:0,
'favoriteDate': favoriteDate
};
factory Artist.fromSQL(Map<String, dynamic> data) => Artist(
id: data['id'],
@ -320,7 +327,8 @@ class Artist {
fans: data['fans'],
offline: (data['offline'] == 1)?true:false,
library: (data['library'] == 1)?true:false,
radio: (data['radio'] == 1)?true:false
radio: (data['radio'] == 1)?true:false,
favoriteDate: data['favoriteDate']
);
factory Artist.fromJson(Map<String, dynamic> json) => _$ArtistFromJson(json);

View file

@ -71,6 +71,7 @@ Album _$AlbumFromJson(Map<String, dynamic> json) {
library: json['library'] as bool,
type: _$enumDecodeNullable(_$AlbumTypeEnumMap, json['type']),
releaseDate: json['releaseDate'] as String,
favoriteDate: json['favoriteDate'] as String
);
}
@ -85,6 +86,7 @@ Map<String, dynamic> _$AlbumToJson(Album instance) => <String, dynamic>{
'library': instance.library,
'type': _$AlbumTypeEnumMap[instance.type],
'releaseDate': instance.releaseDate,
'favoriteDate': instance.favoriteDate
};
T _$enumDecode<T>(

View file

@ -512,11 +512,12 @@ class _LibraryAlbumsState extends State<LibraryAlbums> {
List<Album> get _sorted {
List<Album> albums = List.from(_albums);
albums.sort((a, b) => a.favoriteDate.compareTo(b.favoriteDate));
switch (_sort) {
case AlbumSortType.DEFAULT:
return _albums;
return albums;
case AlbumSortType.REVERSE:
return _albums.reversed.toList();
return albums.reversed.toList();
case AlbumSortType.ALPHABETIC:
albums.sort((a, b) => a.title.toLowerCase().compareTo(b.title.toLowerCase()));
return albums;
@ -677,11 +678,12 @@ class _LibraryArtistsState extends State<LibraryArtists> {
List<Artist> get _sorted {
List<Artist> artists = List.from(_artists);
artists.sort((a, b) => a.favoriteDate.compareTo(b.favoriteDate));
switch (_sort) {
case ArtistSortType.DEFAULT:
return _artists;
return artists;
case ArtistSortType.REVERSE:
return _artists.reversed.toList();
return artists.reversed.toList();
case ArtistSortType.POPULARITY:
artists.sort((a, b) => b.fans - a.fans);
return artists;