From c369f2c3d707cc879832692364451fed152f9b95 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Thu, 16 Apr 2026 08:14:42 +0200 Subject: [PATCH] refactor: remove dead code across codebase --- lib/models/plex_file_info.dart | 2 - lib/providers/download_provider.dart | 14 ---- lib/providers/settings_provider.dart | 11 --- lib/screens/discover_screen.dart | 4 +- lib/screens/main_screen.dart | 2 +- lib/services/display_mode_service.dart | 1 - lib/services/plex_client.dart | 99 -------------------------- lib/utils/focus_utils.dart | 31 -------- lib/utils/formatters.dart | 16 ----- 9 files changed, 2 insertions(+), 178 deletions(-) diff --git a/lib/models/plex_file_info.dart b/lib/models/plex_file_info.dart index cc68593a..eddbe553 100644 --- a/lib/models/plex_file_info.dart +++ b/lib/models/plex_file_info.dart @@ -27,7 +27,6 @@ class PlexFileInfo { final String? colorSpace; final String? colorRange; final String? colorPrimaries; - final String? colorTrc; final String? chromaSubsampling; final double? frameRate; final int? bitDepth; @@ -59,7 +58,6 @@ class PlexFileInfo { this.colorSpace, this.colorRange, this.colorPrimaries, - this.colorTrc, this.chromaSubsampling, this.frameRate, this.bitDepth, diff --git a/lib/providers/download_provider.dart b/lib/providers/download_provider.dart index 1e5a7e1b..7fc7687d 100644 --- a/lib/providers/download_provider.dart +++ b/lib/providers/download_provider.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:io'; -import 'dart:collection'; import 'package:flutter/foundation.dart'; import 'package:plezy/utils/content_utils.dart'; import '../models/download_models.dart'; @@ -450,13 +449,6 @@ class DownloadProvider extends ChangeNotifier { ); } - /// Whether there are any downloads (active or completed) - bool get hasDownloads => _downloads.isNotEmpty; - - /// Whether there are any active downloads - bool get hasActiveDownloads => - _downloads.values.any((p) => p.status == DownloadStatus.downloading || p.status == DownloadStatus.queued); - /// Get download progress for a specific item /// For shows/seasons, returns aggregate progress of all child episodes /// For episodes/movies, returns direct progress @@ -947,15 +939,9 @@ class DownloadProvider extends ChangeNotifier { notifyListeners(); } - /// Check if an item is being deleted - bool isDeleting(String globalKey) => _deletionProgress.containsKey(globalKey); - /// Get deletion progress for an item DeletionProgress? getDeletionProgress(String globalKey) => _deletionProgress[globalKey]; - /// Get all items currently being deleted - UnmodifiableMapView get deletionProgress => UnmodifiableMapView(_deletionProgress); - /// Refresh the downloads list from database Future refresh() async { await _loadPersistedDownloads(); diff --git a/lib/providers/settings_provider.dart b/lib/providers/settings_provider.dart index 4d36cae1..cb46f3ab 100644 --- a/lib/providers/settings_provider.dart +++ b/lib/providers/settings_provider.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import '../i18n/strings.g.dart'; import '../services/settings_service.dart'; class SettingsProvider extends ChangeNotifier { @@ -162,14 +161,4 @@ class SettingsProvider extends ChangeNotifier { persist: _settingsService!.setAutoHidePerformanceOverlay, ); - String get episodePosterModeDisplayName { - switch (_episodePosterMode) { - case EpisodePosterMode.seriesPoster: - return t.settings.seriesPoster; - case EpisodePosterMode.seasonPoster: - return t.settings.seasonPoster; - case EpisodePosterMode.episodeThumbnail: - return t.settings.episodeThumbnail; - } - } } diff --git a/lib/screens/discover_screen.dart b/lib/screens/discover_screen.dart index 779ca5db..b7c28c64 100644 --- a/lib/screens/discover_screen.dart +++ b/lib/screens/discover_screen.dart @@ -49,9 +49,7 @@ import '../widgets/companion_remote/remote_session_dialog.dart'; import 'companion_remote/mobile_remote_screen.dart'; class DiscoverScreen extends StatefulWidget { - final VoidCallback? onBecameVisible; - - const DiscoverScreen({super.key, this.onBecameVisible}); + const DiscoverScreen({super.key}); @override State createState() => _DiscoverScreenState(); diff --git a/lib/screens/main_screen.dart b/lib/screens/main_screen.dart index 433866c7..965feaa6 100644 --- a/lib/screens/main_screen.dart +++ b/lib/screens/main_screen.dart @@ -567,7 +567,7 @@ class _MainScreenState extends State with RouteAware, WindowListener return [ for (final tab in _getVisibleTabs(offline)) switch (tab.id) { - NavigationTabId.discover => DiscoverScreen(key: _discoverKey, onBecameVisible: _onDiscoverBecameVisible), + NavigationTabId.discover => DiscoverScreen(key: _discoverKey), NavigationTabId.libraries => LibrariesScreen(key: _librariesKey, onLibraryOrderChanged: _onLibraryOrderChanged), NavigationTabId.liveTv => LiveTvScreen(key: _liveTvKey), NavigationTabId.search => SearchScreen(key: _searchKey), diff --git a/lib/services/display_mode_service.dart b/lib/services/display_mode_service.dart index 28f1b91e..8d1ef03d 100644 --- a/lib/services/display_mode_service.dart +++ b/lib/services/display_mode_service.dart @@ -17,7 +17,6 @@ class DisplayModeService { bool _displayModeChanged = false; bool _hdrStateChanged = false; - bool get displayModeChanged => _displayModeChanged; bool get hdrStateChanged => _hdrStateChanged; bool get anyChangeApplied => _displayModeChanged || _hdrStateChanged; diff --git a/lib/services/plex_client.dart b/lib/services/plex_client.dart index 39da8daf..22ed518f 100644 --- a/lib/services/plex_client.dart +++ b/lib/services/plex_client.dart @@ -1327,7 +1327,6 @@ class PlexClient { colorSpace: videoStream?['colorSpace'] as String?, colorRange: videoStream?['colorRange'] as String?, colorPrimaries: videoStream?['colorPrimaries'] as String?, - colorTrc: videoStream?['colorTrc'] as String?, chromaSubsampling: videoStream?['chromaSubsampling'] as String?, frameRate: (videoStream?['frameRate'] as num?)?.toDouble(), bitDepth: videoStream?['bitDepth'] as int?, @@ -1804,31 +1803,6 @@ class PlexClient { return result; } - /// Clear all items from a playlist - Future clearPlaylist(String playlistId) { - return _wrapBoolApiCall(() => _http.delete('/playlists/$playlistId/items'), 'Failed to clear playlist'); - } - - /// Update playlist metadata (e.g., title, summary) - /// Uses the same metadata editing mechanism as other items - Future updatePlaylist({required String playlistId, String? title, String? summary}) { - final queryParams = {'type': 'playlist', 'id': playlistId}; - - if (title != null) { - queryParams['title.value'] = title; - queryParams['title.locked'] = '1'; - } - if (summary != null) { - queryParams['summary.value'] = summary; - queryParams['summary.locked'] = '1'; - } - - return _wrapBoolApiCall( - () => _http.put('/library/metadata/$playlistId', queryParameters: queryParams), - 'Failed to update playlist', - ); - } - // ============================================================================ // Metadata Editing Methods // ============================================================================ @@ -2122,23 +2096,6 @@ class PlexClient { } } - /// Shuffle a play queue - /// The currently selected item is maintained - Future shufflePlayQueue(int playQueueId) async { - try { - final response = await _http.put('/playQueues/$playQueueId/shuffle'); - return PlayQueueResponse.fromJson(response.data); - } catch (e) { - appLogger.e('Failed to shuffle play queue: $e'); - return null; - } - } - - /// Clear all items from a play queue - Future clearPlayQueue(int playQueueId) { - return _wrapBoolApiCall(() => _http.delete('/playQueues/$playQueueId/items'), 'Failed to clear play queue'); - } - /// Create a play queue for a TV show (all episodes) /// /// This is a convenience method that creates a play queue from a show's URI. @@ -2305,62 +2262,6 @@ class PlexClient { await _getWithFailover('/library/sections/$sectionId/analyze'); } - // ============================================================================ - // Library Statistics Methods - // ============================================================================ - - /// Get total item count for a library section efficiently. - /// Uses X-Plex-Container-Size: 1 to get totalSize with minimal data transfer. - Future getLibraryTotalCount(String sectionId) async { - try { - final response = await _getWithFailover( - '/library/sections/$sectionId/all', - queryParameters: {'X-Plex-Container-Start': 0, 'X-Plex-Container-Size': 1}, - ); - final container = _getMediaContainer(response); - // Try totalSize first, fall back to size if not available - return container?['totalSize'] as int? ?? container?['size'] as int? ?? 0; - } catch (e) { - appLogger.e('Failed to get library total count: $e'); - return 0; - } - } - - /// Get total episode count for a TV show library. - /// Uses the allLeaves endpoint to count all episodes. - Future getLibraryEpisodeCount(String sectionId) async { - try { - final response = await _getWithFailover( - '/library/sections/$sectionId/allLeaves', - queryParameters: {'X-Plex-Container-Start': 0, 'X-Plex-Container-Size': 1}, - ); - final container = _getMediaContainer(response); - return container?['totalSize'] as int? ?? container?['size'] as int? ?? 0; - } catch (e) { - appLogger.e('Failed to get library episode count: $e'); - return 0; - } - } - - /// Get watch history count for a time period. - /// [since] - Optional DateTime to filter history from this date onwards. - /// Returns the total count of items watched. - Future getWatchHistoryCount({DateTime? since}) async { - try { - final queryParams = {'X-Plex-Container-Start': 0, 'X-Plex-Container-Size': 1}; - if (since != null) { - final epochSeconds = since.millisecondsSinceEpoch ~/ 1000; - queryParams['viewedAt>'] = epochSeconds; - } - final response = await _getWithFailover('/status/sessions/history/all', queryParameters: queryParams); - final container = _getMediaContainer(response); - return container?['totalSize'] as int? ?? container?['size'] as int? ?? 0; - } catch (e) { - appLogger.e('Failed to get watch history count: $e'); - return 0; - } - } - // ============================================================================ // Live TV / DVR Methods // ============================================================================ diff --git a/lib/utils/focus_utils.dart b/lib/utils/focus_utils.dart index 6de0d5b8..8e8b12b7 100644 --- a/lib/utils/focus_utils.dart +++ b/lib/utils/focus_utils.dart @@ -19,35 +19,4 @@ class FocusUtils { }); } - /// Execute a callback after the current frame completes, with mounted check. - /// The callback will only execute if the State is still mounted. - /// - /// Usage: - /// ```dart - /// FocusUtils.afterBuildIfMounted(this, () { - /// // do something - /// }); - /// ``` - static void afterBuildIfMounted(State state, VoidCallback callback) { - WidgetsBinding.instance.addPostFrameCallback((_) { - if (state.mounted) { - callback(); - } - }); - } - - /// Execute a callback after the current frame completes, without mounted check. - /// Use this when you don't need the mounted check or are managing it yourself. - /// - /// Usage: - /// ```dart - /// FocusUtils.afterBuild(() { - /// // do something - /// }); - /// ``` - static void afterBuild(VoidCallback callback) { - WidgetsBinding.instance.addPostFrameCallback((_) { - callback(); - }); - } } diff --git a/lib/utils/formatters.dart b/lib/utils/formatters.dart index 201169c9..0e0a5fb3 100644 --- a/lib/utils/formatters.dart +++ b/lib/utils/formatters.dart @@ -54,22 +54,6 @@ class ByteFormatter { return '${(kbps / 1000).toStringAsFixed(1)} Mbps'; } - /// Format bitrate in bps to human-readable string - /// - /// [bps] The bitrate in bits per second - /// Returns formatted string like "8.5 Mbps", "256 Kbps", or "128 bps" - static String formatBitrateBps(int bps) { - const kbps = 1000; - const mbps = kbps * 1000; - - if (bps >= mbps) { - return '${(bps / mbps).toStringAsFixed(2)} Mbps'; - } else if (bps >= kbps) { - return '${(bps / kbps).toStringAsFixed(2)} Kbps'; - } else { - return '$bps bps'; - } - } } /// Formats a duration in human-readable textual format (e.g., "1h 23m" or "1 hour 23 minutes").