From e05d881f75904c1b84e5786de240164c6a5cf095 Mon Sep 17 00:00:00 2001 From: nixos script Date: Wed, 4 Oct 2023 16:54:22 +0800 Subject: [PATCH 1/2] add setting to set up a black background for subtitles fix #323 --- lib/database.dart | 1 + lib/l10n/app_en.arb | 10 +++- lib/player/states/video_player.dart | 1 + lib/settings/states/settings.dart | 10 ++++ lib/settings/views/screens/video_player.dart | 50 ++++++++++++-------- lib/settings/views/tv/screens/settings.dart | 6 +++ 6 files changed, 57 insertions(+), 21 deletions(-) diff --git a/lib/database.dart b/lib/database.dart index e49ecb01..6931699a 100644 --- a/lib/database.dart +++ b/lib/database.dart @@ -51,6 +51,7 @@ const DISTRACTION_FREE_MODE = 'distraction-free-mode'; const BACKGROUND_NOTIFICATIONS = 'background-notifications'; const SUBSCRIPTION_NOTIFICATIONS = 'subscriptions-notifications'; const BACKGROUND_CHECK_FREQUENCY = "background-check-frequency"; +const SUBTITLE_BACKGROUND = 'subtitle-background'; const ON_OPEN = "on-open"; diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 6f9211ad..e619acb1 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -663,7 +663,7 @@ "@logsCopied": { "description": "Message to tell user that logs have been copied to the clipboard" }, - "rememberSubtitleLanguage": "Remember subtitle language", + "rememberSubtitleLanguage": "Remember subtitles language", "@rememberSubtitleLanguage": { "description": "Settings label for remembering subtitle language" }, @@ -1165,6 +1165,14 @@ "format": "compact" } }, + "subtitlesBackground": "Subtitles background", + "@subtitlesBackground": { + "description": "Title for settings to set black background for subtitles" + }, + "subtitlesBackgroundDescription": "Adds a black background to subtitles to make them more readable", + "@subtitlesBackgroundDescription": { + "description": "Description for settings to set black background for subtitles" + }, "history": "History", "@history": { "description": "User view history label" diff --git a/lib/player/states/video_player.dart b/lib/player/states/video_player.dart index 5b551560..5a0b5141 100644 --- a/lib/player/states/video_player.dart +++ b/lib/player/states/video_player.dart @@ -319,6 +319,7 @@ class VideoPlayerCubit extends MediaPlayerCubit { allowedScreenSleep: false, fit: fillVideo ? BoxFit.cover : BoxFit.contain, subtitlesConfiguration: BetterPlayerSubtitlesConfiguration( + backgroundColor: settings.state.subtitlesBackground ? Colors.black.withOpacity(0.8): Colors.transparent, fontSize: settings.state.subtitleSize, outlineEnabled: true, outlineColor: Colors.black, diff --git a/lib/settings/states/settings.dart b/lib/settings/states/settings.dart index 767d5396..6fc358f2 100644 --- a/lib/settings/states/settings.dart +++ b/lib/settings/states/settings.dart @@ -301,6 +301,12 @@ class SettingsCubit extends Cubit { emit(state); } + setSubtitlesBackground(bool b) { + var state = this.state.copyWith(); + state.subtitlesBackground = b; + emit(state); + } + String? getLocaleDisplayName() { List? localeString = state.locale?.split('_'); Locale? l = localeString != null ? Locale.fromSubtags(languageCode: localeString[0], scriptCode: localeString.length >= 2 ? localeString[1] : null) : null; @@ -497,6 +503,10 @@ class SettingsState { set backgroundNotificationFrequency(int i) => _set(BACKGROUND_CHECK_FREQUENCY, i); + bool get subtitlesBackground => _get(SUBTITLE_BACKGROUND)?.value == 'true'; + + set subtitlesBackground(bool b) => _set(SUBTITLE_BACKGROUND, b); + void _set(String name, T value) { if (value == null) { db.deleteSetting(name); diff --git a/lib/settings/views/screens/video_player.dart b/lib/settings/views/screens/video_player.dart index 25acd66b..0c529f1d 100644 --- a/lib/settings/views/screens/video_player.dart +++ b/lib/settings/views/screens/video_player.dart @@ -56,26 +56,6 @@ class VideoPlayerSettingsScreen extends StatelessWidget { title: Text(locals.autoplayVideoOnLoad), description: Text(locals.autoplayVideoOnLoadDescription), ), - SettingsTile( - title: Text(locals.subtitleFontSize), - description: Text(locals.subtitleFontSizeDescription), - trailing: Row( - mainAxisSize: MainAxisSize.min, - children: [ - IconButton( - onPressed: () => cubit.changeSubtitleSize(increase: false), icon: const Icon(Icons.remove)), - Text(_.subtitleSize.floor().toString()), - IconButton( - onPressed: () => cubit.changeSubtitleSize(increase: true), icon: const Icon(Icons.add)), - ], - ), - ), - SettingsTile.switchTile( - initialValue: _.rememberSubtitles, - onToggle: cubit.toggleRememberSubtitles, - title: Text(locals.rememberSubtitleLanguage), - description: Text(locals.rememberSubtitleLanguageDescription), - ), SettingsTile.switchTile( initialValue: _.rememberPlayBackSpeed, onToggle: cubit.toggleRememberPlaybackSpeed, @@ -100,6 +80,36 @@ class VideoPlayerSettingsScreen extends StatelessWidget { description: Text(locals.fillFullscreenDescription), ), ]), + SettingsSection( + title: Text(locals.subtitles), + tiles: [ + SettingsTile( + title: Text(locals.subtitleFontSize), + description: Text(locals.subtitleFontSizeDescription), + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + IconButton( + onPressed: () => cubit.changeSubtitleSize(increase: false), icon: const Icon(Icons.remove)), + Text(_.subtitleSize.floor().toString()), + IconButton( + onPressed: () => cubit.changeSubtitleSize(increase: true), icon: const Icon(Icons.add)), + ], + ), + ), + SettingsTile.switchTile( + initialValue: _.subtitlesBackground, + onToggle: cubit.setSubtitlesBackground, + title: Text(locals.subtitlesBackground), + description: Text(locals.subtitlesBackgroundDescription), + ), + SettingsTile.switchTile( + initialValue: _.rememberSubtitles, + onToggle: cubit.toggleRememberSubtitles, + title: Text(locals.rememberSubtitleLanguage), + description: Text(locals.rememberSubtitleLanguageDescription), + ), + ]), ], ), ); diff --git a/lib/settings/views/tv/screens/settings.dart b/lib/settings/views/tv/screens/settings.dart index e32aeb0c..cc8674dc 100644 --- a/lib/settings/views/tv/screens/settings.dart +++ b/lib/settings/views/tv/screens/settings.dart @@ -159,6 +159,12 @@ class TVSettingsScreen extends StatelessWidget { description: locals.subtitleFontSizeDescription, onNewValue: cubit.setSubtitleSize, ), + SettingsTile( + title: locals.subtitlesBackground, + description: locals.subtitlesBackgroundDescription, + onSelected: (context) => cubit.setSubtitlesBackground(!_.subtitlesBackground), + trailing: Switch(onChanged: (value) {}, value: _.subtitlesBackground), + ), SettingsTile( title: locals.rememberSubtitleLanguage, description: locals.rememberSubtitleLanguageDescription, From 2db3407f021ffea7e393c04ef14f492b4b3b67a1 Mon Sep 17 00:00:00 2001 From: nixos script Date: Wed, 4 Oct 2023 16:59:58 +0800 Subject: [PATCH 2/2] add const to duration --- lib/workmanager.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/workmanager.dart b/lib/workmanager.dart index 1eb8fe93..a9be1fe0 100644 --- a/lib/workmanager.dart +++ b/lib/workmanager.dart @@ -25,7 +25,7 @@ Future configureBackgroundService(SettingsCubit settings) async { Future setupTasks(SettingsCubit settings) async { await Workmanager().registerPeriodicTask(taskName, taskName, - frequency: kDebugMode ? Duration(seconds: 15) : Duration(hours: settings.state.backgroundNotificationFrequency), + frequency: kDebugMode ? const Duration(seconds: 15) : Duration(hours: settings.state.backgroundNotificationFrequency), constraints: Constraints(networkType: NetworkType.connected, requiresBatteryNotLow: true)); }