@@ -6,18 +6,22 @@ import '../common/data/audio.dart';
6
6
import '../common/data/podcast_genre.dart' ;
7
7
import '../common/view/audio_filter.dart' ;
8
8
import '../common/view/languages.dart' ;
9
+ import '../library/library_service.dart' ;
9
10
import '../notifications/notifications_service.dart' ;
10
11
import '../settings/settings_service.dart' ;
11
12
import 'podcast_utils.dart' ;
12
13
13
14
class PodcastService {
14
15
final NotificationsService _notificationsService;
15
16
final SettingsService _settingsService;
17
+ final LibraryService _libraryService;
16
18
PodcastService ({
17
19
required NotificationsService notificationsService,
18
20
required SettingsService settingsService,
21
+ required LibraryService libraryService,
19
22
}) : _notificationsService = notificationsService,
20
- _settingsService = settingsService;
23
+ _settingsService = settingsService,
24
+ _libraryService = libraryService;
21
25
22
26
SearchResult ? _searchResult;
23
27
Search ? _search;
@@ -80,11 +84,11 @@ class PodcastService {
80
84
}
81
85
82
86
Future <void > updatePodcasts ({
83
- required Map <String , List <Audio >> oldPodcasts,
84
- required void Function (String name, List <Audio > audios) updatePodcast,
87
+ Map <String , List <Audio >>? oldPodcasts,
85
88
required String updateMessage,
89
+ Function ({required String message})? notify,
86
90
}) async {
87
- for (final old in oldPodcasts.entries) {
91
+ for (final old in ( oldPodcasts ?? _libraryService.podcasts) .entries) {
88
92
if (old.value.isNotEmpty) {
89
93
final list = old.value;
90
94
sortListByAudioFilter (
@@ -102,10 +106,14 @@ class PodcastService {
102
106
audios.firstOrNull? .year == firstOld.year ||
103
107
audios.isEmpty) return ;
104
108
105
- updatePodcast (old.key, audios);
106
- _notificationsService.notify (
107
- message: '$updateMessage ${firstOld .album ?? old .value }' ,
108
- );
109
+ _libraryService.updatePodcast (old.key, audios);
110
+ if (notify != null ) {
111
+ notify (message: '$updateMessage ${firstOld .album ?? old .value }' );
112
+ } else {
113
+ _notificationsService.notify (
114
+ message: '$updateMessage ${firstOld .album ?? old .value }' ,
115
+ );
116
+ }
109
117
});
110
118
}
111
119
}
0 commit comments