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

View File

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