Sort favorite tracks by adding date
This commit is contained in:
parent
2a19f7b2fa
commit
d47024932d
@ -33,11 +33,12 @@ class Track {
|
|||||||
bool favorite;
|
bool favorite;
|
||||||
int diskNumber;
|
int diskNumber;
|
||||||
bool explicit;
|
bool explicit;
|
||||||
|
int favoriteDate;
|
||||||
|
|
||||||
List<dynamic> playbackDetails;
|
List<dynamic> playbackDetails;
|
||||||
|
|
||||||
Track({this.id, this.title, this.duration, this.album, this.playbackDetails, this.albumArt,
|
Track({this.id, this.title, this.duration, this.album, this.playbackDetails, this.albumArt,
|
||||||
this.artists, this.trackNumber, this.offline, this.lyrics, this.favorite, this.diskNumber, this.explicit});
|
this.artists, this.trackNumber, this.offline, this.lyrics, this.favorite, this.diskNumber, this.explicit, this.favoriteDate});
|
||||||
|
|
||||||
String get artistString => artists.map<String>((art) => art.name).join(', ');
|
String get artistString => artists.map<String>((art) => art.name).join(', ');
|
||||||
String get durationString => "${duration.inMinutes}:${duration.inSeconds.remainder(60).toString().padLeft(2, '0')}";
|
String get durationString => "${duration.inMinutes}:${duration.inSeconds.remainder(60).toString().padLeft(2, '0')}";
|
||||||
@ -139,7 +140,8 @@ class Track {
|
|||||||
lyrics: Lyrics(id: json['LYRICS_ID'].toString()),
|
lyrics: Lyrics(id: json['LYRICS_ID'].toString()),
|
||||||
favorite: favorite,
|
favorite: favorite,
|
||||||
diskNumber: int.parse(json['DISK_NUMBER']??'1'),
|
diskNumber: int.parse(json['DISK_NUMBER']??'1'),
|
||||||
explicit: (json['EXPLICIT_LYRICS'].toString() == '1') ? true:false
|
explicit: (json['EXPLICIT_LYRICS'].toString() == '1') ? true:false,
|
||||||
|
favoriteDate: json['DATE_ADD']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Map<String, dynamic> toSQL({off = false}) => {
|
Map<String, dynamic> toSQL({off = false}) => {
|
||||||
@ -154,7 +156,8 @@ class Track {
|
|||||||
'lyrics': jsonEncode(lyrics.toJson()),
|
'lyrics': jsonEncode(lyrics.toJson()),
|
||||||
'favorite': (favorite??0)?1:0,
|
'favorite': (favorite??0)?1:0,
|
||||||
'diskNumber': diskNumber,
|
'diskNumber': diskNumber,
|
||||||
'explicit': explicit?1:0
|
'explicit': explicit?1:0,
|
||||||
|
'favoriteDate': favoriteDate
|
||||||
};
|
};
|
||||||
factory Track.fromSQL(Map<String, dynamic> data) => Track(
|
factory Track.fromSQL(Map<String, dynamic> data) => Track(
|
||||||
id: data['trackId']??data['id'], //If loading from downloads table
|
id: data['trackId']??data['id'], //If loading from downloads table
|
||||||
@ -170,7 +173,8 @@ class Track {
|
|||||||
lyrics: Lyrics.fromJson(jsonDecode(data['lyrics'])),
|
lyrics: Lyrics.fromJson(jsonDecode(data['lyrics'])),
|
||||||
favorite: (data['favorite'] == 1) ? true:false,
|
favorite: (data['favorite'] == 1) ? true:false,
|
||||||
diskNumber: data['diskNumber'],
|
diskNumber: data['diskNumber'],
|
||||||
explicit: (data['explicit'] == 1) ? true:false
|
explicit: (data['explicit'] == 1) ? true:false,
|
||||||
|
favoriteDate: data['favoriteDate']
|
||||||
);
|
);
|
||||||
|
|
||||||
factory Track.fromJson(Map<String, dynamic> json) => _$TrackFromJson(json);
|
factory Track.fromJson(Map<String, dynamic> json) => _$TrackFromJson(json);
|
||||||
|
@ -32,6 +32,7 @@ Track _$TrackFromJson(Map<String, dynamic> json) {
|
|||||||
favorite: json['favorite'] as bool,
|
favorite: json['favorite'] as bool,
|
||||||
diskNumber: json['diskNumber'] as int,
|
diskNumber: json['diskNumber'] as int,
|
||||||
explicit: json['explicit'] as bool,
|
explicit: json['explicit'] as bool,
|
||||||
|
favoriteDate: json['favoriteDate'] as int,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +50,7 @@ Map<String, dynamic> _$TrackToJson(Track instance) => <String, dynamic>{
|
|||||||
'diskNumber': instance.diskNumber,
|
'diskNumber': instance.diskNumber,
|
||||||
'explicit': instance.explicit,
|
'explicit': instance.explicit,
|
||||||
'playbackDetails': instance.playbackDetails,
|
'playbackDetails': instance.playbackDetails,
|
||||||
|
'favoriteDate': instance.favoriteDate,
|
||||||
};
|
};
|
||||||
|
|
||||||
Album _$AlbumFromJson(Map<String, dynamic> json) {
|
Album _$AlbumFromJson(Map<String, dynamic> json) {
|
||||||
|
@ -225,6 +225,7 @@ class _LibraryTracksState extends State<LibraryTracks> {
|
|||||||
|
|
||||||
List<Track> get _sorted {
|
List<Track> get _sorted {
|
||||||
List<Track> tcopy = List.from(tracks);
|
List<Track> tcopy = List.from(tracks);
|
||||||
|
tcopy.sort((a, b) => a.favoriteDate.compareTo(b.favoriteDate));
|
||||||
switch (_sort) {
|
switch (_sort) {
|
||||||
case SortType.ALPHABETIC:
|
case SortType.ALPHABETIC:
|
||||||
tcopy.sort((a, b) => a.title.compareTo(b.title));
|
tcopy.sort((a, b) => a.title.compareTo(b.title));
|
||||||
|
Loading…
Reference in New Issue
Block a user