From eb143a41fc80859dc3d337c3176c39b9f784b0fa Mon Sep 17 00:00:00 2001 From: zarzet Date: Wed, 18 Mar 2026 01:12:16 +0700 Subject: [PATCH] refactor: remove redundant comments and fix setMetadataSource bug - Fix setMetadataSource always returning 'deezer' regardless of input parameter - Remove self-evident doc comments that restate method/class names across app_theme, dynamic_color_wrapper, cover_cache_manager, history_database, library_database, and download_service_picker - Remove stale migration inline notes (// 12 -> 16, // 20 -> 16, etc.) from app_theme - Remove trivial section-label comments in queue_tab batch conversion method - Remove duplicate 'wait up to 5 seconds' comment in main_shell --- lib/providers/settings_provider.dart | 3 +-- lib/screens/main_shell.dart | 1 - lib/screens/queue_tab.dart | 5 ---- lib/services/cover_cache_manager.dart | 2 -- lib/services/history_database.dart | 11 -------- lib/services/library_database.dart | 5 +--- lib/theme/app_theme.dart | 32 +++++++++--------------- lib/theme/dynamic_color_wrapper.dart | 3 --- lib/widgets/download_service_picker.dart | 2 -- 9 files changed, 14 insertions(+), 50 deletions(-) diff --git a/lib/providers/settings_provider.dart b/lib/providers/settings_provider.dart index 33706c57..fcab3631 100644 --- a/lib/providers/settings_provider.dart +++ b/lib/providers/settings_provider.dart @@ -406,8 +406,7 @@ class SettingsNotifier extends Notifier { } void setMetadataSource(String source) { - final normalized = source == 'deezer' ? 'deezer' : 'deezer'; - state = state.copyWith(metadataSource: normalized); + state = state.copyWith(metadataSource: source); _saveSettings(); } diff --git a/lib/screens/main_shell.dart b/lib/screens/main_shell.dart index 70c21461..0440a08c 100644 --- a/lib/screens/main_shell.dart +++ b/lib/screens/main_shell.dart @@ -83,7 +83,6 @@ class _MainShellState extends ConsumerState { final extState = ref.read(extensionProvider); if (!extState.isInitialized) { _log.d('Waiting for extensions to initialize before handling URL...'); - // Wait up to 5 seconds for extensions to initialize for (int i = 0; i < 50; i++) { await Future.delayed(const Duration(milliseconds: 100)); if (!mounted) return; diff --git a/lib/screens/queue_tab.dart b/lib/screens/queue_tab.dart index 26ba7861..18a78c16 100644 --- a/lib/screens/queue_tab.dart +++ b/lib/screens/queue_tab.dart @@ -5082,7 +5082,6 @@ class _QueueTabState extends ConsumerState { ); try { - // Read metadata from file final metadata = { 'TITLE': item.trackName, 'ARTIST': item.artistName, @@ -5111,7 +5110,6 @@ class _QueueTabState extends ConsumerState { 1000, ); - // Extract cover art String? coverPath; try { final tempDir = await getTemporaryDirectory(); @@ -5126,7 +5124,6 @@ class _QueueTabState extends ConsumerState { } } catch (_) {} - // Handle SAF vs regular file String workingPath = item.filePath; final isSaf = isContentUri(item.filePath); String? safTempPath; @@ -5139,7 +5136,6 @@ class _QueueTabState extends ConsumerState { workingPath = safTempPath; } - // Convert final newPath = await FFmpegService.convertAudioFormat( inputPath: workingPath, targetFormat: targetFormat.toLowerCase(), @@ -5149,7 +5145,6 @@ class _QueueTabState extends ConsumerState { deleteOriginal: !isSaf, ); - // Cleanup cover temp if (coverPath != null) { try { await File(coverPath).delete(); diff --git a/lib/services/cover_cache_manager.dart b/lib/services/cover_cache_manager.dart index 81cb6c06..0af65464 100644 --- a/lib/services/cover_cache_manager.dart +++ b/lib/services/cover_cache_manager.dart @@ -37,7 +37,6 @@ class CoverCacheManager { final appDir = await getApplicationSupportDirectory(); _cachePath = p.join(appDir.path, 'cover_cache'); - // Ensure cache directory exists await Directory(_cachePath!).create(recursive: true); debugPrint('CoverCacheManager: Initializing at $_cachePath'); @@ -48,7 +47,6 @@ class CoverCacheManager { debugPrint('CoverCacheManager: Initialized successfully'); } catch (e) { debugPrint('CoverCacheManager: Failed to initialize: $e'); - // Will fallback to DefaultCacheManager } } diff --git a/lib/services/history_database.dart b/lib/services/history_database.dart index 75bfaada..9e648bc7 100644 --- a/lib/services/history_database.dart +++ b/lib/services/history_database.dart @@ -12,7 +12,6 @@ final Future _prefs = SharedPreferences.getInstance(); /// Cached current iOS container path for path normalization String? _currentContainerPath; -/// SQLite database service for download history /// Provides O(1) lookups by spotify_id and isrc with proper indexing class HistoryDatabase { static final HistoryDatabase instance = HistoryDatabase._init(); @@ -78,7 +77,6 @@ class HistoryDatabase { ) '''); - // Indexes for fast lookups await db.execute('CREATE INDEX idx_spotify_id ON history(spotify_id)'); await db.execute('CREATE INDEX idx_isrc ON history(isrc)'); await db.execute( @@ -171,7 +169,6 @@ class HistoryDatabase { try { final db = await database; - // Get all items with iOS paths final rows = await db.query('history', columns: ['id', 'file_path']); int updatedCount = 0; final batch = db.batch(); @@ -198,7 +195,6 @@ class HistoryDatabase { await batch.commit(noResult: true); } - // Save current container path await prefs.setString('ios_last_container_path', _currentContainerPath!); _log.i('iOS path migration complete: $updatedCount paths updated'); @@ -323,7 +319,6 @@ class HistoryDatabase { }; } - /// Insert or update a history item Future upsert(Map json) async { final db = await database; await db.insert( @@ -345,7 +340,6 @@ class HistoryDatabase { return rows.map(_dbRowToJson).toList(); } - /// Get item by ID Future?> getById(String id) async { final db = await database; final rows = await db.query( @@ -403,26 +397,22 @@ class HistoryDatabase { return rows.map((r) => r['spotify_id'] as String).toSet(); } - /// Delete by ID Future deleteById(String id) async { final db = await database; await db.delete('history', where: 'id = ?', whereArgs: [id]); } - /// Delete by Spotify ID Future deleteBySpotifyId(String spotifyId) async { final db = await database; await db.delete('history', where: 'spotify_id = ?', whereArgs: [spotifyId]); } - /// Clear all history Future clearAll() async { final db = await database; await db.delete('history'); _log.i('Cleared all history'); } - /// Get total count Future getCount() async { final db = await database; final result = await db.rawQuery('SELECT COUNT(*) as count FROM history'); @@ -459,7 +449,6 @@ class HistoryDatabase { return null; } - /// Close database Future close() async { final db = await database; await db.close(); diff --git a/lib/services/library_database.dart b/lib/services/library_database.dart index 16955171..47b3ab19 100644 --- a/lib/services/library_database.dart +++ b/lib/services/library_database.dart @@ -123,7 +123,7 @@ class LibraryDatabase { return await openDatabase( path, - version: 4, // Bumped version for bitrate column + version: 4, onConfigure: (db) async { await db.rawQuery('PRAGMA journal_mode = WAL'); await db.execute('PRAGMA synchronous = NORMAL'); @@ -331,13 +331,11 @@ class LibraryDatabase { String? trackName, String? artistName, }) async { - // First try ISRC if available if (isrc != null && isrc.isNotEmpty) { final byIsrc = await getByIsrc(isrc); if (byIsrc != null) return byIsrc; } - // Then try name matching if (trackName != null && artistName != null) { final matches = await findByTrackAndArtist(trackName, artistName); if (matches.isNotEmpty) return matches.first; @@ -523,7 +521,6 @@ class LibraryDatabase { return rows.map((r) => r['file_path'] as String).toSet(); } - /// Delete multiple items by their file paths Future deleteByPaths(List filePaths) async { if (filePaths.isEmpty) return 0; final db = await database; diff --git a/lib/theme/app_theme.dart b/lib/theme/app_theme.dart index 2aba9e85..c13b54ee 100644 --- a/lib/theme/app_theme.dart +++ b/lib/theme/app_theme.dart @@ -35,7 +35,6 @@ class AppTheme { ); } - /// Create dark theme static ThemeData dark({ ColorScheme? dynamicScheme, Color? seedColor, @@ -88,12 +87,11 @@ class AppTheme { ), ); - /// Card theme static CardThemeData _cardTheme(ColorScheme scheme) => CardThemeData( elevation: 0, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), - ), // 12 -> 16 + ), color: scheme.surfaceContainerLow, surfaceTintColor: scheme.surfaceTint, ); @@ -104,18 +102,17 @@ class AppTheme { elevation: 1, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), - ), // 20 -> 16 + ), padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), ), ); - /// Filled button theme static FilledButtonThemeData _filledButtonTheme(ColorScheme scheme) => FilledButtonThemeData( style: FilledButton.styleFrom( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), - ), // 20 -> 16 + ), padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), ), ); @@ -125,18 +122,17 @@ class AppTheme { style: OutlinedButton.styleFrom( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), - ), // 20 -> 16 + ), padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), ), ); - /// Text button theme static TextButtonThemeData _textButtonTheme(ColorScheme scheme) => TextButtonThemeData( style: TextButton.styleFrom( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), - ), // 20 -> 16 + ), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), ), ); @@ -149,40 +145,39 @@ class AppTheme { foregroundColor: scheme.onPrimaryContainer, ); - /// Input decoration theme static InputDecorationTheme _inputDecorationTheme(ColorScheme scheme) => InputDecorationTheme( filled: true, fillColor: scheme.surfaceContainerHighest.withValues( alpha: 0.3, - ), // Added transparency + ), border: OutlineInputBorder( - borderRadius: BorderRadius.circular(16), // 12 -> 16 + borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none, ), enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(16), // 12 -> 16 + borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none, ), focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(16), // 12 -> 16 + borderRadius: BorderRadius.circular(16), borderSide: BorderSide(color: scheme.primary, width: 2), ), errorBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(16), // 12 -> 16 + borderRadius: BorderRadius.circular(16), borderSide: BorderSide(color: scheme.error, width: 1), ), contentPadding: const EdgeInsets.symmetric( horizontal: 20, vertical: 16, - ), // consistent padding + ), ); static ListTileThemeData _listTileTheme(ColorScheme scheme) => ListTileThemeData( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), - ), // 12 -> 16 + ), contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4), ); @@ -193,7 +188,6 @@ class AppTheme { surfaceTintColor: scheme.surfaceTint, ); - /// Navigation bar theme static NavigationBarThemeData _navigationBarTheme( ColorScheme scheme, { bool isAmoled = false, @@ -213,7 +207,6 @@ class AppTheme { contentTextStyle: TextStyle(color: scheme.onInverseSurface), ); - /// Progress indicator theme static ProgressIndicatorThemeData _progressIndicatorTheme( ColorScheme scheme, ) => ProgressIndicatorThemeData( @@ -243,7 +236,6 @@ class AppTheme { }), ); - /// Chip theme static ChipThemeData _chipTheme(ColorScheme scheme) => ChipThemeData( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), backgroundColor: scheme.surfaceContainerLow, diff --git a/lib/theme/dynamic_color_wrapper.dart b/lib/theme/dynamic_color_wrapper.dart index 6ee84b86..77237502 100644 --- a/lib/theme/dynamic_color_wrapper.dart +++ b/lib/theme/dynamic_color_wrapper.dart @@ -4,7 +4,6 @@ import 'package:dynamic_color/dynamic_color.dart'; import 'package:spotiflac_android/providers/theme_provider.dart'; import 'package:spotiflac_android/theme/app_theme.dart'; -/// Wrapper widget that provides dynamic color support from device wallpaper class DynamicColorWrapper extends ConsumerWidget { final Widget Function(ThemeData light, ThemeData dark, ThemeMode mode) builder; @@ -23,7 +22,6 @@ class DynamicColorWrapper extends ConsumerWidget { ColorScheme darkScheme; if (themeSettings.useDynamicColor && lightDynamic != null && darkDynamic != null) { - // Use dynamic colors from wallpaper (Android 12+) lightScheme = lightDynamic; darkScheme = darkDynamic; } else { @@ -38,7 +36,6 @@ class DynamicColorWrapper extends ConsumerWidget { ); } - // Apply AMOLED mode if enabled (pure black background) if (themeSettings.useAmoled) { darkScheme = _applyAmoledColors(darkScheme); } diff --git a/lib/widgets/download_service_picker.dart b/lib/widgets/download_service_picker.dart index 977a31b6..3b8bac12 100644 --- a/lib/widgets/download_service_picker.dart +++ b/lib/widgets/download_service_picker.dart @@ -22,7 +22,6 @@ class BuiltInService { }); } -/// Default quality options for built-in services /// Default quality options for each built-in service const _builtInServices = [ BuiltInService( @@ -98,7 +97,6 @@ const _builtInServices = [ ), ]; -/// A reusable widget for selecting download service (built-in + extensions) class DownloadServicePicker extends ConsumerStatefulWidget { final String? trackName; final String? artistName;