Skip to content

Commit

Permalink
Add high contrast mode, closes #564
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Dec 28, 2023
1 parent 2c0937e commit 7eb5735
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 24 deletions.
12 changes: 12 additions & 0 deletions app/lib/cubits/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class ButterflySettings with _$ButterflySettings {
@Default([]) List<int> recentColors,
@Default([]) List<String> flags,
@Default(false) bool spreadPages,
@Default(false) bool highContrast,
}) = _ButterflySettings;

factory ButterflySettings.fromPrefs(
Expand Down Expand Up @@ -445,6 +446,8 @@ class ButterflySettings with _$ButterflySettings {
recentColors:
prefs.getStringList('recent_colors')?.map(int.parse).toList() ?? [],
flags: prefs.getStringList('flags') ?? [],
spreadPages: prefs.getBool('spread_pages') ?? false,
highContrast: prefs.getBool('high_contrast') ?? false,
);
}

Expand Down Expand Up @@ -502,6 +505,8 @@ class ButterflySettings with _$ButterflySettings {
await prefs.setStringList(
'recent_colors', recentColors.map((e) => e.toString()).toList());
await prefs.setStringList('flags', flags);
await prefs.setBool('spread_pages', spreadPages);
await prefs.setBool('high_contrast', highContrast);
}

ExternalStorage? getRemote(String? identifier) {
Expand Down Expand Up @@ -975,4 +980,11 @@ class SettingsCubit extends Cubit<ButterflySettings> {
}

Future<void> resetSpreadPages() => changeSpreadPages(true);

Future<void> changeHighContrast(bool value) {
emit(state.copyWith(highContrast: value));
return save();
}

Future<void> resetHighContrast() => changeHighContrast(false);
}
48 changes: 36 additions & 12 deletions app/lib/cubits/settings.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class _$DavRemoteStorageImpl extends DavRemoteStorage
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$DavRemoteStorageImpl &&
Expand Down Expand Up @@ -868,7 +868,7 @@ class _$LocalStorageImpl extends LocalStorage with DiagnosticableTreeMixin {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LocalStorageImpl &&
Expand Down Expand Up @@ -1301,7 +1301,7 @@ class _$InputConfigurationImpl extends _InputConfiguration
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$InputConfigurationImpl &&
Expand Down Expand Up @@ -1413,6 +1413,7 @@ mixin _$ButterflySettings {
List<int> get recentColors => throw _privateConstructorUsedError;
List<String> get flags => throw _privateConstructorUsedError;
bool get spreadPages => throw _privateConstructorUsedError;
bool get highContrast => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$ButterflySettingsCopyWith<ButterflySettings> get copyWith =>
Expand Down Expand Up @@ -1462,7 +1463,8 @@ abstract class $ButterflySettingsCopyWith<$Res> {
PlatformTheme platformTheme,
List<int> recentColors,
List<String> flags,
bool spreadPages});
bool spreadPages,
bool highContrast});

$InputConfigurationCopyWith<$Res> get inputConfiguration;
}
Expand Down Expand Up @@ -1517,6 +1519,7 @@ class _$ButterflySettingsCopyWithImpl<$Res, $Val extends ButterflySettings>
Object? recentColors = null,
Object? flags = null,
Object? spreadPages = null,
Object? highContrast = null,
}) {
return _then(_value.copyWith(
theme: null == theme
Expand Down Expand Up @@ -1667,6 +1670,10 @@ class _$ButterflySettingsCopyWithImpl<$Res, $Val extends ButterflySettings>
? _value.spreadPages
: spreadPages // ignore: cast_nullable_to_non_nullable
as bool,
highContrast: null == highContrast
? _value.highContrast
: highContrast // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}

Expand Down Expand Up @@ -1725,7 +1732,8 @@ abstract class _$$ButterflySettingsImplCopyWith<$Res>
PlatformTheme platformTheme,
List<int> recentColors,
List<String> flags,
bool spreadPages});
bool spreadPages,
bool highContrast});

@override
$InputConfigurationCopyWith<$Res> get inputConfiguration;
Expand Down Expand Up @@ -1779,6 +1787,7 @@ class __$$ButterflySettingsImplCopyWithImpl<$Res>
Object? recentColors = null,
Object? flags = null,
Object? spreadPages = null,
Object? highContrast = null,
}) {
return _then(_$ButterflySettingsImpl(
theme: null == theme
Expand Down Expand Up @@ -1929,6 +1938,10 @@ class __$$ButterflySettingsImplCopyWithImpl<$Res>
? _value.spreadPages
: spreadPages // ignore: cast_nullable_to_non_nullable
as bool,
highContrast: null == highContrast
? _value.highContrast
: highContrast // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
Expand Down Expand Up @@ -1974,7 +1987,8 @@ class _$ButterflySettingsImpl extends _ButterflySettings
this.platformTheme = PlatformTheme.system,
final List<int> recentColors = const [],
final List<String> flags = const [],
this.spreadPages = false})
this.spreadPages = false,
this.highContrast = false})
: _history = history,
_connections = connections,
_starred = starred,
Expand Down Expand Up @@ -2121,10 +2135,13 @@ class _$ButterflySettingsImpl extends _ButterflySettings
@override
@JsonKey()
final bool spreadPages;
@override
@JsonKey()
final bool highContrast;

