Skip to content

Commit

Permalink
feat: enhance theme management by integrating theme selection based o…
Browse files Browse the repository at this point in the history
…n audiobook playback
  • Loading branch information
Dr-Blank committed Oct 5, 2024
1 parent db85a76 commit 37f775a
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import 'package:vaani/features/logging/core/logger.dart';
import 'package:vaani/features/playback_reporting/providers/playback_reporter_provider.dart';
import 'package:vaani/features/player/core/init.dart';
import 'package:vaani/features/player/providers/audiobook_player.dart'
show simpleAudiobookPlayerProvider;
show audiobookPlayerProvider, simpleAudiobookPlayerProvider;
import 'package:vaani/features/shake_detection/providers/shake_detector.dart';
import 'package:vaani/features/sleep_timer/providers/sleep_timer_provider.dart';
import 'package:vaani/router/router.dart';
import 'package:vaani/settings/api_settings_provider.dart';
import 'package:vaani/settings/app_settings_provider.dart';
import 'package:vaani/theme/providers/system_them_provider.dart';
import 'package:vaani/theme/providers/theme_from_cover_provider.dart';
import 'package:vaani/theme/theme.dart';

final appLogger = Logger('vaani');
Expand Down Expand Up @@ -73,7 +74,6 @@ class MyApp extends ConsumerWidget {
}

if (themeSettings.useMaterialThemeFromSystem) {
appLogger.info('Using theme from system');
var themes =
ref.watch(systemThemeProvider(highContrast: shouldUseHighContrast));
if (themes.valueOrNull != null) {
Expand All @@ -82,12 +82,29 @@ class MyApp extends ConsumerWidget {
}
}

// AudiobookPlayer? player;

// if (themeSettings.useMaterialThemeOfPlayingItem) {
// appLogger.info('Using theme from playing item');
// player = ref.watch(audiobookPlayerProvider);
// }
if (themeSettings.useMaterialThemeOfPlayingItem) {
final player = ref.watch(audiobookPlayerProvider);
if (player.book != null) {
final themeLight = ref.watch(
themeOfLibraryItemProvider(
player.book!.libraryItemId,
highContrast: shouldUseHighContrast,
brightness: Brightness.light,
),
);
final themeDark = ref.watch(
themeOfLibraryItemProvider(
player.book!.libraryItemId,
highContrast: shouldUseHighContrast,
brightness: Brightness.dark,
),
);
if (themeLight.valueOrNull != null && themeDark.valueOrNull != null) {
lightColorScheme = themeLight.valueOrNull!;
darkColorScheme = themeDark.valueOrNull!;
}
}
}
final appThemeLight = ThemeData(
useMaterial3: true,
colorScheme: lightColorScheme.harmonized(),
Expand Down

0 comments on commit 37f775a

Please sign in to comment.