Skip to content

Commit

Permalink
fix: tmp. ignore podcast and episoes
Browse files Browse the repository at this point in the history
  • Loading branch information
phanan committed Jun 6, 2024
1 parent 35c0758 commit 3cf9d34
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 25 deletions.
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ List<SingleChildWidget> _providers = [
ChangeNotifierProvider(
create: (context) => DataProvider(
playlistProvider: context.read<PlaylistProvider>(),
songProvider: context.read<SongProvider>(),
),
),
ChangeNotifierProvider(
Expand Down
8 changes: 5 additions & 3 deletions lib/providers/data_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import 'package:version/version.dart';

class DataProvider with ChangeNotifier {
final PlaylistProvider _playlistProvider;
final SongProvider _songProvider;

DataProvider({required playlistProvider})
: _playlistProvider = playlistProvider;
DataProvider({required playlistProvider, required songProvider})
: _playlistProvider = playlistProvider,
_songProvider = songProvider;

Future<void> init() async {
final Map<String, dynamic> data = await get('data');
Expand All @@ -28,7 +30,7 @@ class DataProvider with ChangeNotifier {
if (data.containsKey('queue_state')) {
AppState.set(
['app', 'queueState'],
QueueState.parse(data['queue_state']),
QueueState.parse(data['queue_state'], _songProvider),
);
} else {
AppState.set(['app', 'queueState'], QueueState.empty());
Expand Down
11 changes: 3 additions & 8 deletions lib/providers/overview_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class OverviewProvider with ChangeNotifier, StreamSubscriber {

mostPlayedSongs
..clear()
..addAll(_parseSongsFromJson(response['most_played_songs']));
..addAll(_songProvider.parseFromJson(response['most_played_songs']));

recentlyAddedSongs
..clear()
..addAll(_parseSongsFromJson(response['recently_added_songs']));
..addAll(_songProvider.parseFromJson(response['recently_added_songs']));

recentlyPlayedSongs
..clear()
..addAll(_parseSongsFromJson(response['recently_played_songs']));
..addAll(_songProvider.parseFromJson(response['recently_played_songs']));

final _mostPlayedAlbums = response['most_played_albums']
.map<Album>((j) => Album.fromJson(j))
Expand All @@ -74,9 +74,4 @@ class OverviewProvider with ChangeNotifier, StreamSubscriber {

notifyListeners();
}

List<Song> _parseSongsFromJson(dynamic json) {
return _songProvider
.syncWithVault(json.map<Song>((j) => Song.fromJson(j)).toList());
}
}
9 changes: 8 additions & 1 deletion lib/providers/recently_played_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ class RecentlyPlayedProvider with ChangeNotifier, StreamSubscriber {

Future<List<Song>> fetch() async {
final res = await get('songs/recently-played');
final items = res.map<Song>((j) => Song.fromJson(j)).toList();
final items = <Song>[];

res.forEach((json) {
if (json['type'] == 'songs') {
items.add(Song.fromJson(json));
}
});

songs = _songProvider.syncWithVault(items);
_loaded = true;
notifyListeners();
Expand Down
19 changes: 13 additions & 6 deletions lib/providers/song_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@ class SongProvider with ChangeNotifier, StreamSubscriber {

Future<List<Song>> _stateAwareFetch(String url, Object cacheKey) async {
if (AppState.has(cacheKey)) return AppState.get(cacheKey);

final res = await get(url);
final items = res.map<Song>((json) => Song.fromJson(json)).toList();
AppState.set(cacheKey, items);

return syncWithVault(items);
return AppState.set(cacheKey, parseFromJson(await get(url)));
}

Future<List<Song>> fetchRandom({int limit = 500}) async {
Expand All @@ -129,6 +124,18 @@ class SongProvider with ChangeNotifier, StreamSubscriber {
final items = res.map<Song>((json) => Song.fromJson(json)).toList();
return syncWithVault(items);
}

List<Song> parseFromJson(dynamic json) {
final songs = <Song>[];

json.forEach((j) {
if (j['type'] == 'songs') {
songs.add(Song.fromJson(j));
}
});

return syncWithVault(songs).toList();
}
}

class SongPaginationConfig {
Expand Down
18 changes: 11 additions & 7 deletions lib/values/queue_state.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:app/models/models.dart';
import 'package:app/providers/providers.dart';

class QueueState {
List<Song> songs;
Expand All @@ -11,14 +12,17 @@ class QueueState {
this.playbackPosition = 0,
});

static parse(Map<String, dynamic> json) {
static parse(Map<String, dynamic> json, SongProvider songProvider) {
final songs = songProvider.parseFromJson(json['songs']);

var currentSong =
json['current_song'] != null && json['current_song']['type'] == 'songs'
? Song.fromJson(json['current_song'])
: null;

return QueueState(
songs: (json['songs'] as List<dynamic>)
.map<Song>((song) => Song.fromJson(song))
.toList(),
currentSong: json['current_song'] != null
? Song.fromJson(json['current_song'])
: null,
songs: songs,
currentSong: currentSong,
playbackPosition: json['playback_position'],
);
}
Expand Down

0 comments on commit 3cf9d34

Please sign in to comment.