Skip to content

Commit

Permalink
feat: sort tracks by newest and oldest dates
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jun 18, 2023
1 parent af6ab5f commit b4713e3
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 18 deletions.
3 changes: 2 additions & 1 deletion lib/components/library/user_local_tracks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ enum SortBy {
descending,
artist,
album,
dateAdded,
newest,
oldest,
}

final localTracksProvider = FutureProvider<List<LocalTrack>>((ref) async {
Expand Down
19 changes: 14 additions & 5 deletions lib/components/shared/sort_tracks_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SortTracksDropdown extends StatelessWidget {

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
return ListTileTheme(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
Expand Down Expand Up @@ -47,11 +48,19 @@ class SortTracksDropdown extends StatelessWidget {
),
),
PopSheetEntry(
value: SortBy.dateAdded,
enabled: value != SortBy.dateAdded,
value: SortBy.newest,
enabled: value != SortBy.newest,
child: ListTile(
enabled: value != SortBy.dateAdded,
title: Text(context.l10n.sort_date),
enabled: value != SortBy.newest,
title: Text(context.l10n.sort_newest),
),
),
PopSheetEntry(
value: SortBy.oldest,
enabled: value != SortBy.oldest,
child: ListTile(
enabled: value != SortBy.oldest,
title: Text(context.l10n.sort_oldest),
),
),
PopSheetEntry(
Expand Down Expand Up @@ -79,7 +88,7 @@ class SortTracksDropdown extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
child: DefaultTextStyle(
style: Theme.of(context).textTheme.titleSmall!,
style: theme.textTheme.titleSmall!,
child: Row(
children: [
const Icon(SpotubeIcons.sort),
Expand Down
1 change: 0 additions & 1 deletion lib/components/shared/track_table/tracks_table_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class TracksTableView extends HookConsumerWidget {

@override
Widget build(context, ref) {
final theme = Theme.of(context);
final mediaQuery = MediaQuery.of(context);

ref.watch(ProxyPlaylistNotifier.provider);
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_bn.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"none": "কোনটিই না",
"sort_a_z": "A-Z ক্রমে সাজান",
"sort_z_a": "Z-A ক্রমে সাজান",
"sort_date": "তারিখের ক্রমে সাজান",
"sort_artist": "শিল্পীর ক্রমে সাজান",
"sort_album": "অ্যালবামের ক্রমে সাজান",
"sort_tracks": "গানের ক্রম",
Expand Down
7 changes: 4 additions & 3 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"none": "None",
"sort_a_z": "Sort by A-Z",
"sort_z_a": "Sort by Z-A",
"sort_date": "Sort by date",
"sort_artist": "Sort by Artist",
"sort_album": "Sort by Album",
"sort_tracks": "Sort Tracks",
Expand Down Expand Up @@ -235,8 +234,10 @@
"youtube": "YouTube",
"channel": "Channel",
"likes": "Likes",
"dislikes": "Dislikes",
"dislikes": "Dislikes",
"views": "Views",
"streamUrl": "Stream URL",
"stop": "Stop"
"stop": "Stop",
"sort_newest": "Sort by newest added",
"sort_oldest": "Sort by oldest added"
}
1 change: 0 additions & 1 deletion lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"none": "Aucun",
"sort_a_z": "Trier par ordre alphabétique",
"sort_z_a": "Trier par ordre alphabétique inverse",
"sort_date": "Trier par date",
"sort_artist": "Trier par artiste",
"sort_album": "Trier par album",
"sort_tracks": "Trier les pistes",
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_hi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"none": "कोई नहीं",
"sort_a_z": "A-Z सॉर्ट करें",
"sort_z_a": "Z-A सॉर्ट करें",
"sort_date": "तिथि के अनुसार सॉर्ट करें",
"sort_artist": "कलाकार के अनुसार सॉर्ट करें",
"sort_album": "एल्बम के अनुसार सॉर्ट करें",
"sort_tracks": "ट्रैक को सॉर्ट करें",
Expand Down
12 changes: 7 additions & 5 deletions lib/utils/service_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,14 @@ abstract class ServiceUtils {
0;
case SortBy.ascending:
return a.name?.compareTo(b.name ?? "") ?? 0;
case SortBy.dateAdded:
final aDate =
double.parse(a.album?.releaseDate?.split("-").first ?? "2069");
final bDate =
double.parse(b.album?.releaseDate?.split("-").first ?? "2069");
case SortBy.oldest:
final aDate = DateTime.parse(a.album?.releaseDate ?? "2069-01-01");
final bDate = DateTime.parse(b.album?.releaseDate ?? "2069-01-01");
return aDate.compareTo(bDate);
case SortBy.newest:
final aDate = DateTime.parse(a.album?.releaseDate ?? "2069-01-01");
final bDate = DateTime.parse(b.album?.releaseDate ?? "2069-01-01");
return bDate.compareTo(aDate);
case SortBy.descending:
return b.name?.compareTo(a.name ?? "") ?? 0;
default:
Expand Down

0 comments on commit b4713e3

Please sign in to comment.