2020-06-23 21:23:12 +02:00
|
|
|
import 'package:connectivity/connectivity.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2020-10-09 20:52:45 +02:00
|
|
|
import 'package:freezer/api/cache.dart';
|
2020-06-23 21:23:12 +02:00
|
|
|
import 'package:freezer/api/deezer.dart';
|
|
|
|
import 'package:freezer/api/definitions.dart';
|
|
|
|
import 'package:freezer/api/player.dart';
|
|
|
|
import 'package:freezer/settings.dart';
|
|
|
|
import 'package:freezer/ui/details_screens.dart';
|
|
|
|
import 'package:freezer/ui/downloads_screen.dart';
|
2020-10-19 21:28:45 +02:00
|
|
|
import 'package:freezer/ui/elements.dart';
|
2020-06-23 21:23:12 +02:00
|
|
|
import 'package:freezer/ui/error.dart';
|
2020-06-25 14:28:56 +02:00
|
|
|
import 'package:freezer/ui/importer_screen.dart';
|
2020-06-23 21:23:12 +02:00
|
|
|
import 'package:freezer/ui/tiles.dart';
|
2020-09-18 19:36:41 +02:00
|
|
|
import 'package:freezer/translations.i18n.dart';
|
2020-06-23 21:23:12 +02:00
|
|
|
|
|
|
|
import 'menu.dart';
|
|
|
|
import 'settings_screen.dart';
|
2020-06-25 14:28:56 +02:00
|
|
|
import '../api/spotify.dart';
|
2020-06-23 21:23:12 +02:00
|
|
|
import '../api/download.dart';
|
|
|
|
|
|
|
|
class LibraryAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|
|
|
|
|
|
|
@override
|
|
|
|
Size get preferredSize => AppBar().preferredSize;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-10-19 21:28:45 +02:00
|
|
|
return FreezerAppBar(
|
|
|
|
'Library'.i18n,
|
2020-06-23 21:23:12 +02:00
|
|
|
actions: <Widget>[
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.file_download),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => DownloadsScreen())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.settings),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => SettingsScreen())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibraryScreen extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: LibraryAppBar(),
|
|
|
|
body: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(height: 4.0,),
|
2020-10-09 20:52:45 +02:00
|
|
|
if (!downloadManager.running && downloadManager.queueSize > 0)
|
2020-06-23 21:23:12 +02:00
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Downloads'.i18n),
|
2020-10-19 21:28:45 +02:00
|
|
|
leading: LeadingIcon(Icons.file_download, color: Colors.grey),
|
2020-09-18 19:36:41 +02:00
|
|
|
subtitle: Text('Downloading is currently stopped, click here to resume.'.i18n),
|
2020-06-23 21:23:12 +02:00
|
|
|
onTap: () {
|
2020-09-09 20:50:15 +02:00
|
|
|
downloadManager.start();
|
2020-06-23 21:23:12 +02:00
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) => DownloadsScreen()
|
|
|
|
));
|
|
|
|
},
|
|
|
|
),
|
2020-10-19 21:28:45 +02:00
|
|
|
ListTile(
|
|
|
|
title: Text('Shuffle'.i18n),
|
|
|
|
leading: LeadingIcon(Icons.shuffle, color: Color(0xffeca704)),
|
|
|
|
onTap: () async {
|
|
|
|
List<Track> tracks = await deezerAPI.libraryShuffle();
|
|
|
|
playerHelper.playFromTrackList(tracks, tracks[0].id, QueueSource(
|
|
|
|
id: 'libraryshuffle',
|
|
|
|
source: 'libraryshuffle',
|
|
|
|
text: 'Library shuffle'.i18n
|
|
|
|
));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
FreezerDivider(),
|
2020-06-23 21:23:12 +02:00
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Tracks'.i18n),
|
2020-10-19 21:28:45 +02:00
|
|
|
leading: LeadingIcon(Icons.audiotrack, color: Color(0xffbe3266)),
|
2020-06-23 21:23:12 +02:00
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => LibraryTracks())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Albums'.i18n),
|
2020-10-19 21:28:45 +02:00
|
|
|
leading: LeadingIcon(Icons.album, color: Color(0xff4b2e7e)),
|
2020-06-23 21:23:12 +02:00
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => LibraryAlbums())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Artists'.i18n),
|
2020-10-19 21:28:45 +02:00
|
|
|
leading: LeadingIcon(Icons.recent_actors, color: Color(0xff384697)),
|
2020-06-23 21:23:12 +02:00
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => LibraryArtists())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Playlists'.i18n),
|
2020-10-19 21:28:45 +02:00
|
|
|
leading: LeadingIcon(Icons.playlist_play, color: Color(0xff0880b5)),
|
2020-06-23 21:23:12 +02:00
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => LibraryPlaylists())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2020-10-19 21:28:45 +02:00
|
|
|
FreezerDivider(),
|
2020-10-09 20:52:45 +02:00
|
|
|
ListTile(
|
|
|
|
title: Text('History'.i18n),
|
2020-10-19 21:28:45 +02:00
|
|
|
leading: LeadingIcon(Icons.history, color: Color(0xff009a85)),
|
2020-10-09 20:52:45 +02:00
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => HistoryScreen())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2020-10-19 21:28:45 +02:00
|
|
|
FreezerDivider(),
|
2020-06-25 14:28:56 +02:00
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Import'.i18n),
|
2020-10-19 21:28:45 +02:00
|
|
|
leading: LeadingIcon(Icons.import_export, color: Color(0xff2ba766)),
|
2020-09-18 19:36:41 +02:00
|
|
|
subtitle: Text('Import playlists from Spotify'.i18n),
|
2020-06-25 14:28:56 +02:00
|
|
|
onTap: () {
|
|
|
|
if (spotify.doneImporting != null) {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => CurrentlyImportingScreen())
|
|
|
|
);
|
|
|
|
if (spotify.doneImporting) spotify.doneImporting = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => ImporterScreen())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2020-06-23 21:23:12 +02:00
|
|
|
ExpansionTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Statistics'.i18n),
|
2020-10-19 21:28:45 +02:00
|
|
|
leading: LeadingIcon(Icons.insert_chart, color: Colors.grey),
|
2020-06-23 21:23:12 +02:00
|
|
|
children: <Widget>[
|
|
|
|
FutureBuilder(
|
|
|
|
future: downloadManager.getStats(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasError) return ErrorScreen();
|
|
|
|
if (!snapshot.hasData) return 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(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Offline tracks'.i18n),
|
2020-06-23 21:23:12 +02:00
|
|
|
leading: Icon(Icons.audiotrack),
|
|
|
|
trailing: Text(data[0]),
|
|
|
|
),
|
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Offline albums'.i18n),
|
2020-06-23 21:23:12 +02:00
|
|
|
leading: Icon(Icons.album),
|
|
|
|
trailing: Text(data[1]),
|
|
|
|
),
|
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Offline playlists'.i18n),
|
2020-06-23 21:23:12 +02:00
|
|
|
leading: Icon(Icons.playlist_add),
|
|
|
|
trailing: Text(data[2]),
|
|
|
|
),
|
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Offline size'.i18n),
|
2020-06-23 21:23:12 +02:00
|
|
|
leading: Icon(Icons.sd_card),
|
|
|
|
trailing: Text(data[3]),
|
|
|
|
),
|
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Free space'.i18n),
|
2020-06-23 21:23:12 +02:00
|
|
|
leading: Icon(Icons.disc_full),
|
|
|
|
trailing: Text(data[4]),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibraryTracks extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_LibraryTracksState createState() => _LibraryTracksState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LibraryTracksState extends State<LibraryTracks> {
|
|
|
|
|
|
|
|
bool _loading = false;
|
2020-10-10 22:51:20 +02:00
|
|
|
bool _loadingTracks = false;
|
2020-06-23 21:23:12 +02:00
|
|
|
ScrollController _scrollController = ScrollController();
|
|
|
|
List<Track> tracks = [];
|
|
|
|
List<Track> allTracks = [];
|
2020-10-09 20:52:45 +02:00
|
|
|
int trackCount;
|
2020-10-14 21:09:16 +02:00
|
|
|
SortType _sort = SortType.DEFAULT;
|
2020-06-23 21:23:12 +02:00
|
|
|
|
|
|
|
Playlist get _playlist => Playlist(id: deezerAPI.favoritesPlaylistId);
|
|
|
|
|
2020-10-14 21:09:16 +02:00
|
|
|
List<Track> get _sorted {
|
|
|
|
List<Track> tcopy = List.from(tracks);
|
2020-11-01 17:32:28 +01:00
|
|
|
tcopy.sort((a, b) => a.favoriteDate.compareTo(b.favoriteDate));
|
2020-10-14 21:09:16 +02:00
|
|
|
switch (_sort) {
|
|
|
|
case SortType.ALPHABETIC:
|
|
|
|
tcopy.sort((a, b) => a.title.compareTo(b.title));
|
|
|
|
return tcopy;
|
|
|
|
case SortType.ARTIST:
|
|
|
|
tcopy.sort((a, b) => a.artists[0].name.toLowerCase().compareTo(b.artists[0].name.toLowerCase()));
|
|
|
|
return tcopy;
|
|
|
|
case SortType.REVERSE:
|
|
|
|
return tcopy.reversed.toList();
|
|
|
|
case SortType.DEFAULT:
|
|
|
|
default:
|
|
|
|
return tcopy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
Future _load() async {
|
2020-10-09 20:52:45 +02:00
|
|
|
//Already loaded
|
|
|
|
if (trackCount != null && tracks.length >= trackCount) {
|
|
|
|
//Update tracks cache if fully loaded
|
|
|
|
if (cache.libraryTracks == null || cache.libraryTracks.length != trackCount) {
|
|
|
|
setState(() {
|
|
|
|
cache.libraryTracks = tracks.map((t) => t.id).toList();
|
|
|
|
});
|
|
|
|
await cache.save();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
ConnectivityResult connectivity = await Connectivity().checkConnectivity();
|
|
|
|
if (connectivity != ConnectivityResult.none) {
|
|
|
|
setState(() => _loading = true);
|
|
|
|
int pos = tracks.length;
|
2020-10-09 20:52:45 +02:00
|
|
|
|
|
|
|
if (trackCount == null || tracks.length == 0) {
|
|
|
|
//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
|
|
|
|
setState(() {
|
|
|
|
trackCount = favPlaylist.trackCount;
|
|
|
|
tracks = favPlaylist.tracks;
|
|
|
|
_makeFavorite();
|
|
|
|
_loading = false;
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
//Load another page of tracks from deezer
|
2020-10-10 22:51:20 +02:00
|
|
|
if (_loadingTracks) return;
|
|
|
|
_loadingTracks = true;
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
List<Track> _t;
|
|
|
|
try {
|
|
|
|
_t = await deezerAPI.playlistTracksPage(deezerAPI.favoritesPlaylistId, pos);
|
|
|
|
} catch (e) {}
|
|
|
|
//On error load offline
|
|
|
|
if (_t == null) {
|
|
|
|
await _loadOffline();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
tracks.addAll(_t);
|
2020-10-09 20:52:45 +02:00
|
|
|
_makeFavorite();
|
2020-06-23 21:23:12 +02:00
|
|
|
_loading = false;
|
2020-10-10 22:51:20 +02:00
|
|
|
_loadingTracks = false;
|
2020-06-23 21:23:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-14 21:09:16 +02:00
|
|
|
//Load all tracks
|
|
|
|
Future _loadFull() async {
|
|
|
|
if (tracks.length < (trackCount??0)) {
|
|
|
|
Playlist p;
|
|
|
|
try {
|
|
|
|
p = await deezerAPI.fullPlaylist(deezerAPI.favoritesPlaylistId);
|
|
|
|
} catch (e) {}
|
|
|
|
if (p != null) {
|
|
|
|
setState(() {
|
|
|
|
tracks = p.tracks;
|
|
|
|
trackCount = p.trackCount;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
Future _loadOffline() async {
|
|
|
|
Playlist p = await downloadManager.getPlaylist(deezerAPI.favoritesPlaylistId);
|
|
|
|
if (p != null) setState(() {
|
|
|
|
tracks = p.tracks;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-14 21:09:16 +02:00
|
|
|
Future _loadAllOffline() async {
|
2020-06-23 21:23:12 +02:00
|
|
|
List tracks = await downloadManager.allOfflineTracks();
|
|
|
|
setState(() {
|
|
|
|
allTracks = tracks;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-09 20:52:45 +02:00
|
|
|
//Update tracks with favorite true
|
|
|
|
void _makeFavorite() {
|
|
|
|
for (int i=0; i<tracks.length; i++)
|
|
|
|
tracks[i].favorite = true;
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_scrollController.addListener(() {
|
|
|
|
//Load more tracks on scroll
|
|
|
|
double off = _scrollController.position.maxScrollExtent * 0.90;
|
|
|
|
if (_scrollController.position.pixels > off) _load();
|
|
|
|
});
|
|
|
|
|
2020-10-14 21:09:16 +02:00
|
|
|
_sort = cache.trackSort??SortType.DEFAULT;
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
_load();
|
2020-10-14 21:09:16 +02:00
|
|
|
//Load all offline tracks
|
|
|
|
_loadAllOffline();
|
2020-06-23 21:23:12 +02:00
|
|
|
|
2020-10-14 21:09:16 +02:00
|
|
|
if (_sort != SortType.DEFAULT)
|
|
|
|
_loadFull();
|
2020-06-23 21:23:12 +02:00
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2020-10-19 21:28:45 +02:00
|
|
|
appBar: FreezerAppBar(
|
|
|
|
'Tracks'.i18n,
|
2020-10-14 21:09:16 +02:00
|
|
|
actions: [
|
|
|
|
PopupMenuButton(
|
|
|
|
child: Icon(Icons.sort, size: 32.0),
|
2020-10-19 21:28:45 +02:00
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
2020-10-14 21:09:16 +02:00
|
|
|
onSelected: (SortType s) async {
|
|
|
|
//Preload for sorting
|
|
|
|
if (tracks.length < (trackCount??0))
|
|
|
|
await _loadFull();
|
|
|
|
|
|
|
|
setState(() => _sort = s);
|
|
|
|
cache.trackSort = s;
|
|
|
|
await cache.save();
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => <PopupMenuEntry<SortType>>[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.DEFAULT,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Default'.i18n, style: popupMenuTextStyle()),
|
2020-10-14 21:09:16 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.REVERSE,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Reverse'.i18n, style: popupMenuTextStyle()),
|
2020-10-14 21:09:16 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.ALPHABETIC,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Alphabetic'.i18n, style: popupMenuTextStyle()),
|
2020-10-14 21:09:16 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: SortType.ARTIST,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Artist'.i18n, style: popupMenuTextStyle()),
|
2020-10-14 21:09:16 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-10-15 20:37:36 +02:00
|
|
|
Container(width: 8.0),
|
2020-10-14 21:09:16 +02:00
|
|
|
],
|
|
|
|
),
|
2020-06-23 21:23:12 +02:00
|
|
|
body: ListView(
|
2020-10-09 20:52:45 +02:00
|
|
|
controller: _scrollController,
|
2020-06-23 21:23:12 +02:00
|
|
|
children: <Widget>[
|
2020-10-19 21:28:45 +02:00
|
|
|
Container(
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
2020-06-23 21:23:12 +02:00
|
|
|
children: <Widget>[
|
2020-10-19 21:28:45 +02:00
|
|
|
MakePlaylistOffline(_playlist),
|
|
|
|
FlatButton(
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(Icons.file_download, size: 32.0,),
|
|
|
|
Container(width: 4,),
|
|
|
|
Text('Download'.i18n)
|
|
|
|
],
|
2020-06-23 21:23:12 +02:00
|
|
|
),
|
2020-10-19 21:28:45 +02:00
|
|
|
onPressed: () async {
|
|
|
|
if (await downloadManager.addOfflinePlaylist(_playlist, private: false, context: context) != false)
|
|
|
|
MenuSheet(context).showDownloadStartedToast();
|
|
|
|
},
|
2020-06-23 21:23:12 +02:00
|
|
|
)
|
|
|
|
],
|
2020-10-19 21:28:45 +02:00
|
|
|
)
|
2020-06-23 21:23:12 +02:00
|
|
|
),
|
2020-10-19 21:28:45 +02:00
|
|
|
FreezerDivider(),
|
2020-06-23 21:23:12 +02:00
|
|
|
//Loved tracks
|
|
|
|
...List.generate(tracks.length, (i) {
|
2020-10-14 21:09:16 +02:00
|
|
|
Track t = (tracks.length == (trackCount??0))?_sorted[i]:tracks[i];
|
2020-06-23 21:23:12 +02:00
|
|
|
return TrackTile(
|
|
|
|
t,
|
|
|
|
onTap: () {
|
2020-10-14 21:09:16 +02:00
|
|
|
playerHelper.playFromTrackList((tracks.length == (trackCount??0))?_sorted:tracks, t.id, QueueSource(
|
2020-06-23 21:23:12 +02:00
|
|
|
id: deezerAPI.favoritesPlaylistId,
|
2020-09-18 19:36:41 +02:00
|
|
|
text: 'Favorites'.i18n,
|
2020-06-23 21:23:12 +02:00
|
|
|
source: 'playlist'
|
|
|
|
));
|
|
|
|
},
|
|
|
|
onHold: () {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
m.defaultTrackMenu(
|
|
|
|
t,
|
|
|
|
onRemove: () {
|
|
|
|
setState(() {
|
|
|
|
tracks.removeWhere((track) => t.id == track.id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
if (_loading)
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2020-10-19 21:28:45 +02:00
|
|
|
FreezerDivider(),
|
2020-06-23 21:23:12 +02:00
|
|
|
Text(
|
2020-09-18 19:36:41 +02:00
|
|
|
'All offline tracks'.i18n,
|
2020-06-23 21:23:12 +02:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 24,
|
|
|
|
fontWeight: FontWeight.bold
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(height: 8,),
|
|
|
|
...List.generate(allTracks.length, (i) {
|
|
|
|
Track t = allTracks[i];
|
|
|
|
return TrackTile(
|
|
|
|
t,
|
|
|
|
onTap: () {
|
|
|
|
playerHelper.playFromTrackList(allTracks, t.id, QueueSource(
|
|
|
|
id: 'allTracks',
|
2020-09-18 19:36:41 +02:00
|
|
|
text: 'All offline tracks'.i18n,
|
2020-06-23 21:23:12 +02:00
|
|
|
source: 'offline'
|
|
|
|
));
|
|
|
|
},
|
|
|
|
onHold: () {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
m.defaultTrackMenu(t);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
],
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-12 22:49:13 +02:00
|
|
|
enum AlbumSortType {
|
|
|
|
DEFAULT,
|
|
|
|
REVERSE,
|
|
|
|
ALPHABETIC,
|
|
|
|
ARTIST
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
class LibraryAlbums extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_LibraryAlbumsState createState() => _LibraryAlbumsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LibraryAlbumsState extends State<LibraryAlbums> {
|
|
|
|
|
|
|
|
List<Album> _albums;
|
2020-10-12 22:49:13 +02:00
|
|
|
AlbumSortType _sort = AlbumSortType.DEFAULT;
|
|
|
|
|
|
|
|
List<Album> get _sorted {
|
|
|
|
List<Album> albums = List.from(_albums);
|
2020-10-25 10:32:23 +01:00
|
|
|
albums.sort((a, b) => a.favoriteDate.compareTo(b.favoriteDate));
|
2020-10-12 22:49:13 +02:00
|
|
|
switch (_sort) {
|
|
|
|
case AlbumSortType.DEFAULT:
|
2020-10-25 10:32:23 +01:00
|
|
|
return albums;
|
2020-10-12 22:49:13 +02:00
|
|
|
case AlbumSortType.REVERSE:
|
2020-10-25 10:32:23 +01:00
|
|
|
return albums.reversed.toList();
|
2020-10-12 22:49:13 +02:00
|
|
|
case AlbumSortType.ALPHABETIC:
|
|
|
|
albums.sort((a, b) => a.title.toLowerCase().compareTo(b.title.toLowerCase()));
|
|
|
|
return albums;
|
|
|
|
case AlbumSortType.ARTIST:
|
|
|
|
albums.sort((a, b) => a.artists[0].name.toLowerCase().compareTo(b.artists[0].name.toLowerCase()));
|
|
|
|
return albums;
|
|
|
|
}
|
|
|
|
return albums;
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
|
|
|
|
Future _load() async {
|
|
|
|
if (settings.offlineMode) return;
|
|
|
|
try {
|
|
|
|
List<Album> albums = await deezerAPI.getAlbums();
|
|
|
|
setState(() => _albums = albums);
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_load();
|
2020-10-12 22:49:13 +02:00
|
|
|
_sort = cache.albumSort??AlbumSortType.DEFAULT;
|
2020-06-23 21:23:12 +02:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2020-10-19 21:28:45 +02:00
|
|
|
appBar: FreezerAppBar(
|
|
|
|
'Albums'.i18n,
|
2020-10-12 22:49:13 +02:00
|
|
|
actions: [
|
|
|
|
PopupMenuButton(
|
2020-10-19 21:28:45 +02:00
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
2020-10-12 22:49:13 +02:00
|
|
|
child: Icon(Icons.sort, size: 32.0),
|
|
|
|
onSelected: (AlbumSortType s) async {
|
|
|
|
setState(() => _sort = s);
|
|
|
|
cache.albumSort = s;
|
|
|
|
await cache.save();
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => <PopupMenuEntry<AlbumSortType>>[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: AlbumSortType.DEFAULT,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Default'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: AlbumSortType.REVERSE,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Reverse'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: AlbumSortType.ALPHABETIC,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Alphabetic'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: AlbumSortType.ARTIST,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Artist'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-10-15 20:37:36 +02:00
|
|
|
Container(width: 8.0),
|
2020-10-12 22:49:13 +02:00
|
|
|
],
|
|
|
|
),
|
2020-06-23 21:23:12 +02:00
|
|
|
body: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(height: 8.0,),
|
|
|
|
if (!settings.offlineMode && _albums == null)
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
CircularProgressIndicator()
|
|
|
|
],
|
|
|
|
),
|
|
|
|
|
|
|
|
if (_albums != null)
|
|
|
|
...List.generate(_albums.length, (int i) {
|
2020-10-12 22:49:13 +02:00
|
|
|
Album a = _sorted[i];
|
2020-06-23 21:23:12 +02:00
|
|
|
return AlbumTile(
|
|
|
|
a,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => AlbumDetails(a))
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onHold: () async {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
m.defaultAlbumMenu(a, onRemove: () {
|
|
|
|
setState(() => _albums.remove(a));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
|
|
|
|
FutureBuilder(
|
|
|
|
future: downloadManager.getOfflineAlbums(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasError || !snapshot.hasData || snapshot.data.length == 0) return Container(height: 0, width: 0,);
|
|
|
|
|
|
|
|
List<Album> albums = snapshot.data;
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
2020-10-19 21:28:45 +02:00
|
|
|
FreezerDivider(),
|
2020-06-23 21:23:12 +02:00
|
|
|
Text(
|
2020-09-18 19:36:41 +02:00
|
|
|
'Offline albums'.i18n,
|
2020-06-23 21:23:12 +02:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 24.0
|
|
|
|
),
|
|
|
|
),
|
|
|
|
...List.generate(albums.length, (i) {
|
|
|
|
Album a = albums[i];
|
|
|
|
return AlbumTile(
|
|
|
|
a,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => AlbumDetails(a))
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onHold: () async {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
m.defaultAlbumMenu(a, onRemove: () {
|
|
|
|
setState(() {
|
|
|
|
albums.remove(a);
|
|
|
|
_albums.remove(a);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-12 22:49:13 +02:00
|
|
|
enum ArtistSortType {
|
|
|
|
DEFAULT,
|
|
|
|
REVERSE,
|
|
|
|
POPULARITY,
|
|
|
|
ALPHABETIC
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
class LibraryArtists extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_LibraryArtistsState createState() => _LibraryArtistsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LibraryArtistsState extends State<LibraryArtists> {
|
2020-10-12 22:49:13 +02:00
|
|
|
|
|
|
|
List<Artist> _artists;
|
|
|
|
ArtistSortType _sort = ArtistSortType.DEFAULT;
|
|
|
|
bool _loading = true;
|
|
|
|
bool _error = false;
|
|
|
|
|
|
|
|
List<Artist> get _sorted {
|
|
|
|
List<Artist> artists = List.from(_artists);
|
2020-10-25 10:32:23 +01:00
|
|
|
artists.sort((a, b) => a.favoriteDate.compareTo(b.favoriteDate));
|
2020-10-12 22:49:13 +02:00
|
|
|
switch (_sort) {
|
|
|
|
case ArtistSortType.DEFAULT:
|
2020-10-25 10:32:23 +01:00
|
|
|
return artists;
|
2020-10-12 22:49:13 +02:00
|
|
|
case ArtistSortType.REVERSE:
|
2020-10-25 10:32:23 +01:00
|
|
|
return artists.reversed.toList();
|
2020-10-12 22:49:13 +02:00
|
|
|
case ArtistSortType.POPULARITY:
|
|
|
|
artists.sort((a, b) => b.fans - a.fans);
|
|
|
|
return artists;
|
|
|
|
case ArtistSortType.ALPHABETIC:
|
|
|
|
artists.sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
|
|
|
|
return artists;
|
|
|
|
}
|
2020-10-14 21:09:16 +02:00
|
|
|
return artists;
|
2020-10-12 22:49:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_sort = cache.artistSort;
|
|
|
|
_load();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2020-10-19 21:28:45 +02:00
|
|
|
appBar: FreezerAppBar(
|
|
|
|
'Artists'.i18n,
|
2020-10-12 22:49:13 +02:00
|
|
|
actions: [
|
|
|
|
PopupMenuButton(
|
|
|
|
child: Icon(Icons.sort, size: 32.0),
|
2020-10-19 21:28:45 +02:00
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
2020-10-12 22:49:13 +02:00
|
|
|
onSelected: (ArtistSortType s) async {
|
|
|
|
setState(() => _sort = s);
|
|
|
|
cache.artistSort = s;
|
|
|
|
await cache.save();
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => <PopupMenuEntry<ArtistSortType>>[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: ArtistSortType.DEFAULT,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Default'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: ArtistSortType.REVERSE,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Reverse'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: ArtistSortType.ALPHABETIC,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Alphabetic'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: ArtistSortType.POPULARITY,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Popularity'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
],
|
2020-10-15 20:37:36 +02:00
|
|
|
),
|
|
|
|
Container(width: 8.0),
|
2020-10-12 22:49:13 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
if (_loading)
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.all(8.0),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [CircularProgressIndicator()],
|
|
|
|
),
|
|
|
|
),
|
2020-06-23 21:23:12 +02:00
|
|
|
|
2020-10-12 22:49:13 +02:00
|
|
|
if (_error)
|
|
|
|
Center(child: ErrorScreen()),
|
2020-06-23 21:23:12 +02:00
|
|
|
|
2020-10-12 22:49:13 +02:00
|
|
|
if (!_loading && !_error)
|
|
|
|
...List.generate(_artists.length, (i) {
|
|
|
|
Artist a = _sorted[i];
|
|
|
|
return ArtistHorizontalTile(
|
|
|
|
a,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => ArtistDetails(a))
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onHold: () {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
m.defaultArtistMenu(a, onRemove: () {
|
|
|
|
setState(() {
|
|
|
|
_artists.remove(a);
|
2020-06-23 21:23:12 +02:00
|
|
|
});
|
2020-10-12 22:49:13 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
],
|
2020-06-23 21:23:12 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-12 22:49:13 +02:00
|
|
|
enum PlaylistSortType {
|
|
|
|
DEFAULT,
|
|
|
|
REVERSE,
|
|
|
|
ALPHABETIC,
|
|
|
|
USER,
|
|
|
|
TRACK_COUNT
|
|
|
|
}
|
2020-06-23 21:23:12 +02:00
|
|
|
|
|
|
|
class LibraryPlaylists extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_LibraryPlaylistsState createState() => _LibraryPlaylistsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LibraryPlaylistsState extends State<LibraryPlaylists> {
|
|
|
|
|
|
|
|
List<Playlist> _playlists;
|
2020-10-12 22:49:13 +02:00
|
|
|
PlaylistSortType _sort = PlaylistSortType.DEFAULT;
|
|
|
|
|
|
|
|
List<Playlist> get _sorted {
|
|
|
|
List<Playlist> playlists = List.from(_playlists);
|
|
|
|
switch (_sort) {
|
|
|
|
case PlaylistSortType.DEFAULT:
|
|
|
|
return _playlists;
|
|
|
|
case PlaylistSortType.REVERSE:
|
|
|
|
return _playlists.reversed.toList();
|
|
|
|
case PlaylistSortType.USER:
|
|
|
|
playlists.sort((a, b) => (a.user.name??deezerAPI.userName).toLowerCase().compareTo((b.user.name??deezerAPI.userName).toLowerCase()));
|
|
|
|
return playlists;
|
|
|
|
case PlaylistSortType.TRACK_COUNT:
|
|
|
|
playlists.sort((a, b) => b.trackCount - a.trackCount);
|
|
|
|
return playlists;
|
|
|
|
case PlaylistSortType.ALPHABETIC:
|
|
|
|
playlists.sort((a, b) => a.title.toLowerCase().compareTo(b.title.toLowerCase()));
|
|
|
|
return playlists;
|
|
|
|
}
|
2020-10-14 21:09:16 +02:00
|
|
|
return playlists;
|
2020-10-12 22:49:13 +02:00
|
|
|
}
|
2020-06-23 21:23:12 +02:00
|
|
|
|
|
|
|
Future _load() async {
|
|
|
|
if (!settings.offlineMode) {
|
|
|
|
try {
|
|
|
|
List<Playlist> playlists = await deezerAPI.getPlaylists();
|
|
|
|
setState(() => _playlists = playlists);
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2020-10-12 22:49:13 +02:00
|
|
|
_sort = cache.libraryPlaylistSort;
|
2020-06-23 21:23:12 +02:00
|
|
|
_load();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2020-09-18 19:36:41 +02:00
|
|
|
Playlist get favoritesPlaylist => Playlist(
|
|
|
|
id: deezerAPI.favoritesPlaylistId,
|
|
|
|
title: 'Favorites'.i18n,
|
|
|
|
user: User(name: deezerAPI.userName),
|
|
|
|
image: ImageDetails(thumbUrl: 'assets/favorites_thumb.jpg'),
|
|
|
|
tracks: [],
|
|
|
|
trackCount: 1,
|
|
|
|
duration: Duration(seconds: 0)
|
|
|
|
);
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2020-10-19 21:28:45 +02:00
|
|
|
appBar: FreezerAppBar(
|
|
|
|
'Playlists'.i18n,
|
2020-10-12 22:49:13 +02:00
|
|
|
actions: [
|
|
|
|
PopupMenuButton(
|
|
|
|
child: Icon(Icons.sort, size: 32.0),
|
2020-10-19 21:28:45 +02:00
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
2020-10-12 22:49:13 +02:00
|
|
|
onSelected: (PlaylistSortType s) async {
|
|
|
|
setState(() => _sort = s);
|
|
|
|
cache.libraryPlaylistSort = s;
|
|
|
|
await cache.save();
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => <PopupMenuEntry<PlaylistSortType>>[
|
|
|
|
PopupMenuItem(
|
|
|
|
value: PlaylistSortType.DEFAULT,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Default'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: PlaylistSortType.REVERSE,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Reverse'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: PlaylistSortType.USER,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('User'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: PlaylistSortType.TRACK_COUNT,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Track count'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: PlaylistSortType.ALPHABETIC,
|
2020-10-19 21:28:45 +02:00
|
|
|
child: Text('Alphabetic'.i18n, style: popupMenuTextStyle()),
|
2020-10-12 22:49:13 +02:00
|
|
|
),
|
|
|
|
],
|
2020-10-15 20:37:36 +02:00
|
|
|
),
|
|
|
|
Container(width: 8.0),
|
2020-10-12 22:49:13 +02:00
|
|
|
],
|
|
|
|
),
|
2020-06-23 21:23:12 +02:00
|
|
|
body: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
2020-09-18 19:36:41 +02:00
|
|
|
title: Text('Create new playlist'.i18n),
|
2020-10-19 21:28:45 +02:00
|
|
|
leading: LeadingIcon(Icons.playlist_add, color: Color(0xff009a85)),
|
2020-10-09 20:52:45 +02:00
|
|
|
onTap: () async {
|
2020-06-23 21:23:12 +02:00
|
|
|
if (settings.offlineMode) {
|
|
|
|
Fluttertoast.showToast(
|
2020-09-18 19:36:41 +02:00
|
|
|
msg: 'Cannot create playlists in offline mode'.i18n,
|
2020-06-23 21:23:12 +02:00
|
|
|
gravity: ToastGravity.BOTTOM
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MenuSheet m = MenuSheet(context);
|
2020-10-09 20:52:45 +02:00
|
|
|
await m.createPlaylist();
|
|
|
|
await _load();
|
2020-06-23 21:23:12 +02:00
|
|
|
},
|
|
|
|
),
|
2020-10-19 21:28:45 +02:00
|
|
|
FreezerDivider(),
|
2020-06-23 21:23:12 +02:00
|
|
|
|
|
|
|
if (!settings.offlineMode && _playlists == null)
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
CircularProgressIndicator(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
|
2020-09-18 19:36:41 +02:00
|
|
|
//Favorites playlist
|
|
|
|
PlaylistTile(
|
|
|
|
favoritesPlaylist,
|
|
|
|
onTap: () async {
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) => PlaylistDetails(favoritesPlaylist)
|
|
|
|
));
|
|
|
|
},
|
|
|
|
onHold: () {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
2020-10-09 20:52:45 +02:00
|
|
|
favoritesPlaylist.library = true;
|
2020-09-18 19:36:41 +02:00
|
|
|
m.defaultPlaylistMenu(favoritesPlaylist);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
|
2020-06-23 21:23:12 +02:00
|
|
|
if (_playlists != null)
|
|
|
|
...List.generate(_playlists.length, (int i) {
|
2020-10-14 21:09:16 +02:00
|
|
|
Playlist p = (_sorted??[])[i];
|
2020-06-23 21:23:12 +02:00
|
|
|
return PlaylistTile(
|
|
|
|
p,
|
|
|
|
onTap: () => Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) => PlaylistDetails(p)
|
|
|
|
)),
|
|
|
|
onHold: () {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
2020-10-09 20:52:45 +02:00
|
|
|
m.defaultPlaylistMenu(
|
|
|
|
p,
|
|
|
|
onRemove: () {setState(() => _playlists.remove(p));},
|
|
|
|
onUpdate: () {_load();});
|
2020-06-23 21:23:12 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
|
|
|
|
FutureBuilder(
|
|
|
|
future: downloadManager.getOfflinePlaylists(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasError || !snapshot.hasData) return Container(height: 0, width: 0,);
|
|
|
|
if (snapshot.data.length == 0) return Container(height: 0, width: 0,);
|
|
|
|
|
|
|
|
List<Playlist> playlists = snapshot.data;
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
2020-10-19 21:28:45 +02:00
|
|
|
FreezerDivider(),
|
2020-06-23 21:23:12 +02:00
|
|
|
Text(
|
2020-09-18 19:36:41 +02:00
|
|
|
'Offline playlists'.i18n,
|
2020-06-23 21:23:12 +02:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 24.0,
|
|
|
|
fontWeight: FontWeight.bold
|
|
|
|
),
|
|
|
|
),
|
|
|
|
...List.generate(playlists.length, (i) {
|
|
|
|
Playlist p = playlists[i];
|
|
|
|
return PlaylistTile(
|
|
|
|
p,
|
|
|
|
onTap: () => Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) => PlaylistDetails(p)
|
|
|
|
)),
|
|
|
|
onHold: () {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
m.defaultPlaylistMenu(p, onRemove: () {
|
|
|
|
setState(() {
|
|
|
|
playlists.remove(p);
|
|
|
|
_playlists.remove(p);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 20:52:45 +02:00
|
|
|
|
|
|
|
class HistoryScreen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_HistoryScreenState createState() => _HistoryScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HistoryScreenState extends State<HistoryScreen> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2020-10-19 21:28:45 +02:00
|
|
|
appBar: FreezerAppBar(
|
|
|
|
'History'.i18n,
|
2020-10-09 20:52:45 +02:00
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.delete_sweep),
|
|
|
|
onPressed: () {
|
|
|
|
setState(() => cache.history = []);
|
|
|
|
cache.save();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: ListView.builder(
|
|
|
|
itemCount: (cache.history??[]).length,
|
|
|
|
itemBuilder: (BuildContext context, int i) {
|
2020-10-20 21:55:14 +02:00
|
|
|
Track t = cache.history[cache.history.length - i - 1];
|
2020-10-09 20:52:45 +02:00
|
|
|
return TrackTile(
|
|
|
|
t,
|
|
|
|
onTap: () {
|
2020-10-20 21:55:14 +02:00
|
|
|
playerHelper.playFromTrackList(cache.history.reversed.toList(), t.id, QueueSource(
|
2020-10-09 20:52:45 +02:00
|
|
|
id: null,
|
|
|
|
text: 'History'.i18n,
|
|
|
|
source: 'history'
|
|
|
|
));
|
|
|
|
},
|
|
|
|
onHold: () {
|
|
|
|
MenuSheet m = MenuSheet(context);
|
|
|
|
m.defaultTrackMenu(t);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|