added comment outline mode.

This commit is contained in:
Livinglist
2022-01-10 23:43:43 -08:00
parent 612ab9d87d
commit 3a55f852e5
5 changed files with 59 additions and 19 deletions

View File

@ -20,6 +20,8 @@ class PreferenceCubit extends Cubit<PreferenceState> {
.then((value) => emit(state.copyWith(showComplexStoryTile: value)));
_storageRepository.shouldShowWebFirst
.then((value) => emit(state.copyWith(showWebFirst: value)));
_storageRepository.shouldCommentBorder
.then((value) => emit(state.copyWith(showCommentBorder: value)));
_storageRepository.shouldShowEyeCandy
.then((value) => emit(state.copyWith(showEyeCandy: value)));
}
@ -34,6 +36,11 @@ class PreferenceCubit extends Cubit<PreferenceState> {
_storageRepository.toggleNavigationMode();
}
void toggleCommentBorderMode() {
emit(state.copyWith(showCommentBorder: !state.showCommentBorder));
_storageRepository.toggleCommentBorderMode();
}
void toggleEyeCandyMode() {
emit(state.copyWith(showEyeCandy: !state.showEyeCandy));
_storageRepository.toggleEyeCandyMode();

View File

@ -4,26 +4,31 @@ class PreferenceState extends Equatable {
const PreferenceState({
required this.showComplexStoryTile,
required this.showWebFirst,
required this.showCommentBorder,
required this.showEyeCandy,
});
const PreferenceState.init()
: showComplexStoryTile = false,
showWebFirst = false,
showCommentBorder = false,
showEyeCandy = false;
final bool showComplexStoryTile;
final bool showWebFirst;
final bool showCommentBorder;
final bool showEyeCandy;
PreferenceState copyWith({
bool? showComplexStoryTile,
bool? showWebFirst,
bool? showCommentBorder,
bool? showEyeCandy,
}) {
return PreferenceState(
showComplexStoryTile: showComplexStoryTile ?? this.showComplexStoryTile,
showWebFirst: showWebFirst ?? this.showWebFirst,
showCommentBorder: showCommentBorder ?? this.showCommentBorder,
showEyeCandy: showEyeCandy ?? this.showEyeCandy,
);
}
@ -32,6 +37,7 @@ class PreferenceState extends Equatable {
List<Object?> get props => [
showComplexStoryTile,
showWebFirst,
showCommentBorder,
showEyeCandy,
];
}

View File

@ -20,10 +20,12 @@ class StorageRepository {
/// navigated to web view first. Defaults to false.
static const String _navigationModeKey = 'navigationModeKey';
static const String _commentBorderModeKey = 'commentBorderModeKey';
static const String _eyeCandyModeKey = 'eyeCandyKey';
static const bool _displayModeDefaultValue = true;
static const bool _navigationModeDefaultValue = true;
static const bool _commentBorderModeDefaultValue = true;
static const bool _eyeCandyModeDefaultValue = false;
final Future<SharedPreferences> _prefs;
@ -44,6 +46,9 @@ class StorageRepository {
Future<bool> get shouldShowWebFirst async => _prefs.then((prefs) =>
prefs.getBool(_navigationModeKey) ?? _navigationModeDefaultValue);
Future<bool> get shouldCommentBorder async => _prefs.then((prefs) =>
prefs.getBool(_commentBorderModeKey) ?? _commentBorderModeDefaultValue);
Future<bool> get shouldShowEyeCandy async => _prefs.then(
(prefs) => prefs.getBool(_eyeCandyModeKey) ?? _eyeCandyModeDefaultValue);
@ -79,6 +84,13 @@ class StorageRepository {
await prefs.setBool(_navigationModeKey, !currentMode);
}
Future<void> toggleCommentBorderMode() async {
final prefs = await _prefs;
final currentMode =
prefs.getBool(_commentBorderModeKey) ?? _commentBorderModeDefaultValue;
await prefs.setBool(_commentBorderModeKey, !currentMode);
}
Future<void> toggleEyeCandyMode() async {
final prefs = await _prefs;
final currentMode =

View File

@ -210,6 +210,18 @@ class _ProfileScreenState extends State<ProfileScreen>
},
activeColor: Colors.orange,
),
SwitchListTile(
title: const Text('Show Comment Outlines'),
subtitle: const Text('Be nice to your eyes.'),
value: preferenceState.showCommentBorder,
onChanged: (val) {
HapticFeedback.lightImpact();
context
.read<PreferenceCubit>()
.toggleCommentBorderMode();
},
activeColor: Colors.orange,
),
SwitchListTile(
title: const Text('Eye Candy'),
subtitle: const Text('Some sort of magic.'),

View File

@ -154,27 +154,30 @@ class _CommentTileState extends State<CommentTile> {
color: Colors.orangeAccent.withOpacity(0.3),
child: child,
);
} else if (prefState.showEyeCandy) {
final commentBackgroundColorOpacity =
Theme.of(context).brightness == Brightness.dark
? 0.03
: 0.15;
return Container(
decoration: BoxDecoration(
border: Border(
left: BorderSide(
color: color.withOpacity(0.5),
//color: Colors.grey.withOpacity(0.5),
),
),
color: color.withOpacity(commentBackgroundColorOpacity),
),
child: child,
);
}
return child;
final commentBackgroundColorOpacity =
Theme.of(context).brightness == Brightness.dark
? 0.03
: 0.15;
final borderColor = prefState.showCommentBorder
? color.withOpacity(0.5)
: Colors.transparent;
final commentColor = prefState.showEyeCandy
? color.withOpacity(commentBackgroundColorOpacity)
: Colors.transparent;
return Container(
decoration: BoxDecoration(
border: Border(
left: BorderSide(
color: borderColor,
),
),
color: commentColor,
),
child: child,
);
},
);
},