2023-07-29 02:17:26 +00:00
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttericon/font_awesome5_icons.dart';
|
|
|
|
import 'package:freezer/api/cache.dart';
|
|
|
|
import 'package:freezer/api/deezer.dart';
|
|
|
|
import 'package:freezer/api/definitions.dart';
|
|
|
|
import 'package:freezer/api/importer.dart';
|
2023-10-18 15:08:05 +00:00
|
|
|
import 'package:freezer/api/player/audio_handler.dart';
|
2023-07-29 02:17:26 +00:00
|
|
|
import 'package:freezer/settings.dart';
|
|
|
|
import 'package:freezer/ui/details_screens.dart';
|
|
|
|
import 'package:freezer/ui/elements.dart';
|
|
|
|
import 'package:freezer/ui/error.dart';
|
|
|
|
import 'package:freezer/ui/importer_screen.dart';
|
|
|
|
import 'package:freezer/ui/tiles.dart';
|
|
|
|
import 'package:freezer/translations.i18n.dart';
|
|
|
|
|
|
|
|
import 'menu.dart';
|
|
|
|
import '../api/download.dart';
|
|
|
|
|
|
|
|
class LibraryAppBar extends StatelessWidget implements PreferredSizeWidget {
|
2023-10-12 22:09:37 +00:00
|
|
|
const LibraryAppBar({super.key});
|
|
|
|
|
2023-07-29 02:17:26 +00:00
|
|
|
@override
|
|
|
|
Size get preferredSize => AppBar().preferredSize;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return AppBar(
|
|
|
|
title: Text('Library'.i18n),
|
|
|
|
actions: <Widget>[
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.file_download,
|
|
|
|
semanticLabel: "Download".i18n,
|
|
|
|
),
|
2023-10-08 10:53:22 +00:00
|
|
|
onPressed: () => Navigator.pushNamed(context, '/downloads'),
|
2023-07-29 02:17:26 +00:00
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.settings,
|
|
|
|
semanticLabel: "Settings".i18n,
|
|
|
|
),
|
2023-10-08 10:53:22 +00:00
|
|
|
onPressed: () => Navigator.pushNamed(context, '/settings'),
|
2023-07-29 02:17:26 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibraryScreen extends StatelessWidget {
|
2023-10-12 22:09:37 +00:00
|
|
|
const LibraryScreen({super.key});
|
2023-10-08 10:53:22 +00:00
|
|
|
|
2023-07-29 02:17:26 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2023-10-12 22:09:37 +00:00
|
|
|
appBar: const LibraryAppBar(),
|
2023-07-29 02:17:26 +00:00
|
|
|
body: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
const SizedBox(height: 4.0),
|
|
|
|
if (!downloadManager.running && downloadManager.queueSize! > 0)
|
|
|
|
ListTile(
|
|
|
|
title: Text('Downloads'.i18n),
|
2023-10-12 22:09:37 +00:00
|
|
|
leading:
|
|
|
|
const LeadingIcon(Icons.file_download, color: Colors.grey),
|
2023-07-29 02:17:26 +00:00
|
|
|
subtitle: Text(
|
|
|
|
'Downloading is currently stopped, click here to resume.'
|
|
|
|
.i18n),
|
|
|
|
onTap: () {
|
|
|
|
downloadManager.start();
|
|
|
|
Navigator.pushNamed(context, '/downloads');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('Shuffle'.i18n),
|
2023-10-12 22:09:37 +00:00
|
|
|
leading: const LeadingIcon(Icons.shuffle, color: Color(0xffeca704)),
|
2023-07-29 02:17:26 +00:00
|
|
|
onTap: () async {
|
|
|
|
List<Track> tracks = (await deezerAPI.libraryShuffle())!;
|
|
|
|
playerHelper.playFromTrackList(
|
|
|
|
tracks,
|
|
|
|
tracks[0].id,
|
|
|
|
QueueSource(
|
|
|
|
id: 'libraryshuffle',
|
|
|
|
source: 'libraryshuffle',
|
|
|
|
text: 'Library shuffle'.i18n));
|
|
|
|
},
|
|
|
|
),
|
2023-10-12 22:09:37 +00:00
|
|
|
const FreezerDivider(),
|
2023-07-29 02:17:26 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text('Tracks'.i18n),
|
2023-10-12 22:09:37 +00:00
|
|
|
leading:
|
|
|
|
const LeadingIcon(Icons.audiotrack, color: Color(0xffbe3266)),
|
2023-07-29 02:17:26 +00:00
|
|
|
onTap: () => Navigator.pushNamed(context, '/library/tracks'),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('Albums'.i18n),
|
2023-10-12 22:09:37 +00:00
|
|
|
leading: const LeadingIcon(Icons.album, color: Color(0xff4b2e7e)),
|
2023-07-29 02:17:26 +00:00
|
|
|
onTap: () => Navigator.pushNamed(context, '/library/albums'),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('Artists'.i18n),
|
2023-10-12 22:09:37 +00:00
|
|
|
leading: const LeadingIcon(Icons.recent_actors,
|
|
|
|
color: Color(0xff384697)),
|
2023-07-29 02:17:26 +00:00
|
|
|
onTap: () => Navigator.pushNamed(context, '/library/artists'),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('Playlists'.i18n),
|
2023-10-12 22:09:37 +00:00
|
|
|
leading: const LeadingIcon(Icons.playlist_play,
|
|
|
|
color: Color(0xff0880b5)),
|
2023-07-29 02:17:26 +00:00
|
|
|
onTap: () => Navigator.pushNamed(context, '/library/playlists'),
|
|
|
|
),
|
2023-10-12 22:09:37 +00:00
|
|
|
const FreezerDivider(),
|
2023-07-29 02:17:26 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text('History'.i18n),
|
2023-10-12 22:09:37 +00:00
|
|
|
leading: const LeadingIcon(Icons.history, color: Color(0xff009a85)),
|
2023-07-29 02:17:26 +00:00
|
|
|
onTap: () => Navigator.pushNamed(context, '/library/history'),
|
|
|
|
),
|
2023-10-12 22:09:37 +00:00
|
|
|
const FreezerDivider(),
|
2023-07-29 02:17:26 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text('Import'.i18n),
|
2023-10-12 22:09:37 +00:00
|
|
|
leading: const LeadingIcon(Icons.import_export,
|
|
|
|
color: Color(0xff2ba766)),
|
2023-07-29 02:17:26 +00:00
|
|
|
subtitle: Text('Import playlists from Spotify'.i18n),
|
|
|
|
onTap: () {
|
|
|
|
//Show progress
|
|
|
|
if (importer.done || importer.busy) {
|
2023-10-12 22:09:37 +00:00
|
|
|
Navigator.of(context).pushRoute(
|
|
|
|
builder: (context) => const ImporterStatusScreen());
|
2023-07-29 02:17:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-20 23:12:33 +00:00
|
|
|
Navigator.of(context).pushNamed('/spotify-importer');
|
|
|
|
|
|
|
|
//Pick importer dialog (removed as ImporterV1 is broken)
|
|
|
|
// showDialog(
|
|
|
|
// context: context,
|
|
|
|
// builder: (context) => SimpleDialog(
|
|
|
|
// title: Text('Importer'.i18n),
|
|
|
|
// children: [
|
|
|
|
// ListTile(
|
|
|
|
// leading: const Icon(FontAwesome5.spotify),
|
|
|
|
// title: Text('Spotify v1'.i18n),
|
|
|
|
// subtitle: Text(
|
|
|
|
// 'Import Spotify playlists up to 100 tracks without any login.'
|
|
|
|
// .i18n),
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.of(context).pop();
|
|
|
|
// Navigator.of(context).pushRoute(
|
|
|
|
// builder: (context) =>
|
|
|
|
// const SpotifyImporterV1());
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ListTile(
|
|
|
|
// leading: const Icon(FontAwesome5.spotify),
|
|
|
|
// title: Text('Spotify v2'.i18n),
|
|
|
|
// subtitle: Text(
|
|
|
|
// 'Import any Spotify playlist, import from own Spotify library. Requires free account.'
|
|
|
|
// .i18n),
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.of(context).pop();
|
|
|
|
// Navigator.of(context).pushRoute(
|
|
|
|
// builder: (context) =>
|
|
|
|
// const SpotifyImporterV2());
|
|
|
|
// },
|
|
|
|
// )
|
|
|
|
// ],
|
|
|
|
// ));
|
2023-07-29 02:17:26 +00:00
|
|
|
},
|
|
|
|
),
|
2023-10-14 14:26:13 +00:00
|
|
|
if (DownloadManager.isSupported)
|
2023-10-16 22:22:50 +00:00
|
|
|
ExpansionTile(
|
|
|
|
title: Text('Statistics'.i18n),
|
|
|
|
leading:
|
|
|
|
const LeadingIcon(Icons.insert_chart, color: Colors.grey),
|
|
|
|
children: <Widget>[
|
|
|
|
FutureBuilder(
|
|
|
|
future: downloadManager.getStats(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasError) return const ErrorScreen();
|
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 4.0),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[CircularProgressIndicator()],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
List<String> data = snapshot.data!;
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
title: Text('Offline tracks'.i18n),
|
|
|
|
leading: const Icon(Icons.audiotrack),
|
|
|
|
trailing: Text(data[0]),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('Offline albums'.i18n),
|
|
|
|
leading: const Icon(Icons.album),
|
|
|
|
trailing: Text(data[1]),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('Offline playlists'.i18n),
|
|
|
|
leading: const Icon(Icons.playlist_add),
|
|
|
|
trailing: Text(data[2]),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('Offline size'.i18n),
|
|
|
|
leading: const Icon(Icons.sd_card),
|
|
|
|
trailing: Text(data[3]),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('Free space'.i18n),
|
|
|
|
leading: const Icon(Icons.disc_full),
|
|
|
|
trailing: Text(data[4]),
|
|
|
|
),
|
|
|
|
],
|
2023-07-29 02:17:26 +00:00
|
|
|
);
|
2023-10-16 22:22:50 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
2023-07-29 02:17:26 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibraryTracks extends StatefulWidget {
|
2023-10-12 22:09:37 +00:00
|
|
|
const LibraryTracks({super.key});
|
2023-10-08 10:53:22 +00:00
|
|
|
|
2023-07-29 02:17:26 +00:00
|
|
|
@override
|
2023-10-12 22:09:37 +00:00
|
|
|
State<LibraryTracks> createState() => _LibraryTracksState();
|
2023-07-29 02:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _LibraryTracksState extends State<LibraryTracks> {
|
|
|
|
bool _loading = false;
|
|
|
|
bool _loadingTracks = false;
|
2023-10-12 22:09:37 +00:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
2023-07-29 02:17:26 +00:00
|
|
|
List<Track> tracks = [];
|
2024-01-24 17:55:25 +00:00
|
|
|
List<Track> allTracks = [];
|
2023-07-29 02:17:26 +00:00
|
|
|
int? trackCount;
|
|
|
|
Sorting? _sort = Sorting(sourceType: SortSourceTypes.TRACKS);
|
|
|
|
|
|
|
|
Playlist get _playlist => Playlist(id: deezerAPI.favoritesPlaylistId!);
|
|
|
|
|
|
|
|
List<Track> get _sorted {
|
|
|
|
List<Track> tcopy = List.from(tracks);
|
|
|
|
tcopy.sort((a, b) => a.addedDate!.compareTo(b.addedDate!));
|
|
|
|
switch (_sort!.type) {
|
|
|
|
case SortType.ALPHABETIC:
|
|
|
|
tcopy.sort((a, b) => a.title!.compareTo(b.title!));
|
|
|
|
break;
|
|
|
|
case SortType.ARTIST:
|
|
|
|
tcopy.sort((a, b) => a.artists![0].name!
|
|
|
|
.toLowerCase()
|
|
|
|
.compareTo(b.artists![0].name!.toLowerCase()));
|
|
|
|
break;
|
|
|
|
case SortType.DEFAULT:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//Reverse
|
|
|
|
if (_sort!.reverse!) return tcopy.reversed.toList();
|
|
|
|
return tcopy;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _reverse() async {
|
|
|
|
setState(() => _sort!.reverse = !_sort!.reverse!);
|
|
|
|
//Save sorting in cache
|
|
|
|
int? index = Sorting.index(SortSourceTypes.TRACKS);
|
|
|
|
if (index != null) {
|
|
|
|
cache.sorts[index] = _sort;
|
|
|
|
} else {
|
|
|
|
cache.sorts.add(_sort);
|
|
|
|
}
|
|
|
|
await cache.save();
|
|
|
|
|
|
|
|
//Preload for sorting
|
|
|
|
if (tracks.length < (trackCount ?? 0)) _loadFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _load() async {
|
|
|
|
//Already loaded
|
|
|
|
if (trackCount != null && tracks.length >= trackCount!) {
|
|
|
|
//Update tracks cache if fully loaded
|
2023-10-12 22:09:37 +00:00
|
|
|
if (cache.libraryTracks.length != trackCount) {
|
|
|
|
cache.libraryTracks = tracks.map((t) => t.id).toList();
|
2023-07-29 02:17:26 +00:00
|
|
|
await cache.save();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectivityResult connectivity = await Connectivity().checkConnectivity();
|
|
|
|
if (connectivity != ConnectivityResult.none) {
|
|
|
|
setState(() => _loading = true);
|
|
|
|
int pos = tracks.length;
|
|
|
|
|
|
|
|
if (trackCount == null || tracks.isEmpty) {
|
|
|
|
//Load tracks as a playlist
|
|
|
|
Playlist? favPlaylist;
|
|
|
|
try {
|
|
|
|
favPlaylist = await deezerAPI.playlist(deezerAPI.favoritesPlaylistId);
|
|
|
|
} catch (e) {}
|
|
|
|
//Error loading
|
|
|
|
if (favPlaylist == null) {
|
|
|
|
setState(() => _loading = false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//Update
|
2023-10-12 22:09:37 +00:00
|
|
|
if (mounted) {
|
2023-07-29 02:17:26 +00:00
|
|
|
setState(() {
|
|
|
|
trackCount = favPlaylist!.trackCount;
|
2023-10-12 22:09:37 +00:00
|
|
|
if (tracks.isEmpty && favPlaylist.tracks != null) {
|
2023-07-29 02:17:26 +00:00
|
|
|
tracks = favPlaylist.tracks!;
|
2023-10-12 22:09:37 +00:00
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
_makeFavorite();
|
|
|
|
_loading = false;
|
|
|
|
});
|
2023-10-12 22:09:37 +00:00
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Load another page of tracks from deezer
|
|
|
|
if (_loadingTracks) return;
|
|
|
|
_loadingTracks = true;
|
|
|
|
|
2023-10-12 22:09:37 +00:00
|
|
|
List<Track>? t;
|
2023-07-29 02:17:26 +00:00
|
|
|
try {
|
2023-10-12 22:09:37 +00:00
|
|
|
t = await deezerAPI.playlistTracksPage(
|
2023-07-29 02:17:26 +00:00
|
|
|
deezerAPI.favoritesPlaylistId, pos);
|
|
|
|
} catch (e) {}
|
|
|
|
//On error load offline
|
2023-10-12 22:09:37 +00:00
|
|
|
if (t == null) {
|
2023-07-29 02:17:26 +00:00
|
|
|
await _loadOffline();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setState(() {
|
2023-10-12 22:09:37 +00:00
|
|
|
tracks.addAll(t!);
|
2023-07-29 02:17:26 +00:00
|
|
|
_makeFavorite();
|
|
|
|
_loading = false;
|
|
|
|
_loadingTracks = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Load all tracks
|
|
|
|
Future _loadFull() async {
|
|
|
|
if (tracks.isEmpty || tracks.length < (trackCount ?? 0)) {
|
|
|
|
Playlist? p;
|
|
|
|
try {
|
|
|
|
p = await deezerAPI.fullPlaylist(deezerAPI.favoritesPlaylistId);
|
|
|
|
} catch (e) {}
|
|
|
|
if (p != null) {
|
|
|
|
setState(() {
|
|
|
|
tracks.addAll(p!.tracks!);
|
|
|
|
trackCount = p.trackCount;
|
|
|
|
_sort = _sort;
|
|
|
|
});
|
2023-10-12 22:09:37 +00:00
|
|
|
|
|
|
|
if (cache.libraryTracks.length != trackCount) {
|
|
|
|
cache.libraryTracks = tracks.map((t) => t.id).toList();
|
|
|
|
await cache.save();
|
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _loadOffline() async {
|
|
|
|
if (deezerAPI.favoritesPlaylistId == null) return;
|
|
|
|
Playlist? p =
|
|
|
|
await downloadManager.getPlaylistFromId(deezerAPI.favoritesPlaylistId!);
|
2023-10-12 22:09:37 +00:00
|
|
|
if (p != null) {
|
2023-07-29 02:17:26 +00:00
|
|
|
setState(() {
|
|
|
|
tracks.addAll(p.tracks!);
|
|
|
|
});
|
2023-10-12 22:09:37 +00:00
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future _loadAllOffline() async {
|
2024-01-24 17:55:25 +00:00
|
|
|
List<Track> tracks = await downloadManager.allOfflineTracks();
|
2023-07-29 02:17:26 +00:00
|
|
|
setState(() {
|
|
|
|
allTracks = tracks;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//Update tracks with favorite true
|
|
|
|
void _makeFavorite() {
|
2023-10-12 22:09:37 +00:00
|
|
|
for (int i = 0; i < tracks.length; i++) {
|
|
|
|
tracks[i].favorite = true;
|
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_scrollController.addListener(() {
|
|
|
|
//Load more tracks on scroll
|
|
|
|
double off = _scrollController.position.maxScrollExtent * 0.90;
|
|
|
|
if (_scrollController.position.pixels > off) _load();
|
|
|
|
});
|
|
|
|
|
|
|
|
_load();
|
|
|
|
//Load all offline tracks
|
|
|
|
_loadAllOffline();
|
|
|
|
|
|
|
|
//Load sorting
|
|
|
|
int? index = Sorting.index(SortSourceTypes.TRACKS);
|
|
|
|
if (index != null) setState(() => _sort = cache.sorts[index]);
|
|
|
|
|
|
|
|
if (_sort!.type != SortType.DEFAULT || _sort!.reverse!) _loadFull();
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('Tracks'.i18n),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
_sort!.reverse!
|
|
|
|
? FontAwesome5.sort_alpha_up
|
|
|
|
: FontAwesome5.sort_alpha_down,
|
|
|
|
semanticLabel: _sort!.reverse!
|
|
|
|
? "Sort descending".i18n
|
|
|
|
: "Sort ascending".i18n,
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
await _reverse();
|
|
|
|
}),
|
|
|
|
PopupMenuButton(
|
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
onSelected: (SortType s) async {
|
|
|
|
//Preload for sorting
|
|
|
|
if (tracks.length < (trackCount ?? 0)) await _loadFull();
|
|
|
|
|
|
|
|
setState(() => _sort!.type = s);
|
|
|
|
//Save sorting in cache
|
|
|
|
int? index = Sorting.index(SortSourceTypes.TRACKS);
|
|
|
|
if (index != null) {
|
|
|
|
cache.sorts[index] = _sort;
|
|
|
|
} else {
|
|
|
|
cache.sorts.add(_sort);
|
|
|
|
}
|
|
|
|
await cache.save();
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => <PopupMenuEntry<SortType>>[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.DEFAULT,
|
|
|
|
child: Text('Default'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.ALPHABETIC,
|
|
|
|
child: Text('Alphabetic'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.ARTIST,
|
|
|
|
child: Text('Artist'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
],
|
2023-10-12 22:09:37 +00:00
|
|
|
child: Icon(
|
|
|
|
Icons.sort,
|
|
|
|
size: 32.0,
|
|
|
|
semanticLabel: "Sort".i18n,
|
|
|
|
),
|
2023-07-29 02:17:26 +00:00
|
|
|
),
|
|
|
|
const SizedBox(width: 8.0),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: _loading && allTracks.isEmpty
|
|
|
|
? const Center(child: CircularProgressIndicator())
|
2023-10-24 22:32:28 +00:00
|
|
|
: Scrollbar(
|
|
|
|
interactive: true,
|
2023-07-29 02:17:26 +00:00
|
|
|
controller: _scrollController,
|
2023-10-24 22:32:28 +00:00
|
|
|
thickness: 8.0,
|
2023-07-29 02:17:26 +00:00
|
|
|
child: ListView(
|
|
|
|
controller: _scrollController,
|
|
|
|
children: <Widget>[
|
|
|
|
if (!_loading)
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
children: <Widget>[
|
|
|
|
MakePlaylistOffline(_playlist),
|
|
|
|
TextButton.icon(
|
2023-10-12 22:09:37 +00:00
|
|
|
icon: const Icon(Icons.file_download),
|
2023-07-29 02:17:26 +00:00
|
|
|
label: Text('Download'.i18n),
|
|
|
|
onPressed: () async {
|
|
|
|
if (await downloadManager.addOfflinePlaylist(
|
|
|
|
_playlist,
|
|
|
|
private: false,
|
|
|
|
context: context) !=
|
2023-10-12 22:09:37 +00:00
|
|
|
false) {
|
2023-07-29 02:17:26 +00:00
|
|
|
MenuSheet(context).showDownloadStartedToast();
|
2023-10-12 22:09:37 +00:00
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
]),
|
2023-10-12 22:09:37 +00:00
|
|
|
const FreezerDivider(),
|
2023-07-29 02:17:26 +00:00
|
|
|
//Loved tracks
|
|
|
|
if (_loading)
|
|
|
|
const Center(child: CircularProgressIndicator()),
|
|
|
|
...List.generate(tracks.length, (i) {
|
|
|
|
Track? t = (tracks.length == (trackCount ?? 0))
|
|
|
|
? _sorted[i]
|
|
|
|
: tracks[i];
|
2023-10-16 22:22:50 +00:00
|
|
|
return TrackTile.fromTrack(
|
2023-07-29 02:17:26 +00:00
|
|
|
t,
|
|
|
|
onTap: () {
|
|
|
|
playerHelper.playFromTrackList(
|
|
|
|
(tracks.length == (trackCount ?? 0))
|
|
|
|
? _sorted
|
|
|
|
: tracks,
|
|
|
|
t.id,
|
|
|
|
QueueSource(
|
|
|
|
id: deezerAPI.favoritesPlaylistId,
|
|
|
|
text: 'Favorites'.i18n,
|
|
|
|
source: 'playlist'));
|
|
|
|
},
|
2023-10-16 22:22:50 +00:00
|
|
|
onSecondary: (details) {
|
2023-07-29 02:17:26 +00:00
|
|
|
MenuSheet m = MenuSheet(context);
|
2023-10-16 22:22:50 +00:00
|
|
|
m.defaultTrackMenu(t, details: details, onRemove: () {
|
2023-07-29 02:17:26 +00:00
|
|
|
setState(() {
|
|
|
|
tracks.removeWhere((track) => t.id == track.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
2023-10-12 22:09:37 +00:00
|
|
|
const FreezerDivider(),
|
2023-07-29 02:17:26 +00:00
|
|
|
Text(
|
|
|
|
'All offline tracks'.i18n,
|
|
|
|
textAlign: TextAlign.center,
|
2023-10-12 22:09:37 +00:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 24, fontWeight: FontWeight.bold),
|
2023-07-29 02:17:26 +00:00
|
|
|
),
|
|
|
|
const SizedBox(height: 8.0),
|
|
|
|
for (final track in allTracks)
|
2023-10-16 22:22:50 +00:00
|
|
|
TrackTile.fromTrack(track!, onTap: () {
|
2023-07-29 02:17:26 +00:00
|
|
|
playerHelper.playFromTrackList(
|
|
|
|
allTracks,
|
|
|
|
track.id,
|
|
|
|
QueueSource(
|
|
|
|
id: 'allTracks',
|
|
|
|
text: 'All offline tracks'.i18n,
|
|
|
|
source: 'offline'));
|
2023-10-16 22:22:50 +00:00
|
|
|
}, onSecondary: (details) {
|
|
|
|
MenuSheet(context)
|
|
|
|
.defaultTrackMenu(track, details: details);
|
2023-07-29 02:17:26 +00:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibraryAlbums extends StatefulWidget {
|
2023-10-12 22:09:37 +00:00
|
|
|
const LibraryAlbums({super.key});
|
2023-10-08 10:53:22 +00:00
|
|
|
|
2023-07-29 02:17:26 +00:00
|
|
|
@override
|
2023-10-12 22:09:37 +00:00
|
|
|
State<LibraryAlbums> createState() => _LibraryAlbumsState();
|
2023-07-29 02:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _LibraryAlbumsState extends State<LibraryAlbums> {
|
|
|
|
List<Album>? _albums;
|
|
|
|
Sorting? _sort = Sorting(sourceType: SortSourceTypes.ALBUMS);
|
2023-10-12 22:09:37 +00:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
2023-07-29 02:17:26 +00:00
|
|
|
|
|
|
|
List<Album> get _sorted {
|
|
|
|
List<Album> albums = List.from(_albums!);
|
|
|
|
albums.sort((a, b) => a.favoriteDate!.compareTo(b.favoriteDate!));
|
|
|
|
switch (_sort!.type) {
|
|
|
|
case SortType.DEFAULT:
|
|
|
|
break;
|
|
|
|
case SortType.ALPHABETIC:
|
|
|
|
albums.sort(
|
|
|
|
(a, b) => a.title!.toLowerCase().compareTo(b.title!.toLowerCase()));
|
|
|
|
break;
|
|
|
|
case SortType.ARTIST:
|
|
|
|
albums.sort((a, b) => a.artists![0].name!
|
|
|
|
.toLowerCase()
|
|
|
|
.compareTo(b.artists![0].name!.toLowerCase()));
|
|
|
|
break;
|
|
|
|
case SortType.RELEASE_DATE:
|
|
|
|
albums.sort((a, b) => DateTime.parse(a.releaseDate!)
|
|
|
|
.compareTo(DateTime.parse(b.releaseDate!)));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//Reverse
|
|
|
|
if (_sort!.reverse!) return albums.reversed.toList();
|
|
|
|
return albums;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _load() async {
|
|
|
|
if (settings.offlineMode) return;
|
|
|
|
try {
|
|
|
|
List<Album> albums = await deezerAPI.getAlbums();
|
|
|
|
setState(() => _albums = albums);
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_load();
|
|
|
|
//Load sorting
|
|
|
|
int? index = Sorting.index(SortSourceTypes.ALBUMS);
|
|
|
|
if (index != null) _sort = cache.sorts[index];
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _reverse() async {
|
|
|
|
setState(() => _sort!.reverse = !_sort!.reverse!);
|
|
|
|
//Save sorting in cache
|
|
|
|
int? index = Sorting.index(SortSourceTypes.ALBUMS);
|
|
|
|
if (index != null) {
|
|
|
|
cache.sorts[index] = _sort;
|
|
|
|
} else {
|
|
|
|
cache.sorts.add(_sort);
|
|
|
|
}
|
|
|
|
await cache.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('Albums'.i18n),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
_sort!.reverse!
|
|
|
|
? FontAwesome5.sort_alpha_up
|
|
|
|
: FontAwesome5.sort_alpha_down,
|
|
|
|
semanticLabel: _sort!.reverse!
|
|
|
|
? "Sort descending".i18n
|
|
|
|
: "Sort ascending".i18n,
|
|
|
|
),
|
|
|
|
onPressed: () => _reverse(),
|
|
|
|
),
|
|
|
|
PopupMenuButton(
|
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
2023-10-12 22:09:37 +00:00
|
|
|
child: const Icon(Icons.sort, size: 32.0),
|
2023-07-29 02:17:26 +00:00
|
|
|
onSelected: (SortType s) async {
|
|
|
|
setState(() => _sort!.type = s);
|
|
|
|
//Save to cache
|
|
|
|
int? index = Sorting.index(SortSourceTypes.ALBUMS);
|
|
|
|
if (index == null) {
|
|
|
|
cache.sorts.add(_sort);
|
|
|
|
} else {
|
|
|
|
cache.sorts[index] = _sort;
|
|
|
|
}
|
|
|
|
await cache.save();
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => <PopupMenuEntry<SortType>>[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.DEFAULT,
|
|
|
|
child: Text('Default'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.ALPHABETIC,
|
|
|
|
child: Text('Alphabetic'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.ARTIST,
|
|
|
|
child: Text('Artist'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.RELEASE_DATE,
|
|
|
|
child: Text('Release date'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(width: 8.0),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: !settings.offlineMode && _albums == null
|
|
|
|
? const Center(child: CircularProgressIndicator())
|
2023-10-24 22:32:28 +00:00
|
|
|
: Scrollbar(
|
|
|
|
interactive: true,
|
2023-07-29 02:17:26 +00:00
|
|
|
controller: _scrollController,
|
2023-10-24 22:32:28 +00:00
|
|
|
thickness: 8.0,
|
2023-07-29 02:17:26 +00:00
|
|
|
child: ListView(
|
|
|
|
controller: _scrollController,
|
|
|
|
children: <Widget>[
|
|
|
|
const SizedBox(height: 8.0),
|
|
|
|
if (_albums != null)
|
|
|
|
...List.generate(_albums!.length, (int i) {
|
|
|
|
Album a = _sorted[i];
|
|
|
|
return AlbumTile(
|
|
|
|
a,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pushRoute(
|
|
|
|
builder: (context) => AlbumDetails(a));
|
|
|
|
},
|
2023-10-16 22:22:50 +00:00
|
|
|
onSecondary: (details) {
|
2023-07-29 02:17:26 +00:00
|
|
|
MenuSheet m = MenuSheet(context);
|
2023-10-16 22:22:50 +00:00
|
|
|
m.defaultAlbumMenu(
|
|
|
|
a,
|
|
|
|
details: details,
|
|
|
|
onRemove: () {
|
|
|
|
setState(() => _albums!.remove(a));
|
|
|
|
},
|
|
|
|
);
|
2023-07-29 02:17:26 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
FutureBuilder(
|
|
|
|
future: downloadManager.getOfflineAlbums(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasError ||
|
|
|
|
!snapshot.hasData ||
|
2023-10-12 22:09:37 +00:00
|
|
|
(snapshot.data!).isEmpty) {
|
|
|
|
return const SizedBox(
|
2023-07-29 02:17:26 +00:00
|
|
|
height: 0,
|
|
|
|
width: 0,
|
|
|
|
);
|
2023-10-12 22:09:37 +00:00
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
|
|
|
|
List<Album> albums = snapshot.data as List<Album>;
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
2023-10-12 22:09:37 +00:00
|
|
|
const FreezerDivider(),
|
2023-07-29 02:17:26 +00:00
|
|
|
Text(
|
|
|
|
'Offline albums'.i18n,
|
|
|
|
textAlign: TextAlign.center,
|
2023-10-12 22:09:37 +00:00
|
|
|
style: const TextStyle(
|
2023-07-29 02:17:26 +00:00
|
|
|
fontWeight: FontWeight.bold, fontSize: 24.0),
|
|
|
|
),
|
|
|
|
...List.generate(albums.length, (i) {
|
|
|
|
Album a = albums[i];
|
|
|
|
return AlbumTile(
|
|
|
|
a,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pushRoute(
|
|
|
|
builder: (context) => AlbumDetails(a));
|
|
|
|
},
|
2023-10-16 22:22:50 +00:00
|
|
|
onSecondary: (details) {
|
2023-07-29 02:17:26 +00:00
|
|
|
MenuSheet m = MenuSheet(context);
|
2023-10-16 22:22:50 +00:00
|
|
|
m.defaultAlbumMenu(a, details: details,
|
|
|
|
onRemove: () {
|
2023-07-29 02:17:26 +00:00
|
|
|
setState(() {
|
|
|
|
albums.remove(a);
|
|
|
|
_albums!.remove(a);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibraryArtists extends StatefulWidget {
|
2023-10-12 22:09:37 +00:00
|
|
|
const LibraryArtists({super.key});
|
2023-10-08 10:53:22 +00:00
|
|
|
|
2023-07-29 02:17:26 +00:00
|
|
|
@override
|
2023-10-12 22:09:37 +00:00
|
|
|
State<LibraryArtists> createState() => _LibraryArtistsState();
|
2023-07-29 02:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _LibraryArtistsState extends State<LibraryArtists> {
|
|
|
|
late List<Artist> _artists;
|
|
|
|
Sorting? _sort = Sorting(sourceType: SortSourceTypes.ARTISTS);
|
|
|
|
bool _loading = true;
|
|
|
|
bool _error = false;
|
2023-10-12 22:09:37 +00:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
2023-07-29 02:17:26 +00:00
|
|
|
|
|
|
|
List<Artist> get _sorted {
|
|
|
|
List<Artist> artists = List.from(_artists);
|
|
|
|
artists.sort((a, b) => a.favoriteDate!.compareTo(b.favoriteDate!));
|
|
|
|
switch (_sort!.type) {
|
|
|
|
case SortType.DEFAULT:
|
|
|
|
break;
|
|
|
|
case SortType.POPULARITY:
|
|
|
|
artists.sort((a, b) => b.fans! - a.fans!);
|
|
|
|
break;
|
|
|
|
case SortType.ALPHABETIC:
|
|
|
|
artists.sort(
|
|
|
|
(a, b) => a.name!.toLowerCase().compareTo(b.name!.toLowerCase()));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//Reverse
|
|
|
|
if (_sort!.reverse!) return artists.reversed.toList();
|
|
|
|
return artists;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Load data
|
|
|
|
Future _load() async {
|
|
|
|
setState(() => _loading = true);
|
|
|
|
//Fetch
|
|
|
|
List<Artist>? data;
|
|
|
|
try {
|
|
|
|
data = await deezerAPI.getArtists();
|
|
|
|
} catch (e) {}
|
|
|
|
//Update UI
|
|
|
|
setState(() {
|
|
|
|
if (data != null) {
|
|
|
|
_artists = data;
|
|
|
|
} else {
|
|
|
|
_error = true;
|
|
|
|
}
|
|
|
|
_loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _reverse() async {
|
|
|
|
setState(() => _sort!.reverse = !_sort!.reverse!);
|
|
|
|
//Save sorting in cache
|
|
|
|
int? index = Sorting.index(SortSourceTypes.ARTISTS);
|
|
|
|
if (index != null) {
|
|
|
|
cache.sorts[index] = _sort;
|
|
|
|
} else {
|
|
|
|
cache.sorts.add(_sort);
|
|
|
|
}
|
|
|
|
await cache.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
//Restore sort
|
|
|
|
int? index = Sorting.index(SortSourceTypes.ARTISTS);
|
|
|
|
if (index != null) _sort = cache.sorts[index];
|
|
|
|
|
|
|
|
_load();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('Artists'.i18n),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
_sort!.reverse!
|
|
|
|
? FontAwesome5.sort_alpha_up
|
|
|
|
: FontAwesome5.sort_alpha_down,
|
|
|
|
semanticLabel: _sort!.reverse!
|
|
|
|
? "Sort descending".i18n
|
|
|
|
: "Sort ascending".i18n,
|
|
|
|
),
|
|
|
|
onPressed: () => _reverse(),
|
|
|
|
),
|
|
|
|
PopupMenuButton(
|
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
onSelected: (SortType s) async {
|
|
|
|
setState(() => _sort!.type = s);
|
|
|
|
//Save
|
|
|
|
int? index = Sorting.index(SortSourceTypes.ARTISTS);
|
|
|
|
if (index == null) {
|
|
|
|
cache.sorts.add(_sort);
|
|
|
|
} else {
|
|
|
|
cache.sorts[index] = _sort;
|
|
|
|
}
|
|
|
|
await cache.save();
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => <PopupMenuEntry<SortType>>[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.DEFAULT,
|
|
|
|
child: Text('Default'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.ALPHABETIC,
|
|
|
|
child: Text('Alphabetic'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.POPULARITY,
|
|
|
|
child: Text('Popularity'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
],
|
2023-10-12 22:09:37 +00:00
|
|
|
child: const Icon(Icons.sort, size: 32.0),
|
2023-07-29 02:17:26 +00:00
|
|
|
),
|
|
|
|
const SizedBox(width: 8.0),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: _loading
|
|
|
|
? const Center(child: CircularProgressIndicator())
|
|
|
|
: _error
|
|
|
|
? const Center(child: ErrorScreen())
|
2023-10-24 22:32:28 +00:00
|
|
|
: Scrollbar(
|
|
|
|
interactive: true,
|
2023-07-29 02:17:26 +00:00
|
|
|
controller: _scrollController,
|
2023-10-24 22:32:28 +00:00
|
|
|
thickness: 8.0,
|
2023-07-29 02:17:26 +00:00
|
|
|
child: ListView(
|
|
|
|
controller: _scrollController,
|
|
|
|
children: <Widget>[
|
|
|
|
for (final artist in _sorted)
|
|
|
|
ArtistHorizontalTile(
|
|
|
|
artist,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pushRoute(
|
|
|
|
builder: (context) => ArtistDetails(artist));
|
|
|
|
},
|
|
|
|
onHold: () {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
m.defaultArtistMenu(artist, onRemove: () {
|
|
|
|
setState(() {
|
|
|
|
_artists.remove(artist);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibraryPlaylists extends StatefulWidget {
|
2023-10-12 22:09:37 +00:00
|
|
|
const LibraryPlaylists({super.key});
|
2023-10-08 10:53:22 +00:00
|
|
|
|
2023-07-29 02:17:26 +00:00
|
|
|
@override
|
2023-10-12 22:09:37 +00:00
|
|
|
State<LibraryPlaylists> createState() => _LibraryPlaylistsState();
|
2023-07-29 02:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _LibraryPlaylistsState extends State<LibraryPlaylists> {
|
|
|
|
List<Playlist>? _playlists;
|
|
|
|
Sorting? _sort = Sorting(sourceType: SortSourceTypes.PLAYLISTS);
|
2023-10-12 22:09:37 +00:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
2023-07-29 02:17:26 +00:00
|
|
|
String _filter = '';
|
|
|
|
|
|
|
|
List<Playlist> get _sorted {
|
|
|
|
List<Playlist> playlists = List.from(_playlists!
|
|
|
|
.where((p) => p.title!.toLowerCase().contains(_filter.toLowerCase())));
|
|
|
|
switch (_sort!.type) {
|
|
|
|
case SortType.DEFAULT:
|
|
|
|
break;
|
|
|
|
case SortType.USER:
|
|
|
|
playlists.sort((a, b) => (a.user!.name ?? deezerAPI.userName)!
|
|
|
|
.toLowerCase()
|
|
|
|
.compareTo((b.user!.name ?? deezerAPI.userName)!.toLowerCase()));
|
|
|
|
break;
|
|
|
|
case SortType.TRACK_COUNT:
|
|
|
|
playlists.sort((a, b) => b.trackCount! - a.trackCount!);
|
|
|
|
break;
|
|
|
|
case SortType.ALPHABETIC:
|
|
|
|
playlists.sort(
|
|
|
|
(a, b) => a.title!.toLowerCase().compareTo(b.title!.toLowerCase()));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (_sort!.reverse!) return playlists.reversed.toList();
|
|
|
|
return playlists;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _load() async {
|
2024-01-24 17:55:25 +00:00
|
|
|
if (cache.favoritePlaylists != null) {
|
|
|
|
setState(() => _playlists =
|
|
|
|
cache.favoritePlaylists!.value.values.toList(growable: false));
|
|
|
|
|
|
|
|
if (DateTime.now().difference(cache.favoritePlaylists!.updatedAt) <
|
|
|
|
const Duration(hours: 1)) return;
|
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
if (!settings.offlineMode) {
|
|
|
|
try {
|
2023-10-12 22:09:37 +00:00
|
|
|
final List<Playlist> playlists = await deezerAPI.getPlaylists();
|
2023-07-29 02:17:26 +00:00
|
|
|
setState(() => _playlists = playlists);
|
2024-01-24 17:55:25 +00:00
|
|
|
if (cache.favoritePlaylists == null) {
|
|
|
|
cache.favoritePlaylists =
|
|
|
|
CacheEntry({for (final p in playlists) p.id: p});
|
|
|
|
} else {
|
|
|
|
// update non-destructively
|
|
|
|
final oldEntry = cache.favoritePlaylists!.value;
|
|
|
|
final newEntry = <String, Playlist>{};
|
|
|
|
for (final playlist in playlists) {
|
|
|
|
if (oldEntry.containsKey(playlist.id)) {
|
|
|
|
newEntry[playlist.id] = oldEntry[playlist.id]!;
|
|
|
|
} else {
|
|
|
|
newEntry[playlist.id] = playlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await cache.save();
|
2023-10-12 22:09:37 +00:00
|
|
|
return;
|
2023-07-29 02:17:26 +00:00
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _reverse() async {
|
|
|
|
setState(() => _sort!.reverse = !_sort!.reverse!);
|
|
|
|
//Save sorting in cache
|
|
|
|
int? index = Sorting.index(SortSourceTypes.PLAYLISTS);
|
|
|
|
if (index != null) {
|
|
|
|
cache.sorts[index] = _sort;
|
|
|
|
} else {
|
|
|
|
cache.sorts.add(_sort);
|
|
|
|
}
|
|
|
|
await cache.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
//Restore sort
|
|
|
|
int? index = Sorting.index(SortSourceTypes.PLAYLISTS);
|
|
|
|
if (index != null) _sort = cache.sorts[index];
|
|
|
|
|
|
|
|
_load();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
Playlist get favoritesPlaylist => Playlist(
|
|
|
|
id: deezerAPI.favoritesPlaylistId!,
|
|
|
|
title: 'Favorites'.i18n,
|
|
|
|
user: User(name: deezerAPI.userName),
|
2023-09-26 00:06:59 +00:00
|
|
|
image: UrlImageDetails.single('assets/favorites_thumb.jpg'),
|
2023-07-29 02:17:26 +00:00
|
|
|
tracks: [],
|
|
|
|
trackCount: 1,
|
2023-10-12 22:09:37 +00:00
|
|
|
duration: const Duration(seconds: 0));
|
2023-07-29 02:17:26 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('Playlists'.i18n),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
_sort!.reverse!
|
|
|
|
? FontAwesome5.sort_alpha_up
|
|
|
|
: FontAwesome5.sort_alpha_down,
|
|
|
|
semanticLabel: _sort!.reverse!
|
|
|
|
? "Sort descending".i18n
|
|
|
|
: "Sort ascending".i18n,
|
|
|
|
),
|
|
|
|
onPressed: () => _reverse(),
|
|
|
|
),
|
|
|
|
PopupMenuButton(
|
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
onSelected: (SortType s) async {
|
|
|
|
setState(() => _sort!.type = s);
|
|
|
|
//Save to cache
|
|
|
|
int? index = Sorting.index(SortSourceTypes.PLAYLISTS);
|
2023-10-12 22:09:37 +00:00
|
|
|
if (index == null) {
|
2023-07-29 02:17:26 +00:00
|
|
|
cache.sorts.add(_sort);
|
2023-10-12 22:09:37 +00:00
|
|
|
} else {
|
2023-07-29 02:17:26 +00:00
|
|
|
cache.sorts[index] = _sort;
|
2023-10-12 22:09:37 +00:00
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
|
|
|
|
await cache.save();
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => <PopupMenuEntry<SortType>>[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.DEFAULT,
|
|
|
|
child: Text('Default'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.USER,
|
|
|
|
child: Text('User'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.TRACK_COUNT,
|
|
|
|
child: Text('Track count'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.ALPHABETIC,
|
|
|
|
child: Text('Alphabetic'.i18n, style: popupMenuTextStyle()),
|
|
|
|
),
|
|
|
|
],
|
2023-10-12 22:09:37 +00:00
|
|
|
child: const Icon(Icons.sort, size: 32.0),
|
2023-07-29 02:17:26 +00:00
|
|
|
),
|
|
|
|
Container(width: 8.0),
|
|
|
|
],
|
|
|
|
),
|
2023-10-24 22:32:28 +00:00
|
|
|
body: Scrollbar(
|
|
|
|
interactive: true,
|
2023-07-29 02:17:26 +00:00
|
|
|
controller: _scrollController,
|
2023-10-24 22:32:28 +00:00
|
|
|
thickness: 8.0,
|
2023-07-29 02:17:26 +00:00
|
|
|
child: ListView(
|
|
|
|
controller: _scrollController,
|
|
|
|
children: <Widget>[
|
|
|
|
//Search
|
|
|
|
Padding(
|
2023-10-12 22:09:37 +00:00
|
|
|
padding: const EdgeInsets.all(8.0),
|
2023-07-29 02:17:26 +00:00
|
|
|
child: TextField(
|
|
|
|
onChanged: (String s) => setState(() => _filter = s),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'Search'.i18n,
|
|
|
|
filled: true,
|
|
|
|
focusedBorder: const OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: Colors.grey)),
|
|
|
|
enabledBorder: const OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(color: Colors.grey)),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('Create new playlist'.i18n),
|
2023-10-12 22:09:37 +00:00
|
|
|
leading: const LeadingIcon(Icons.playlist_add,
|
|
|
|
color: Color(0xff009a85)),
|
2023-07-29 02:17:26 +00:00
|
|
|
onTap: () async {
|
|
|
|
if (settings.offlineMode) {
|
|
|
|
ScaffoldMessenger.of(context)
|
|
|
|
.snack('Cannot create playlists in offline mode'.i18n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
await m.createPlaylist();
|
|
|
|
await _load();
|
|
|
|
},
|
|
|
|
),
|
2023-10-12 22:09:37 +00:00
|
|
|
const FreezerDivider(),
|
2023-07-29 02:17:26 +00:00
|
|
|
|
|
|
|
if (!settings.offlineMode && _playlists == null)
|
2023-10-12 22:09:37 +00:00
|
|
|
const Row(
|
2023-07-29 02:17:26 +00:00
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
CircularProgressIndicator(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
|
|
|
|
//Favorites playlist
|
|
|
|
PlaylistTile(
|
|
|
|
favoritesPlaylist,
|
|
|
|
onTap: () async {
|
|
|
|
Navigator.of(context).pushRoute(
|
|
|
|
builder: (context) => PlaylistDetails(favoritesPlaylist));
|
|
|
|
},
|
2023-10-16 22:22:50 +00:00
|
|
|
onSecondary: (details) {
|
2023-07-29 02:17:26 +00:00
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
favoritesPlaylist.library = true;
|
2023-10-16 22:22:50 +00:00
|
|
|
m.defaultPlaylistMenu(favoritesPlaylist, details: details);
|
2023-07-29 02:17:26 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
if (_playlists != null)
|
|
|
|
...List.generate(_sorted.length, (int i) {
|
|
|
|
Playlist p = _sorted[i];
|
|
|
|
return PlaylistTile(
|
|
|
|
p,
|
|
|
|
onTap: () => Navigator.of(context)
|
|
|
|
.pushRoute(builder: (context) => PlaylistDetails(p)),
|
2023-10-16 22:22:50 +00:00
|
|
|
onSecondary: (details) {
|
2023-07-29 02:17:26 +00:00
|
|
|
MenuSheet m = MenuSheet(context);
|
2023-10-16 22:22:50 +00:00
|
|
|
m.defaultPlaylistMenu(p, details: details, onRemove: () {
|
2023-07-29 02:17:26 +00:00
|
|
|
setState(() => _playlists!.remove(p));
|
|
|
|
}, onUpdate: () {
|
|
|
|
_load();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
|
|
|
|
FutureBuilder(
|
|
|
|
future: downloadManager.getOfflinePlaylists(),
|
|
|
|
builder: (context, AsyncSnapshot<List<Playlist>> snapshot) {
|
|
|
|
if (snapshot.hasError ||
|
|
|
|
!snapshot.hasData ||
|
2023-10-12 22:09:37 +00:00
|
|
|
snapshot.data!.isEmpty) {
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
}
|
2023-07-29 02:17:26 +00:00
|
|
|
|
|
|
|
List<Playlist> playlists = snapshot.data!;
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
2023-10-12 22:09:37 +00:00
|
|
|
const FreezerDivider(),
|
2023-07-29 02:17:26 +00:00
|
|
|
Text(
|
|
|
|
'Offline playlists'.i18n,
|
|
|
|
textAlign: TextAlign.center,
|
2023-10-12 22:09:37 +00:00
|
|
|
style: const TextStyle(
|
2023-07-29 02:17:26 +00:00
|
|
|
fontSize: 24.0, fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
...List.generate(playlists.length, (i) {
|
|
|
|
Playlist p = playlists[i];
|
|
|
|
return PlaylistTile(
|
|
|
|
p,
|
|
|
|
onTap: () => Navigator.of(context).pushRoute(
|
|
|
|
builder: (context) => PlaylistDetails(p)),
|
2023-10-16 22:22:50 +00:00
|
|
|
onSecondary: (details) {
|
2023-07-29 02:17:26 +00:00
|
|
|
MenuSheet m = MenuSheet(context);
|
2023-10-16 22:22:50 +00:00
|
|
|
m.defaultPlaylistMenu(p, details: details,
|
|
|
|
onRemove: () {
|
2023-07-29 02:17:26 +00:00
|
|
|
setState(() {
|
|
|
|
playlists.remove(p);
|
|
|
|
_playlists!.remove(p);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class HistoryScreen extends StatefulWidget {
|
2023-10-12 22:09:37 +00:00
|
|
|
const HistoryScreen({super.key});
|
2023-10-08 10:53:22 +00:00
|
|
|
|
2023-07-29 02:17:26 +00:00
|
|
|
@override
|
2023-10-12 22:09:37 +00:00
|
|
|
State<HistoryScreen> createState() => _HistoryScreenState();
|
2023-07-29 02:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _HistoryScreenState extends State<HistoryScreen> {
|
2023-10-12 22:09:37 +00:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
2023-07-29 02:17:26 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('History'.i18n),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.delete_sweep,
|
|
|
|
semanticLabel: "Clear all".i18n,
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
setState(() => cache.history = []);
|
|
|
|
cache.save();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2023-10-24 22:32:28 +00:00
|
|
|
body: Scrollbar(
|
|
|
|
interactive: true,
|
2023-07-29 02:17:26 +00:00
|
|
|
controller: _scrollController,
|
2023-10-24 22:32:28 +00:00
|
|
|
thickness: 8.0,
|
2023-07-29 02:17:26 +00:00
|
|
|
child: ListView.builder(
|
|
|
|
controller: _scrollController,
|
|
|
|
itemCount: cache.history.length,
|
|
|
|
itemBuilder: (BuildContext context, int i) {
|
|
|
|
Track t = cache.history[cache.history.length - i - 1];
|
2023-10-16 22:22:50 +00:00
|
|
|
return TrackTile.fromTrack(
|
2023-07-29 02:17:26 +00:00
|
|
|
t,
|
|
|
|
onTap: () {
|
|
|
|
playerHelper.playFromTrackList(
|
|
|
|
cache.history.reversed.toList(),
|
|
|
|
t.id,
|
|
|
|
QueueSource(
|
|
|
|
id: null, text: 'History'.i18n, source: 'history'));
|
|
|
|
},
|
2023-10-16 22:22:50 +00:00
|
|
|
onSecondary: (details) {
|
2023-07-29 02:17:26 +00:00
|
|
|
MenuSheet m = MenuSheet(context);
|
2023-10-16 22:22:50 +00:00
|
|
|
m.defaultTrackMenu(t, details: details);
|
2023-07-29 02:17:26 +00:00
|
|
|
},
|
2023-10-17 14:03:39 +00:00
|
|
|
checkTrackOffline: false,
|
2023-07-29 02:17:26 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|