@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'ButterflySettings(theme: $theme, density: $density, localeTag: $localeTag, documentPath: $documentPath, touchSensitivity: $touchSensitivity, mouseSensitivity: $mouseSensitivity, penSensitivity: $penSensitivity, selectSensitivity: $selectSensitivity, penOnlyInput: $penOnlyInput, inputGestures: $inputGestures, design: $design, bannerVisibility: $bannerVisibility, history: $history, navigatorEnabled: $navigatorEnabled, zoomEnabled: $zoomEnabled, lastVersion: $lastVersion, connections: $connections, defaultRemote: $defaultRemote, nativeTitleBar: $nativeTitleBar, startInFullScreen: $startInFullScreen, navigationRail: $navigationRail, fullScreen: $fullScreen, syncMode: $syncMode, inputConfiguration: $inputConfiguration, fallbackPack: $fallbackPack, starred: $starred, defaultTemplate: $defaultTemplate, navigatorPage: $navigatorPage, toolbarPosition: $toolbarPosition, sortBy: $sortBy, sortOrder: $sortOrder, imageScale: $imageScale, pdfQuality: $pdfQuality, platformTheme: $platformTheme, recentColors: $recentColors, flags: $flags, spreadPages: $spreadPages)';
return 'ButterflySettings(theme: $theme, density: $density, localeTag: $localeTag, documentPath: $documentPath, touchSensitivity: $touchSensitivity, mouseSensitivity: $mouseSensitivity, penSensitivity: $penSensitivity, selectSensitivity: $selectSensitivity, penOnlyInput: $penOnlyInput, inputGestures: $inputGestures, design: $design, bannerVisibility: $bannerVisibility, history: $history, navigatorEnabled: $navigatorEnabled, zoomEnabled: $zoomEnabled, lastVersion: $lastVersion, connections: $connections, defaultRemote: $defaultRemote, nativeTitleBar: $nativeTitleBar, startInFullScreen: $startInFullScreen, navigationRail: $navigationRail, fullScreen: $fullScreen, syncMode: $syncMode, inputConfiguration: $inputConfiguration, fallbackPack: $fallbackPack, starred: $starred, defaultTemplate: $defaultTemplate, navigatorPage: $navigatorPage, toolbarPosition: $toolbarPosition, sortBy: $sortBy, sortOrder: $sortOrder, imageScale: $imageScale, pdfQuality: $pdfQuality, platformTheme: $platformTheme, recentColors: $recentColors, flags: $flags, spreadPages: $spreadPages, highContrast: $highContrast)';
}

@override
Expand Down Expand Up @@ -2168,11 +2185,12 @@ class _$ButterflySettingsImpl extends _ButterflySettings
..add(DiagnosticsProperty('platformTheme', platformTheme))
..add(DiagnosticsProperty('recentColors', recentColors))
..add(DiagnosticsProperty('flags', flags))
..add(DiagnosticsProperty('spreadPages', spreadPages));
..add(DiagnosticsProperty('spreadPages', spreadPages))
..add(DiagnosticsProperty('highContrast', highContrast));
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ButterflySettingsImpl &&
Expand Down Expand Up @@ -2242,7 +2260,9 @@ class _$ButterflySettingsImpl extends _ButterflySettings
.equals(other._recentColors, _recentColors) &&
const DeepCollectionEquality().equals(other._flags, _flags) &&
(identical(other.spreadPages, spreadPages) ||
other.spreadPages == spreadPages));
other.spreadPages == spreadPages) &&
(identical(other.highContrast, highContrast) ||
other.highContrast == highContrast));
}

@override
Expand Down Expand Up @@ -2284,7 +2304,8 @@ class _$ButterflySettingsImpl extends _ButterflySettings
platformTheme,
const DeepCollectionEquality().hash(_recentColors),
const DeepCollectionEquality().hash(_flags),
spreadPages
spreadPages,
highContrast
]);

