0.6.3 - Playlist search, few other things i forgot
This commit is contained in:
parent
e9d97986b5
commit
e029c41b43
26 changed files with 520 additions and 62 deletions
|
@ -308,7 +308,7 @@ class ArtistDetails extends StatelessWidget {
|
|||
rounded: true,
|
||||
),
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width / 2 - 8,
|
||||
width: MediaQuery.of(context).size.width / 2 - 24,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
@ -410,6 +410,32 @@ class ArtistDetails extends StatelessWidget {
|
|||
),
|
||||
FreezerDivider(),
|
||||
Container(height: 12.0,),
|
||||
//Highlight
|
||||
if (artist.highlight != null)
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 2.0),
|
||||
child: Text(
|
||||
artist.highlight.title,
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20.0
|
||||
),
|
||||
),
|
||||
),
|
||||
if (artist.highlight.type == ArtistHighlightType.ALBUM)
|
||||
AlbumTile(
|
||||
artist.highlight.data,
|
||||
onTap: () {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) => AlbumDetails(artist.highlight.data)));
|
||||
},
|
||||
),
|
||||
Container(height: 8.0)
|
||||
],
|
||||
),
|
||||
//Top tracks
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 2.0),
|
||||
|
@ -417,8 +443,8 @@ class ArtistDetails extends StatelessWidget {
|
|||
'Top Tracks'.i18n,
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20.0
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20.0
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -502,7 +502,8 @@ enum AlbumSortType {
|
|||
DEFAULT,
|
||||
REVERSE,
|
||||
ALPHABETIC,
|
||||
ARTIST
|
||||
ARTIST,
|
||||
DATE
|
||||
}
|
||||
|
||||
class LibraryAlbums extends StatefulWidget {
|
||||
|
@ -530,6 +531,9 @@ class _LibraryAlbumsState extends State<LibraryAlbums> {
|
|||
case AlbumSortType.ARTIST:
|
||||
albums.sort((a, b) => a.artists[0].name.toLowerCase().compareTo(b.artists[0].name.toLowerCase()));
|
||||
return albums;
|
||||
case AlbumSortType.DATE:
|
||||
albums.sort((a, b) => DateTime.parse(a.releaseDate).compareTo(DateTime.parse(b.releaseDate)));
|
||||
return albums;
|
||||
}
|
||||
return albums;
|
||||
}
|
||||
|
@ -581,6 +585,10 @@ class _LibraryAlbumsState extends State<LibraryAlbums> {
|
|||
value: AlbumSortType.ARTIST,
|
||||
child: Text('Artist'.i18n, style: popupMenuTextStyle()),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: AlbumSortType.DATE,
|
||||
child: Text('Release date'.i18n, style: popupMenuTextStyle()),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(width: 8.0),
|
||||
|
@ -829,14 +837,15 @@ class _LibraryPlaylistsState extends State<LibraryPlaylists> {
|
|||
List<Playlist> _playlists;
|
||||
PlaylistSortType _sort = PlaylistSortType.DEFAULT;
|
||||
ScrollController _scrollController = ScrollController();
|
||||
String _filter = '';
|
||||
|
||||
List<Playlist> get _sorted {
|
||||
List<Playlist> playlists = List.from(_playlists);
|
||||
List<Playlist> playlists = List.from(_playlists.where((p) => p.title.toLowerCase().contains(_filter.toLowerCase())));
|
||||
switch (_sort) {
|
||||
case PlaylistSortType.DEFAULT:
|
||||
return _playlists;
|
||||
return playlists;
|
||||
case PlaylistSortType.REVERSE:
|
||||
return _playlists.reversed.toList();
|
||||
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;
|
||||
|
@ -923,6 +932,24 @@ class _LibraryPlaylistsState extends State<LibraryPlaylists> {
|
|||
child: ListView(
|
||||
controller: _scrollController,
|
||||
children: <Widget>[
|
||||
//Search
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: TextField(
|
||||
onChanged: (String s) => setState(() => _filter = s),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Search'.i18n,
|
||||
fillColor: Theme.of(context).bottomAppBarColor,
|
||||
filled: true,
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey)
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey)
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('Create new playlist'.i18n),
|
||||
leading: LeadingIcon(Icons.playlist_add, color: Color(0xff009a85)),
|
||||
|
@ -965,7 +992,7 @@ class _LibraryPlaylistsState extends State<LibraryPlaylists> {
|
|||
),
|
||||
|
||||
if (_playlists != null)
|
||||
...List.generate(_playlists.length, (int i) {
|
||||
...List.generate(_sorted.length, (int i) {
|
||||
Playlist p = (_sorted??[])[i];
|
||||
return PlaylistTile(
|
||||
p,
|
||||
|
|
|
@ -16,6 +16,7 @@ import 'package:freezer/ui/downloads_screen.dart';
|
|||
import 'package:freezer/ui/elements.dart';
|
||||
import 'package:freezer/ui/error.dart';
|
||||
import 'package:freezer/ui/home_screen.dart';
|
||||
import 'package:freezer/ui/updater.dart';
|
||||
import 'package:i18n_extension/i18n_widget.dart';
|
||||
import 'package:language_pickers/language_pickers.dart';
|
||||
import 'package:language_pickers/languages.dart';
|
||||
|
@ -141,9 +142,16 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text('Updates'.i18n),
|
||||
leading: LeadingIcon(Icons.update, color: Color(0xff2ba766)),
|
||||
onTap: () => Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => UpdaterScreen()
|
||||
)),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('About'.i18n),
|
||||
leading: LeadingIcon(Icons.info, color: Color(0xff2ba766)),
|
||||
leading: LeadingIcon(Icons.info, color: Colors.grey),
|
||||
onTap: () => Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => CreditsScreen()
|
||||
)),
|
||||
|
@ -1282,9 +1290,6 @@ class _CreditsScreenState extends State<CreditsScreen> {
|
|||
ListTile(
|
||||
title: Text('Deemix'),
|
||||
subtitle: Text('Better app <3'),
|
||||
onTap: () {
|
||||
launch('https://codeberg.org/RemixDev/deemix');
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text('Xandar Null'),
|
||||
|
|
|
@ -178,6 +178,7 @@ class PlaylistTile extends StatelessWidget {
|
|||
|
||||
String get subtitle {
|
||||
if (playlist.user == null || playlist.user.name == null || playlist.user.name == '' || playlist.user.id == deezerAPI.userId) {
|
||||
if (playlist.trackCount == null) return '';
|
||||
return '${playlist.trackCount} ' + 'Tracks'.i18n;
|
||||
}
|
||||
return playlist.user.name;
|
||||
|
@ -246,6 +247,7 @@ class PlaylistCardTile extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
height: 180.0,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
onLongPress: onHold,
|
||||
|
@ -290,6 +292,7 @@ class SmartTrackListTile extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: 200.0,
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
|
@ -298,18 +301,43 @@ class SmartTrackListTile extends StatelessWidget {
|
|||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: CachedImage(
|
||||
width: 128,
|
||||
height: 128,
|
||||
url: smartTrackList.cover.thumb,
|
||||
rounded: true,
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
CachedImage(
|
||||
width: 128,
|
||||
height: 128,
|
||||
url: smartTrackList.cover.thumb,
|
||||
rounded: true,
|
||||
),
|
||||
Container(
|
||||
width: 128.0,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 6.0),
|
||||
child: Text(
|
||||
smartTrackList.title,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18.0,
|
||||
shadows: [
|
||||
Shadow(
|
||||
offset: Offset(1, 1),
|
||||
blurRadius: 2,
|
||||
color: Colors.black
|
||||
)
|
||||
]
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
),
|
||||
Container(
|
||||
width: 144.0,
|
||||
child: Text(
|
||||
smartTrackList.title,
|
||||
maxLines: 1,
|
||||
smartTrackList.subtitle,
|
||||
maxLines: 3,
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
|
|
265
lib/ui/updater.dart
Normal file
265
lib/ui/updater.dart
Normal file
|
@ -0,0 +1,265 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:freezer/api/cache.dart';
|
||||
import 'package:freezer/api/download.dart';
|
||||
import 'package:freezer/ui/elements.dart';
|
||||
import 'package:freezer/translations.i18n.dart';
|
||||
import 'package:freezer/ui/error.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:open_file/open_file.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'dart:convert';
|
||||
|
||||
|
||||
class UpdaterScreen extends StatefulWidget {
|
||||
@override
|
||||
_UpdaterScreenState createState() => _UpdaterScreenState();
|
||||
}
|
||||
|
||||
class _UpdaterScreenState extends State<UpdaterScreen> {
|
||||
|
||||
bool _loading = true;
|
||||
bool _error = false;
|
||||
FreezerVersions _versions;
|
||||
String _current;
|
||||
String _arch;
|
||||
double _progress = 0.0;
|
||||
bool _buttonEnabled = true;
|
||||
|
||||
Future _load() async {
|
||||
//Load current version
|
||||
PackageInfo info = await PackageInfo.fromPlatform();
|
||||
setState(() => _current = info.version);
|
||||
|
||||
//Get architecture
|
||||
_arch = await DownloadManager.platform.invokeMethod("arch");
|
||||
if (_arch == 'armv8l')
|
||||
_arch = 'arm32';
|
||||
|
||||
//Load from website
|
||||
try {
|
||||
FreezerVersions versions = await FreezerVersions.fetch();
|
||||
setState(() {
|
||||
_versions = versions;
|
||||
_loading = false;
|
||||
});
|
||||
} catch (e, st) {
|
||||
print(e + st);
|
||||
_error = true;
|
||||
_loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
FreezerDownload get _versionDownload {
|
||||
return _versions.versions[0].downloads.firstWhere((d) => d.version.toLowerCase().contains(_arch.toLowerCase()), orElse: () => null);
|
||||
}
|
||||
|
||||
Future _download() async {
|
||||
String url = _versionDownload.directUrl;
|
||||
//Start request
|
||||
http.Client client = new http.Client();
|
||||
http.StreamedResponse res = await client.send(http.Request('GET', Uri.parse(url)));
|
||||
int size = res.contentLength;
|
||||
//Open file
|
||||
String path = p.join((await getExternalStorageDirectory()).path, 'update.apk');
|
||||
File file = File(path);
|
||||
IOSink fileSink = file.openWrite();
|
||||
//Update progress
|
||||
Future.doWhile(() async {
|
||||
int received = await file.length();
|
||||
setState(() => _progress = received/size);
|
||||
return received != size;
|
||||
});
|
||||
//Pipe
|
||||
await res.stream.pipe(fileSink);
|
||||
fileSink.close();
|
||||
|
||||
OpenFile.open(path);
|
||||
setState(() => _buttonEnabled = true);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_load();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: FreezerAppBar('Updates'.i18n),
|
||||
body: ListView(
|
||||
children: [
|
||||
|
||||
if (_error)
|
||||
ErrorScreen(),
|
||||
|
||||
if (_loading)
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [CircularProgressIndicator()],
|
||||
),
|
||||
),
|
||||
|
||||
if (!_error && !_loading && _versions.latest == _current)
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'You are running latest version!'.i18n,
|
||||
style: TextStyle(
|
||||
fontSize: 26.0
|
||||
)
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
if (!_error && !_loading && _versions.latest != _current)
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
'New update available!'.i18n + ' ' + _versions.latest,
|
||||
style: TextStyle(
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.bold
|
||||
),
|
||||
),
|
||||
Container(height: 8.0),
|
||||
Text(
|
||||
'Current version: ' + _current,
|
||||
style: TextStyle(
|
||||
fontSize: 14.0,
|
||||
fontStyle: FontStyle.italic
|
||||
),
|
||||
),
|
||||
Container(height: 8.0),
|
||||
FreezerDivider(),
|
||||
Container(height: 8.0),
|
||||
Text(
|
||||
'Changelog',
|
||||
style: TextStyle(
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.bold
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(16, 4, 16, 8),
|
||||
child: Text(
|
||||
_versions.versions[0].changelog,
|
||||
style: TextStyle(fontSize: 16.0),
|
||||
),
|
||||
),
|
||||
FreezerDivider(),
|
||||
Container(height: 8.0),
|
||||
//Available download
|
||||
if (_versionDownload != null)
|
||||
Column(children: [
|
||||
RaisedButton(
|
||||
child: Text('Download'.i18n + ' (${_versionDownload.version})'),
|
||||
onPressed: _buttonEnabled ? () {
|
||||
setState(() => _buttonEnabled = false);
|
||||
_download();
|
||||
}:null
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: LinearProgressIndicator(value: _progress),
|
||||
)
|
||||
]),
|
||||
//Unsupported arch
|
||||
if (_versionDownload == null)
|
||||
Text(
|
||||
'Unsupported platform!'.i18n + ' $_arch',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 16.0),
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FreezerVersions {
|
||||
String latest;
|
||||
List<FreezerVersion> versions;
|
||||
|
||||
FreezerVersions({this.latest, this.versions});
|
||||
|
||||
factory FreezerVersions.fromJson(Map data) => FreezerVersions(
|
||||
latest: data['android']['latest'],
|
||||
versions: data['android']['versions'].map<FreezerVersion>((v) => FreezerVersion.fromJson(v)).toList()
|
||||
);
|
||||
|
||||
//Fetch from website API
|
||||
static Future<FreezerVersions> fetch() async {
|
||||
http.Response response = await http.get('https://freezer.life/api/versions');
|
||||
return FreezerVersions.fromJson(jsonDecode(response.body));
|
||||
}
|
||||
|
||||
static Future checkUpdate() async {
|
||||
//Check only each 24h
|
||||
int updateDelay = 86400000;
|
||||
if ((DateTime.now().millisecondsSinceEpoch - (cache.lastUpdateCheck??0)) < updateDelay) return;
|
||||
cache.lastUpdateCheck = DateTime.now().millisecondsSinceEpoch;
|
||||
await cache.save();
|
||||
|
||||
FreezerVersions versions = await FreezerVersions.fetch();
|
||||
|
||||
//Load current version
|
||||
PackageInfo info = await PackageInfo.fromPlatform();
|
||||
if (info.version == versions.latest) return;
|
||||
|
||||
//Get architecture
|
||||
String _arch = await DownloadManager.platform.invokeMethod("arch");
|
||||
if (_arch == 'armv8l')
|
||||
_arch = 'arm32';
|
||||
//Check compatible architecture
|
||||
if (versions.versions[0].downloads.firstWhere((d) => d.version.toLowerCase().contains(_arch.toLowerCase()), orElse: () => null) == null) return;
|
||||
|
||||
//Show notification
|
||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||
const AndroidInitializationSettings androidInitializationSettings = AndroidInitializationSettings('drawable/ic_logo');
|
||||
final InitializationSettings initializationSettings = InitializationSettings(androidInitializationSettings, null);
|
||||
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
||||
AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails('freezerupdates', 'Freezer Updates'.i18n, 'Freezer Updates'.i18n);
|
||||
NotificationDetails notificationDetails = NotificationDetails(androidNotificationDetails, null);
|
||||
await flutterLocalNotificationsPlugin.show(0, 'New update available!'.i18n, 'Update to latest version in the settings.'.i18n, notificationDetails);
|
||||
}
|
||||
}
|
||||
|
||||
class FreezerVersion {
|
||||
String version;
|
||||
String changelog;
|
||||
List<FreezerDownload> downloads;
|
||||
|
||||
FreezerVersion({this.version, this.changelog, this.downloads});
|
||||
|
||||
factory FreezerVersion.fromJson(Map data) => FreezerVersion(
|
||||
version: data['version'],
|
||||
changelog: data['changelog'],
|
||||
downloads: data['downloads'].map<FreezerDownload>((d) => FreezerDownload.fromJson(d)).toList()
|
||||
);
|
||||
}
|
||||
|
||||
class FreezerDownload {
|
||||
String version;
|
||||
String directUrl;
|
||||
|
||||
FreezerDownload({this.version, this.directUrl});
|
||||
|
||||
factory FreezerDownload.fromJson(Map data) => FreezerDownload(
|
||||
version: data['version'],
|
||||
directUrl: data['links'].first['url']
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue