Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setting to set up a black background for subtitles fix #323 #334

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
10 changes: 9 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lib/player/states/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class VideoPlayerCubit extends MediaPlayerCubit<VideoPlayerState> {
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,
Expand Down
10 changes: 10 additions & 0 deletions lib/settings/states/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ class SettingsCubit extends Cubit<SettingsState> {
emit(state);
}

setSubtitlesBackground(bool b) {
var state = this.state.copyWith();
state.subtitlesBackground = b;
emit(state);
}

String? getLocaleDisplayName() {
List<String>? localeString = state.locale?.split('_');
Locale? l = localeString != null ? Locale.fromSubtags(languageCode: localeString[0], scriptCode: localeString.length >= 2 ? localeString[1] : null) : null;
Expand Down Expand Up @@ -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<T>(String name, T value) {
if (value == null) {
db.deleteSetting(name);
Expand Down
50 changes: 30 additions & 20 deletions lib/settings/views/screens/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
),
]),
],
),
);
Expand Down
6 changes: 6 additions & 0 deletions lib/settings/views/tv/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/workmanager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Future<void> configureBackgroundService(SettingsCubit settings) async {

Future<void> 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));
}

Expand Down