@JsonKey(ignore: true)
Expand Down Expand Up @@ -2333,7 +2354,8 @@ abstract class _ButterflySettings extends ButterflySettings {
final PlatformTheme platformTheme,
final List<int> recentColors,
final List<String> flags,
final bool spreadPages}) = _$ButterflySettingsImpl;
final bool spreadPages,
final bool highContrast}) = _$ButterflySettingsImpl;
const _ButterflySettings._() : super._();

@override
Expand Down Expand Up @@ -2411,6 +2433,8 @@ abstract class _ButterflySettings extends ButterflySettings {
@override
bool get spreadPages;
@override
bool get highContrast;
@override
@JsonKey(ignore: true)
_$$ButterflySettingsImplCopyWith<_$ButterflySettingsImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
3 changes: 2 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,6 @@
}
},
"continueAnyway": "Continue anyway",
"zoomControl": "Zoom control"
"zoomControl": "Zoom control",
"highContrast": "High contrast"
}
11 changes: 6 additions & 5 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ class ButterflyApp extends StatelessWidget {
previous.theme != current.theme ||
previous.localeTag != current.localeTag ||
previous.design != current.design ||
previous.density != current.density,
previous.density != current.density ||
previous.highContrast != current.highContrast,
builder: (context, state) => MaterialApp.router(
locale: state.locale,
title: applicationName,
Expand All @@ -371,10 +372,10 @@ class ButterflyApp extends StatelessWidget {
},
supportedLocales: getLocales(),
themeMode: state.theme,
theme: getThemeData(
state.design, false, state.density.toFlutter(), lightDynamic),
darkTheme: getThemeData(
state.design, true, state.density.toFlutter(), darkDynamic),
theme: getThemeData(state.design, false,
state.density.toFlutter(), lightDynamic, state.highContrast),
darkTheme: getThemeData(state.design, true,
state.density.toFlutter(), darkDynamic, state.highContrast),
));
}

Expand Down
4 changes: 2 additions & 2 deletions app/lib/models/label.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class _$TextContextImpl extends TextContext {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$TextContextImpl &&
Expand Down Expand Up @@ -616,7 +616,7 @@ class _$MarkdownContextImpl extends MarkdownContext {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$MarkdownContextImpl &&
Expand Down
4 changes: 2 additions & 2 deletions app/lib/services/network.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class _$NetworkingInitMessageImpl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$NetworkingInitMessageImpl &&
Expand Down Expand Up @@ -311,7 +311,7 @@ class _$NetworkingUserImpl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$NetworkingUserImpl &&
Expand Down
10 changes: 10 additions & 0 deletions app/lib/settings/personalization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ class PersonalizationSettingsPage extends StatelessWidget {
Text(_getDensityName(context, state.density)),
onTap: () => _openDensityModal(context),
),
SwitchListTile(
secondary:
const PhosphorIcon(PhosphorIconsLight.circleHalf),
title:
Text(AppLocalizations.of(context).highContrast),
value: state.highContrast,
onChanged: (value) => context
.read<SettingsCubit>()
.changeHighContrast(value),
),
]),
),
),
Expand Down
6 changes: 5 additions & 1 deletion app/lib/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const kClassicThemeData = FlexSchemeData(
name: '', description: '', light: kClassicTheme, dark: kClassicTheme);

ThemeData getThemeData(String name, bool dark,
[VisualDensity? density, ColorScheme? overridden]) {
[VisualDensity? density,
ColorScheme? overridden,
bool highContrast = false]) {
final color = getFlexThemeColor(name, dark);
final override = overridden != null && name.isEmpty;
ThemeData theme;
Expand All @@ -27,6 +29,7 @@ ThemeData getThemeData(String name, bool dark,
appBarElevation: 2,
fontFamily: 'Comfortaa',
visualDensity: density,
darkIsTrueBlack: highContrast,
);
} else {
theme = FlexThemeData.light(
Expand All @@ -36,6 +39,7 @@ ThemeData getThemeData(String name, bool dark,
appBarElevation: 0.5,
fontFamily: 'Comfortaa',
visualDensity: density,
lightIsWhite: highContrast,
);
}
return theme.copyWith(
Expand Down
4 changes: 3 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/86.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
* Add high contrast mode ([#564](https://github.com/LinwoodDev/Butterfly/issues/564))
* Add support for multi character input languages ([#539](https://github.com/LinwoodDev/Butterfly/issues/539))
* Add scale to label toolbar
* Add scale to label selection view
* Add markdown element selection view
* Fix moving data directory ([#562](https://github.com/LinwoodDev/Butterfly/issues/562))
* Fix various issues with the label tool
* Fix display icon
* Fix display icon
* Fix spread pages settings not being saved

0 comments on commit 7eb5735

Please sign in to comment.