Skip to content

Commit

Permalink
Minor fixes for uninitialized variable. Merged offline and online tra…
Browse files Browse the repository at this point in the history
…cks, albums and playlists. Changed favorite thumb. Fixed offline favoriteplaylist dual appearance when downloaded.
  • Loading branch information
PetitPrinc3 committed Nov 30, 2024
1 parent 07d6053 commit 8d8f231
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 195 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Latest Version](https://img.shields.io/github/v/release/PetitPrinc3/Deezer?color=blue)](../../releases/latest)
[![Release date](https://img.shields.io/github/release-date/PetitPrinc3/Deezer)](../../releases/latest)
[![Downloads Original](https://img.shields.io/github/downloads/DJDoubleD/ReFreezer/total?color=blue&label=ReFreezer%20downloads)](../../releases)
[![Downloads Refreezer](https://img.shields.io/github/downloads/DJDoubleD/ReFreezer/total?color=blue&label=ReFreezer%20downloads)](../../releases)
[![Downloads MOD](https://img.shields.io/github/downloads/PetitPrinc3/Deezer/total?color=blue&label=MOD%20downloads)](../../releases)
[![Flutter Version](https://shields.io/badge/Flutter-v3.24.4-darkgreen.svg)](https://docs.flutter.dev/tools/sdk)
[![Dart Version](https://shields.io/badge/Dart-v3.5.4-darkgreen.svg)](https://dart.dev/get-dart)
Expand Down Expand Up @@ -71,12 +71,14 @@ This branch focuses on the development of this app while the ReFreezer_Skin bran
- If queue is cleared and player bar is dismissed, it will not be brought back up if the user clicks back on the formerly playing track.
- Lyrics are re-fetched from api each time the player is brought back. This is because the API does not include informations regarding the lyrics in the track model.
- Player bar does not always update its color on track tile tap or various other scenarios.
- App becomes laggy when queue is opened. Unable to diagnose yet...

### :building_construction: Upcoming features
- Merge offline tracks and online tracks under tracks (same for playlists, albums, etc.)
- Caching information to avoid reloading every time (eg. favorites screen)
- Turn the mod into a skin for the official refreezer app
- NavigationRail for landscape mode on left side of screen
- Deezer "playing" animation instead of highlight
- Rebranding to "NotDeezer" ?

### :rocket: MOD Features :
- Floating player bar with background color based on title artwork
Expand Down
Binary file modified assets/favorites_thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion lib/api/download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,10 @@ class DownloadManager {

//Get all offline playlists
Future<List<Playlist>> getOfflinePlaylists() async {
List rawPlaylists = await db!.query('Playlists', columns: ['id']);
List rawPlaylists = await db!.query('Playlists',
columns: ['id'],
where: 'id != ?',
whereArgs: [deezerAPI.favoritesPlaylistId]);
List<Playlist> out = [];
for (Map rawPlaylist in rawPlaylists) {
var offlinePlayList = await getOfflinePlaylist(rawPlaylist['id']);
Expand Down
155 changes: 94 additions & 61 deletions lib/ui/details_screens.dart

Large diffs are not rendered by default.

172 changes: 46 additions & 126 deletions lib/ui/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ class _LibraryTracksState extends State<LibraryTracks> {
return;
}

if (mounted) setState(() => _isLoading = true);

if (await isConnected()) {
if (mounted) setState(() => _isLoading = true);
int pos = tracks.length;

if (tracks.isEmpty) {
Expand Down Expand Up @@ -394,6 +395,12 @@ class _LibraryTracksState extends State<LibraryTracks> {
_isLoadingTracks = false;
});
}
} else {
List<Track> offlineTracks = await _loadAllOffline();
setState(() {
tracks = List.from(offlineTracks);
_isLoading = false;
});
}
}

Expand Down Expand Up @@ -453,8 +460,6 @@ class _LibraryTracksState extends State<LibraryTracks> {
});

_load();
//Load all offline tracks
_loadAllOffline();

//Load sorting
int? index = Sorting.index(SortSourceTypes.TRACKS);
Expand All @@ -470,6 +475,31 @@ class _LibraryTracksState extends State<LibraryTracks> {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
floatingActionButton: ListenableBuilder(
listenable: playerBarState,
builder: (BuildContext context, Widget? child) {
return AnimatedPadding(
duration: Duration(milliseconds: 200),
padding:
EdgeInsets.only(bottom: playerBarState.state ? 80 : 20),
child: FloatingActionButton(
backgroundColor: Theme.of(context).primaryColor,
onPressed: () async {
//Add to offline
if (_playlist.user?.id != deezerAPI.userId) {
await deezerAPI.addPlaylist(_playlist.id!);
}
downloadManager.addOfflinePlaylist(_playlist,
private: true);
MenuSheet().showDownloadStartedToast();
},
child: Icon(
DeezerIcons.download,
size: 25,
)),
);
}),
appBar: FreezerAppBar(
'Tracks'.i18n,
actions: [
Expand Down Expand Up @@ -516,7 +546,7 @@ class _LibraryTracksState extends State<LibraryTracks> {
),
],
child: Icon(
Icons.sort,
DeezerIcons.sort,
size: 32.0,
semanticLabel: 'Sort'.i18n,
),
Expand All @@ -530,35 +560,6 @@ class _LibraryTracksState extends State<LibraryTracks> {
child: ListView(
controller: _scrollController,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
MakePlaylistOffline(_playlist),
TextButton(
child: Row(
children: <Widget>[
const Icon(
Icons.file_download,
size: 32.0,
),
Container(
width: 4,
),
Text('Download'.i18n)
],
),
onPressed: () async {
if (await downloadManager.addOfflinePlaylist(_playlist,
private: false) !=
false) {
MenuSheet().showDownloadStartedToast();
}
},
)
],
),
const FreezerDivider(),
//Loved tracks
...List.generate(tracks.length, (i) {
Track t = (tracks.length == (trackCount ?? 0))
Expand Down Expand Up @@ -598,35 +599,6 @@ class _LibraryTracksState extends State<LibraryTracks> {
)
],
),
const FreezerDivider(),
Text(
'All offline tracks'.i18n,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
Container(
height: 8,
),
...List.generate(allTracks.length, (i) {
Track t = allTracks[i];
return TrackTile(
t,
onTap: () {
GetIt.I<AudioPlayerHandler>().playFromTrackList(
allTracks,
t.id!,
QueueSource(
id: 'allTracks',
text: 'All offline tracks'.i18n,
source: 'offline'));
},
onHold: () {
MenuSheet m = MenuSheet();
m.defaultTrackMenu(t, context: context);
},
);
}),
ListenableBuilder(
listenable: playerBarState,
builder: (BuildContext context, Widget? child) {
Expand All @@ -652,13 +624,12 @@ class _LibraryAlbumsState extends State<LibraryAlbums> {
Sorting _sort = Sorting(sourceType: SortSourceTypes.ALBUMS);
final ScrollController _scrollController = ScrollController();

Future<List<Album>> _loadOnlineAlbums() async {
if (settings.offlineMode) return [];
return await deezerAPI.getAlbums();
}

Future<List<Album>> _loadOfflineAlbums() async {
return await downloadManager.getOfflineAlbums();
Future<List<Album>> _loadAlbums() async {
if (await isConnected()) {
return await deezerAPI.getAlbums();
} else {
return await downloadManager.getOfflineAlbums();
}
}

Future _reverse() async {
Expand Down Expand Up @@ -744,14 +715,9 @@ class _LibraryAlbumsState extends State<LibraryAlbums> {
children: <Widget>[
Container(height: 8.0),
AlbumList(
loadAlbums: _loadOnlineAlbums,
loadAlbums: _loadAlbums,
sort: _sort,
),
AlbumList(
loadAlbums: _loadOfflineAlbums,
sort: _sort,
offline: true,
),
ListenableBuilder(
listenable: playerBarState,
builder: (BuildContext context, Widget? child) {
Expand Down Expand Up @@ -1118,7 +1084,11 @@ class _LibraryPlaylistsState extends State<LibraryPlaylists> {
}

Future _load() async {
if (!settings.offlineMode) {
List<Playlist> offlinePlaylists =
await downloadManager.getOfflinePlaylists();
if (mounted) setState(() => _playlists = offlinePlaylists);

if (await isConnected()) {
try {
List<Playlist> playlists = await deezerAPI.getPlaylists();
if (mounted) setState(() => _playlists = playlists);
Expand Down Expand Up @@ -1294,56 +1264,6 @@ class _LibraryPlaylistsState extends State<LibraryPlaylists> {
},
);
}),

FutureBuilder(
future: downloadManager.getOfflinePlaylists(),
builder: (context, snapshot) {
if (snapshot.hasError || !snapshot.hasData) {
return const SizedBox(
height: 0,
width: 0,
);
}
if (!snapshot.hasData || snapshot.data!.isEmpty) {
return const SizedBox(
height: 0,
width: 0,
);
}

List<Playlist> playlists = snapshot.data!;
return Column(
children: <Widget>[
const FreezerDivider(),
Text(
'Offline playlists'.i18n,
textAlign: TextAlign.center,
style: const 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();
m.defaultPlaylistMenu(p, context: context,
onRemove: () {
setState(() {
playlists.remove(p);
_playlists!.remove(p);
});
});
},
);
})
],
);
},
),
ListenableBuilder(
listenable: playerBarState,
builder: (BuildContext context, Widget? child) {
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MenuSheet {
padding: EdgeInsets.symmetric(vertical: 12.0),
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
color: scaffoldBackgroundColor,
color: Theme.of(context).scaffoldBackgroundColor,
border: Border.all(color: Colors.transparent),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(18),
Expand Down Expand Up @@ -87,7 +87,7 @@ class MenuSheet {
padding: EdgeInsets.symmetric(vertical: 12.0),
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
color: scaffoldBackgroundColor,
color: Theme.of(context).scaffoldBackgroundColor,
border: Border.all(color: Colors.transparent),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(18),
Expand Down
1 change: 0 additions & 1 deletion lib/ui/player_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_it/get_it.dart';
import 'package:logging/logging.dart';
import 'package:palette_generator/palette_generator.dart';
import 'package:refreezer/fonts/deezer_icons.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/player_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
end: Alignment.bottomCenter,
colors: [
palette.dominantColor!.color.withOpacity(0.7),
Settings.deezerBg
scaffoldBackgroundColor
],
stops: const [
0.0,
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/connectivity.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:refreezer/settings.dart';

Future<bool> isConnected() async {
List<ConnectivityResult> connectivity =
await Connectivity().checkConnectivity();

if (connectivity.isNotEmpty &&
!connectivity.contains(ConnectivityResult.none)) {
!connectivity.contains(ConnectivityResult.none) &&
!settings.offlineMode) {
return true;
} else {
return false;
Expand Down

0 comments on commit 8d8f231

Please sign in to comment.