From b70b275e4494b8ccaa5e834972da54df2b6e58b0 Mon Sep 17 00:00:00 2001 From: Frederik Feichtmeier Date: Sun, 25 Aug 2024 13:22:32 +0200 Subject: [PATCH] fix: reduce radio history repaint and minimize streams (#892) --- lib/library/library_model.dart | 50 +------- lib/library/library_service.dart | 116 ++++++------------ lib/player/player_model.dart | 69 ++--------- lib/player/player_service.dart | 86 ++++--------- lib/player/view/bottom_player_image.dart | 2 +- lib/player/view/full_height_player_image.dart | 4 +- lib/player/view/shuffle_button.dart | 3 +- lib/radio/view/radio_history_list.dart | 29 +++-- .../view/radio_page_copy_histoy_button.dart | 4 +- lib/settings/settings_model.dart | 41 +------ lib/settings/settings_service.dart | 52 ++------ 11 files changed, 111 insertions(+), 345 deletions(-) diff --git a/lib/library/library_model.dart b/lib/library/library_model.dart index 9533b84dd..d7c9a1164 100644 --- a/lib/library/library_model.dart +++ b/lib/library/library_model.dart @@ -12,45 +12,14 @@ class LibraryModel extends SafeChangeNotifier { LibraryModel(this._service); final LibraryService _service; - StreamSubscription? _likedAudiosSub; - StreamSubscription? _playlistsSub; - StreamSubscription? _albumsSub; - StreamSubscription? _podcastsSub; - StreamSubscription? _stationsSub; - StreamSubscription? _updatesChangedSub; - StreamSubscription? _favTagsSub; - StreamSubscription? _favCountriesSub; - StreamSubscription? _favLanguageCodeFavsSub; - StreamSubscription? _lastCountryCodeSub; - StreamSubscription? _downloadsSub; - StreamSubscription? _ascendingPodcastsSub; + StreamSubscription? _propertiesChangedSub; Future init() async { await _service.init(); _pageIdStack.add(_service.selectedPageId ?? kSearchPageId); - _likedAudiosSub ??= - _service.likedAudiosChanged.listen((event) => notifyListeners()); - _playlistsSub ??= - _service.playlistsChanged.listen((event) => notifyListeners()); - _albumsSub = _service.albumsChanged.listen((event) => notifyListeners()); - _podcastsSub ??= - _service.podcastsChanged.listen((event) => notifyListeners()); - _stationsSub ??= - _service.starredStationsChanged.listen((event) => notifyListeners()); - _updatesChangedSub ??= - _service.updatesChanged.listen((_) => notifyListeners()); - _favTagsSub ??= _service.favTagsChanged.listen((_) => notifyListeners()); - _favCountriesSub ??= - _service.favCountriesChanged.listen((_) => notifyListeners()); - _favLanguageCodeFavsSub ??= - _service.favLanguagesChanged.listen((_) => notifyListeners()); - _downloadsSub ??= - _service.downloadsChanged.listen((_) => notifyListeners()); - _lastCountryCodeSub ??= - _service.lastCountryCodeChanged.listen((_) => notifyListeners()); - _ascendingPodcastsSub ??= - _service.ascendingPodcastsChanged.listen((_) => notifyListeners()); + _propertiesChangedSub ??= + _service.propertiesChanged.listen((_) => notifyListeners()); notifyListeners(); return true; @@ -58,18 +27,7 @@ class LibraryModel extends SafeChangeNotifier { @override Future dispose() async { - await _likedAudiosSub?.cancel(); - await _playlistsSub?.cancel(); - await _albumsSub?.cancel(); - await _podcastsSub?.cancel(); - await _stationsSub?.cancel(); - await _updatesChangedSub?.cancel(); - await _favTagsSub?.cancel(); - await _favCountriesSub?.cancel(); - await _favLanguageCodeFavsSub?.cancel(); - await _downloadsSub?.cancel(); - await _lastCountryCodeSub?.cancel(); - await _ascendingPodcastsSub?.cancel(); + await _propertiesChangedSub?.cancel(); super.dispose(); } diff --git a/lib/library/library_service.dart b/lib/library/library_service.dart index bff12939d..e97795bf2 100644 --- a/lib/library/library_service.dart +++ b/lib/library/library_service.dart @@ -16,20 +16,21 @@ class LibraryService { final SharedPreferences _sharedPreferences; + final _propertiesChangedController = StreamController.broadcast(); + Stream get propertiesChanged => _propertiesChangedController.stream; + // // Liked Audios // List