Skip to content

Commit

Permalink
Added download indicator underneath TrackTiles. Fixed downloading of …
Browse files Browse the repository at this point in the history
…newly liked titles when favorite tracks playlist is offline.
  • Loading branch information
PetitPrinc3 committed Dec 20, 2024
1 parent bea2d23 commit e5f7f5e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ This repository originates from [ReFreezer](https://github.com/DJDoubleD/ReFreez
- Player bar does not always update its color on track tile tap or various other scenarios.
- Favorite tracks playlist id is not properly saved (no/minor UX consequences).
- Queue screen is laggy. This seems to be because of how the images are loaded.
- Tracks removed from playlist/favorites will not disappear immediately from the detailed screen.

#### :building_construction: Upcoming features
- Caching information to avoid reloading every time (eg. favorites screen)
- Turn the mod into a skin for the official refreezer app
- Deezer "playing" animation instead of highlight
- Download progress on track tiles

#### :rocket: Definitely Not Deezer Features :
- Floating player bar with background color based on title artwork
Expand Down
5 changes: 5 additions & 0 deletions lib/api/deezer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:math';

import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:refreezer/api/download.dart';

import '../api/definitions.dart';
import '../api/spotify.dart';
Expand Down Expand Up @@ -295,6 +296,10 @@ class DeezerAPI {
//Add track to favorites
Future addFavoriteTrack(String id) async {
await callGwApi('favorite_song.add', params: {'SNG_ID': id});
if (await downloadManager.checkOffline(
playlist: Playlist(id: favoritesPlaylistId))) {
downloadManager.updateOfflinePlaylist(Playlist(id: favoritesPlaylistId));
}
}

//Add album to favorites/library
Expand Down
19 changes: 11 additions & 8 deletions lib/api/download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,19 @@ class DownloadManager {
List<Map> out = [];
for (int i = 0; i < toDowload.length; i++) {
Track t = toDowload[i];
out.add(await Download.jsonFromTrack(
String tPath = _generatePath(
t,
_generatePath(
true,
playlistName: playlist.title,
playlistTrackNumber: i,
);
if (!(await File(tPath).exists())) {
out.add(await Download.jsonFromTrack(
t,
true,
playlistName: playlist.title,
playlistTrackNumber: i,
),
private: true,
));
tPath,
private: true,
));
}
}
await platform.invokeMethod('addDownloads', out);
await start();
Expand Down
1 change: 0 additions & 1 deletion lib/ui/details_screens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get_it/get_it.dart';
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
import 'package:refreezer/fonts/deezer_icons.dart';
import 'package:refreezer/main.dart';
import 'package:refreezer/settings.dart';
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ class _LibraryTracksState extends State<LibraryTracks> {
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!));
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,6 @@ class _SearchScreenState extends State<SearchScreen> {
},
trailing: _removeHistoryItemWidget(i),
);
default:
return Container();
}
}),

Expand Down
43 changes: 41 additions & 2 deletions lib/ui/tiles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ class TrackTile extends StatefulWidget {

class _TrackTileState extends State<TrackTile> {
StreamSubscription? _mediaItemSub;
StreamSubscription? _downloadItemSub;
bool _isOffline = false;
bool nowPlaying = false;
bool nowDownloading = false;
double downloadProgress = 0.0;
double downloadProgress = 0;

/*bool get nowPlaying {
if (GetIt.I<AudioPlayerHandler>().mediaItem.value == null) return false;
Expand All @@ -58,12 +59,49 @@ class _TrackTileState extends State<TrackTile> {
}
});

//Listen to download change to drop progress indicator
_downloadItemSub = downloadManager.serviceEvents.stream.listen((e) async {
List<Download> downloads = await downloadManager.getDownloads();

if (e['action'] == 'onProgress') {
setState(() {
for (Map su in e['data']) {
downloads
.firstWhere((d) => d.id == su['id'], orElse: () => Download())
.updateFromJson(su);
}
});
}

for (int i = 0; i < downloads.length; i++) {
if (downloads[i].trackId == widget.track.id) {
if (downloads[i].state != DownloadState.DONE) {
if (mounted) {
setState(() {
nowDownloading = true;
downloadProgress = downloads[i].progress;
Logger.root.info(downloadProgress);
});
}
} else {
if (mounted) {
setState(() {
nowDownloading = false;
_isOffline = true;
});
}
}
}
}
});

super.initState();
}

@override
void dispose() {
_mediaItemSub?.cancel();
_downloadItemSub?.cancel();
super.dispose();
}

Expand Down Expand Up @@ -124,7 +162,8 @@ class _TrackTileState extends State<TrackTile> {
LinearProgressIndicator(
value: downloadProgress,
color: Colors.green.shade400,
minHeight: 1.0,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
minHeight: 1,
)
]);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.7.16+2
version: 0.7.17+2

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down

0 comments on commit e5f7f5e

Please sign in to comment.