From d3602201c63cdd3e7c3e244a976275a39b558d4d Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Fri, 27 Mar 2026 13:04:49 +0100 Subject: [PATCH] refactor: remove dead code --- lib/models/plex_video_playback_data.dart | 3 -- lib/providers/playback_state_provider.dart | 32 ++++--------- lib/services/plex_client.dart | 55 ---------------------- lib/services/settings_service.dart | 9 ---- lib/widgets/download_tree_view.dart | 4 -- 5 files changed, 9 insertions(+), 94 deletions(-) diff --git a/lib/models/plex_video_playback_data.dart b/lib/models/plex_video_playback_data.dart index 11c68382..bde84b61 100644 --- a/lib/models/plex_video_playback_data.dart +++ b/lib/models/plex_video_playback_data.dart @@ -28,7 +28,4 @@ class PlexVideoPlaybackData { /// Returns true if media info is available bool get hasMediaInfo => mediaInfo != null; - - /// Returns true if there are multiple media versions available - bool get hasMultipleVersions => availableVersions.length > 1; } diff --git a/lib/providers/playback_state_provider.dart b/lib/providers/playback_state_provider.dart index 1468e5db..531741c9 100644 --- a/lib/providers/playback_state_provider.dart +++ b/lib/providers/playback_state_provider.dart @@ -3,13 +3,6 @@ import '../models/plex_metadata.dart'; import '../models/play_queue_response.dart'; import '../services/plex_client.dart'; -/// Playback mode types -/// -/// All playback now uses Plex play queues. -enum PlaybackMode { - playQueue, // Play queue-based playback (sequential, shuffle, playlists, collections) -} - /// Result of trying to locate the current queue index. class _IndexLookupResult { final int? index; @@ -32,24 +25,20 @@ class PlaybackStateProvider with ChangeNotifier { List _loadedItems = []; final int _windowSize = 50; // Number of items to keep in memory - // Legacy state for backward compatibility String? _contextKey; // The show/season/playlist ratingKey for this session - PlaybackMode? _playbackMode; + bool _isQueueMode = false; // Client reference for loading more items PlexClient? _client; - /// Current playback mode (null if no queue active) - PlaybackMode? get playbackMode => _playbackMode; - /// Whether shuffle mode is currently active bool get isShuffleActive => _playQueueShuffled; /// Whether playlist/collection mode is currently active - bool get isPlaylistActive => _playbackMode == PlaybackMode.playQueue; + bool get isPlaylistActive => _isQueueMode; /// Whether any queue-based playback is active - bool get isQueueActive => _playQueueId != null && _playbackMode == PlaybackMode.playQueue; + bool get isQueueActive => _playQueueId != null && _isQueueMode; /// The context key (show/season/playlist ratingKey) for the current session String? get shuffleContextKey => _contextKey; @@ -63,9 +52,6 @@ class PlaybackStateProvider with ChangeNotifier { /// The current play queue item ID int? get currentPlayQueueItemID => _currentPlayQueueItemID; - /// Total number of items in the play queue - int get queueLength => _playQueueTotalCount; - /// Set the client reference for loading more items void setClient(PlexClient client) { _client = client; @@ -73,7 +59,7 @@ class PlaybackStateProvider with ChangeNotifier { /// Update the current play queue item when playing a new item void setCurrentItem(PlexMetadata metadata) { - if (_playbackMode == PlaybackMode.playQueue && metadata.playQueueItemID != null) { + if (_isQueueMode && metadata.playQueueItemID != null) { _currentPlayQueueItemID = metadata.playQueueItemID; notifyListeners(); } @@ -92,7 +78,7 @@ class PlaybackStateProvider with ChangeNotifier { _loadedItems = playQueue.items ?? []; _contextKey = contextKey; - _playbackMode = PlaybackMode.playQueue; + _isQueueMode = true; notifyListeners(); } @@ -132,7 +118,7 @@ class PlaybackStateProvider with ChangeNotifier { } Future<_IndexLookupResult> _getCurrentIndex({bool loadIfMissing = false}) async { - if (_playbackMode != PlaybackMode.playQueue || _loadedItems.isEmpty || _currentPlayQueueItemID == null) { + if (!_isQueueMode || _loadedItems.isEmpty || _currentPlayQueueItemID == null) { return const _IndexLookupResult(); } @@ -164,7 +150,7 @@ class PlaybackStateProvider with ChangeNotifier { /// Returns null if queue is exhausted or current item is not in queue. /// [loopQueue] - If true, restart from beginning when queue is exhausted Future getNextEpisode(String currentItemKey, {bool loopQueue = false}) async { - if (_playbackMode != PlaybackMode.playQueue) { + if (!_isQueueMode) { // For sequential mode, let the video player handle next episode return null; } @@ -221,7 +207,7 @@ class PlaybackStateProvider with ChangeNotifier { /// Gets the previous item in the playback queue. /// Returns null if at the beginning of the queue or current item is not in queue. Future getPreviousEpisode(String currentItemKey) async { - if (_playbackMode != PlaybackMode.playQueue) { + if (!_isQueueMode) { // For sequential mode, let the video player handle previous episode return null; } @@ -262,7 +248,7 @@ class PlaybackStateProvider with ChangeNotifier { _currentPlayQueueItemID = null; _loadedItems = []; _contextKey = null; - _playbackMode = null; + _isQueueMode = false; notifyListeners(); } } diff --git a/lib/services/plex_client.dart b/lib/services/plex_client.dart index f4ec93e1..69e87e83 100644 --- a/lib/services/plex_client.dart +++ b/lib/services/plex_client.dart @@ -315,15 +315,6 @@ class PlexClient { } } - /// Update the token used by this client - void updateToken(String newToken) { - // Update both the Dio headers and the config to ensure consistency - _dio.options.headers['X-Plex-Token'] = newToken; - config = config.copyWith(token: newToken); - LogRedactionManager.registerToken(newToken); - appLogger.d('PlexClient token updated (headers and config)'); - } - /// Update endpoint priority list and optionally hop to the new best endpoint. Future updateEndpointPreferences(List prioritizedEndpoints, {bool switchToFirst = false}) async { if (_endpointManager == null || prioritizedEndpoints.isEmpty) { @@ -1058,36 +1049,6 @@ class PlexClient { []; } - /// Get all unwatched episodes for a TV show across all seasons - Future> getAllUnwatchedEpisodes(String showRatingKey) async { - final allEpisodes = []; - - // Get all seasons for the show - final seasons = await getChildren(showRatingKey); - - // Get episodes from each season - for (final season in seasons) { - if (season.isSeason) { - final episodes = await getChildren(season.ratingKey); - - // Filter for unwatched episodes - final unwatchedEpisodes = episodes.where((ep) => ep.isEpisode && (ep.viewCount ?? 0) == 0).toList(); - - allEpisodes.addAll(unwatchedEpisodes); - } - } - - return allEpisodes; - } - - /// Get all unwatched episodes in a specific season - Future> getUnwatchedEpisodesInSeason(String seasonRatingKey) async { - final episodes = await getChildren(seasonRatingKey); - - // Filter for unwatched episodes - return episodes.where((ep) => ep.isEpisode && (ep.viewCount ?? 0) == 0).toList(); - } - /// Get thumbnail URL String getThumbnailUrl(String? thumbPath) { if (thumbPath == null || thumbPath.isEmpty) return ''; @@ -1384,12 +1345,6 @@ class PlexClient { return _wrapBoolApiCall(() => _dio.delete('/library/metadata/$ratingKey'), 'Failed to delete media item'); } - /// Get server preferences - Future> getServerPreferences() async { - final response = await _dio.get('/:/prefs'); - return response.data; - } - /// Get preferences for a library section. /// /// Returns a map of setting id --> value for all settings in the library. @@ -1403,16 +1358,6 @@ class PlexClient { return {for (final s in list) s['id'] as String: s['value']}; } - /// Get sessions (currently playing) - Future> getSessions() async { - final response = await _dio.get('/status/sessions'); - final container = _getMediaContainer(response); - if (container != null && container['Metadata'] != null) { - return container['Metadata'] as List; - } - return []; - } - /// Get available filters for a library section Future> getLibraryFilters(String sectionId) async { if (sectionId == 'shared') return []; diff --git a/lib/services/settings_service.dart b/lib/services/settings_service.dart index 46039865..50d74757 100644 --- a/lib/services/settings_service.dart +++ b/lib/services/settings_service.dart @@ -761,15 +761,6 @@ class SettingsService extends BaseSharedPreferencesService { return preferences[seriesRatingKey]; } - /// Clear media version preference for a series - Future clearMediaVersionPreference(String seriesRatingKey) async { - final preferences = _getMediaVersionPreferences(); - preferences.remove(seriesRatingKey); - - final jsonString = json.encode(preferences); - await prefs.setString(_keyMediaVersionPreferences, jsonString); - } - /// Get all media version preferences Map _getMediaVersionPreferences() { final jsonString = prefs.getString(_keyMediaVersionPreferences); diff --git a/lib/widgets/download_tree_view.dart b/lib/widgets/download_tree_view.dart index 9a1f92b0..5e428df6 100644 --- a/lib/widgets/download_tree_view.dart +++ b/lib/widgets/download_tree_view.dart @@ -38,10 +38,6 @@ class DownloadTreeNode { return children.where((child) => child.status == DownloadStatus.completed).length; } - /// Get the number of downloading children - int get downloadingChildrenCount { - return children.where((child) => child.status == DownloadStatus.downloading).length; - } } /// Type of node in the download tree