Change show notes font.

This commit is contained in:
stonegate 2020-08-29 04:49:11 +08:00
parent 83303b873e
commit 815e4d8caf
4 changed files with 246 additions and 158 deletions

View File

@ -43,6 +43,7 @@ const String boostVolumeKey = 'boostVolumeKey';
const String volumeGainKey = 'volumeGainKey';
const String hideListenedKey = 'hideListenedKey';
const String notificationLayoutKey = 'notificationLayoutKey';
const String showNotesFontKey = 'showNotesFontKey';
class KeyValueStorage {
final String key;

View File

@ -42,150 +42,195 @@ class ThemeSetting extends StatelessWidget {
.bodyText1
.copyWith(color: Theme.of(context).accentColor)),
),
ListView(
physics: const BouncingScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
children: <Widget>[
ListTile(
onTap: () => showGeneralDialog(
context: context,
barrierDismissible: true,
barrierLabel: MaterialLocalizations.of(context)
.modalBarrierDismissLabel,
barrierColor: Colors.black54,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (context, animaiton, secondaryAnimation) =>
AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarIconBrightness: Brightness.light,
systemNavigationBarColor:
Theme.of(context).brightness ==
Brightness.light
? Color.fromRGBO(113, 113, 113, 1)
: Color.fromRGBO(15, 15, 15, 1),
),
child: AlertDialog(
titlePadding: EdgeInsets.only(
top: 20,
left: 40,
right: context.width / 3,
),
elevation: 1,
shape: RoundedRectangleBorder(
ListTile(
onTap: () => showGeneralDialog(
context: context,
barrierDismissible: true,
barrierLabel: MaterialLocalizations.of(context)
.modalBarrierDismissLabel,
barrierColor: Colors.black54,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (context, animaiton, secondaryAnimation) =>
AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarIconBrightness: Brightness.light,
systemNavigationBarColor:
Theme.of(context).brightness == Brightness.light
? Color.fromRGBO(113, 113, 113, 1)
: Color.fromRGBO(15, 15, 15, 1),
),
child: AlertDialog(
titlePadding: EdgeInsets.only(
top: 20,
left: 40,
right: context.width / 3,
),
elevation: 1,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
title: Text(s.settingsTheme),
content: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
title: Text(s.settingsTheme),
content: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(5)),
child: Material(
color: Colors.transparent,
child: RadioListTile(
title: Text(s.systemDefault),
value: ThemeMode.system,
groupValue: settings.theme,
onChanged: (value) {
settings.setTheme = value;
Navigator.of(context).pop();
}),
),
),
ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(5)),
child: Material(
color: Colors.transparent,
child: RadioListTile(
title: Text(s.darkMode),
value: ThemeMode.dark,
groupValue: settings.theme,
onChanged: (value) {
settings.setTheme = value;
Navigator.of(context).pop();
}),
),
),
ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(5)),
child: Material(
color: Colors.transparent,
child: RadioListTile(
title: Text(s.lightMode),
value: ThemeMode.light,
groupValue: settings.theme,
onChanged: (value) {
settings.setTheme = value;
Navigator.of(context).pop();
}),
),
),
],
BorderRadius.all(Radius.circular(5)),
child: Material(
color: Colors.transparent,
child: RadioListTile(
title: Text(s.systemDefault),
value: ThemeMode.system,
groupValue: settings.theme,
onChanged: (value) {
settings.setTheme = value;
Navigator.of(context).pop();
}),
),
),
),
ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(5)),
child: Material(
color: Colors.transparent,
child: RadioListTile(
title: Text(s.darkMode),
value: ThemeMode.dark,
groupValue: settings.theme,
onChanged: (value) {
settings.setTheme = value;
Navigator.of(context).pop();
}),
),
),
ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(5)),
child: Material(
color: Colors.transparent,
child: RadioListTile(
title: Text(s.lightMode),
value: ThemeMode.light,
groupValue: settings.theme,
onChanged: (value) {
settings.setTheme = value;
Navigator.of(context).pop();
}),
),
),
],
),
)),
contentPadding: EdgeInsets.symmetric(horizontal: 70.0),
// leading: Icon(Icons.colorize),
title: Text(s.settingsTheme),
subtitle: Text(s.systemDefault),
),
Selector<SettingState, bool>(
selector: (_, setting) => setting.realDark,
builder: (_, data, __) => ListTile(
onTap: () => settings.setRealDark = !data,
contentPadding: const EdgeInsets.only(
left: 70.0, right: 20, bottom: 10, top: 10),
// leading: Icon(Icons.colorize),
title: Text(
s.settingsRealDark,
),
subtitle: Text(s.settingsRealDarkDes),
trailing: Transform.scale(
scale: 0.9,
child: Switch(
value: data,
onChanged: (boo) async {
settings.setRealDark = boo;
}),
),
),
),
ListTile(
onTap: () => generalDialog(
context,
title: Text.rich(TextSpan(text: s.chooseA, children: [
TextSpan(
text: ' ${s.color}',
style: TextStyle(
fontWeight: FontWeight.bold,
color: context.accentColor))
])),
content: _ColorPicker(
onColorChanged: (value) =>
settings.setAccentColor = value,
),
),
contentPadding: EdgeInsets.only(left: 70.0, right: 35),
title: Text(s.settingsAccentColor),
subtitle: Text(s.settingsAccentColorDes),
trailing: Container(
height: 25,
width: 25,
decoration: BoxDecoration(
shape: BoxShape.circle, color: context.accentColor),
),
),
Divider(height: 1),
],
),
),
)),
contentPadding: EdgeInsets.symmetric(horizontal: 70.0),
// leading: Icon(Icons.colorize),
title: Text(s.settingsTheme),
subtitle: Text(s.systemDefault),
),
Selector<SettingState, bool>(
selector: (_, setting) => setting.realDark,
builder: (_, data, __) => ListTile(
onTap: () => settings.setRealDark = !data,
contentPadding: const EdgeInsets.only(
left: 70.0, right: 20, bottom: 10, top: 10),
// leading: Icon(Icons.colorize),
title: Text(
s.settingsRealDark,
),
subtitle: Text(s.settingsRealDarkDes),
trailing: Transform.scale(
scale: 0.9,
child: Switch(
value: data,
onChanged: (boo) async {
settings.setRealDark = boo;
}),
),
),
),
ListTile(
onTap: () => generalDialog(
context,
title: Text.rich(TextSpan(text: s.chooseA, children: [
TextSpan(
text: ' ${s.color}',
style: TextStyle(
fontWeight: FontWeight.bold,
color: context.accentColor))
])),
content: _ColorPicker(
onColorChanged: (value) => settings.setAccentColor = value,
),
),
contentPadding: EdgeInsets.only(left: 70.0, right: 35),
title: Text(s.settingsAccentColor),
subtitle: Text(s.settingsAccentColorDes),
trailing: Container(
height: 25,
width: 25,
decoration: BoxDecoration(
shape: BoxShape.circle, color: context.accentColor),
),
),
Divider(height: 1),
Padding(
padding: EdgeInsets.all(10.0),
),
Container(
height: 30.0,
padding: EdgeInsets.symmetric(horizontal: 70),
alignment: Alignment.centerLeft,
child: Text(s.fontStyle,
style: Theme.of(context)
.textTheme
.bodyText1
.copyWith(color: Theme.of(context).accentColor)),
),
Selector<SettingState, int>(
selector: (_, setting) => setting.showNotesFontIndex,
builder: (_, data, __) => ListTile(
contentPadding: const EdgeInsets.only(
left: 70.0, right: 20, bottom: 10, top: 10),
title: Text(s.showNotesFonts),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: showNotesFontStyles.map<Widget>((textStyle) {
final index = showNotesFontStyles.indexOf(textStyle);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: InkWell(
onTap: () => settings.setShowNoteFontStyle = index,
borderRadius: BorderRadius.circular(10.0),
child: Container(
height: 60,
width: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: data == index
? context.accentColor.withAlpha(70)
: context.primaryColorDark),
color: data == index
? context.accentColor.withAlpha(70)
: Colors.transparent),
alignment: Alignment.center,
child: Text(
'Show notes',
textAlign: TextAlign.center,
style: textStyle,
),
),
),
);
}).toList(),
),
),
),
Divider(height: 1)
],
),
),

View File

@ -6,6 +6,7 @@ import 'package:connectivity/connectivity.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:intl/intl_standalone.dart';
import 'package:workmanager/workmanager.dart';
@ -79,6 +80,20 @@ ThemeData lightTheme = ThemeData(
buttonTheme: ButtonThemeData(height: 32),
);
final showNotesFontStyles = <TextStyle>[
TextStyle(
height: 1.8,
),
GoogleFonts.martel(
textStyle: TextStyle(
height: 1.8,
)),
GoogleFonts.bitter(
textStyle: TextStyle(
height: 1.8,
)),
];
class SettingState extends ChangeNotifier {
var themeStorage = KeyValueStorage(themesKey);
var accentStorage = KeyValueStorage(accentsKey);
@ -104,6 +119,7 @@ class SettingState extends ChangeNotifier {
var fastForwardSecondsStorage = KeyValueStorage(fastForwardSecondsKey);
var rewindSecondsStorage = KeyValueStorage(rewindSecondsKey);
var localeStorage = KeyValueStorage(localeKey);
var showNotesFontStorage = KeyValueStorage(showNotesFontKey);
Future initData() async {
await _getTheme();
@ -259,6 +275,15 @@ class SettingState extends ChangeNotifier {
_saveRewindSeconds();
}
int _showNotesFontIndex;
int get showNotesFontIndex => _showNotesFontIndex;
TextStyle get showNoteFontStyle => showNotesFontStyles[_showNotesFontIndex];
set setShowNoteFontStyle(int index) {
_showNotesFontIndex = index;
notifyListeners();
_saveShowNotesFonts();
}
@override
void addListener(VoidCallback listener) {
super.addListener(listener);
@ -267,6 +292,7 @@ class SettingState extends ChangeNotifier {
_getDownloadUsingData();
_getSleepTimerData();
_getPlayerSeconds();
_getShowNotesFonts();
_getUpdateInterval().then((value) async {
if (_initUpdateTag == 0) {
setWorkManager(24);
@ -361,63 +387,71 @@ class SettingState extends ChangeNotifier {
await S.load(_locale);
}
Future _saveAccentSetColor() async {
Future<void> _getShowNotesFonts() async {
_showNotesFontIndex = await showNotesFontStorage.getInt(defaultValue: 1);
}
Future<void> _saveAccentSetColor() async {
await accentStorage
.saveString(_accentSetColor.toString().substring(10, 16));
}
Future _setRealDark() async {
Future<void> _setRealDark() async {
await realDarkStorage.saveBool(_realDark);
}
Future saveShowIntro(int i) async {
Future<void> saveShowIntro(int i) async {
await introStorage.saveInt(i);
}
Future _saveUpdateInterval() async {
Future<void> _saveUpdateInterval() async {
await intervalStorage.saveInt(_updateInterval);
}
Future _saveTheme() async {
Future<void> _saveTheme() async {
await themeStorage.saveInt(_theme.index);
}
Future _saveAutoUpdate() async {
Future<void> _saveAutoUpdate() async {
await autoupdateStorage.saveBool(_autoUpdate, reverse: true);
}
Future _saveAutoPlay() async {
Future<void> _saveAutoPlay() async {
await autoPlayStorage.saveBool(_autoPlay, reverse: true);
}
Future _setDefaultSleepTimer() async {
Future<void> _setDefaultSleepTimer() async {
await defaultSleepTimerStorage.saveInt(_defaultSleepTimer);
}
Future _saveAutoSleepTimer() async {
Future<void> _saveAutoSleepTimer() async {
await autoSleepTimerStorage.saveBool(_autoSleepTimer);
}
Future _saveAutoSleepTimerMode() async {
Future<void> _saveAutoSleepTimerMode() async {
await autoSleepTimerModeStorage.saveInt(_autoSleepTimerMode);
}
Future _saveAutoSleepTimerStart() async {
Future<void> _saveAutoSleepTimerStart() async {
await autoSleepTimerStartStorage.saveInt(_autoSleepTimerStart);
}
Future _saveAutoSleepTimerEnd() async {
Future<void> _saveAutoSleepTimerEnd() async {
await autoSleepTimerEndStorage.saveInt(_autoSleepTimerEnd);
}
Future _saveFastForwardSeconds() async {
Future<void> _saveFastForwardSeconds() async {
await fastForwardSecondsStorage.saveInt(_fastForwardSeconds);
}
Future _saveRewindSeconds() async {
Future<void> _saveRewindSeconds() async {
await rewindSecondsStorage.saveInt(_rewindSeconds);
}
Future<void> _saveShowNotesFonts() async {
await showNotesFontStorage.saveInt(_showNotesFontIndex);
}
Future<SettingsBackup> backup() async {
var theme = await themeStorage.getInt();
var accentColor = await accentStorage.getString();
@ -458,6 +492,7 @@ class SettingState extends ChangeNotifier {
await KeyValueStorage(hideListenedKey).getBool(defaultValue: false);
var notificationLayout =
await KeyValueStorage(notificationLayoutKey).getInt(defaultValue: 0);
var showNotesFont = await showNotesFontStorage.getInt(defaultValue: 1);
return SettingsBackup(
theme: theme,
@ -486,7 +521,8 @@ class SettingState extends ChangeNotifier {
playerHeight: playerHeight,
locale: backupLocale,
hideListened: hideListened,
notificationLayout: notificationLayout);
notificationLayout: notificationLayout,
showNotesFont: showNotesFont);
}
Future<void> restore(SettingsBackup backup) async {
@ -520,6 +556,7 @@ class SettingState extends ChangeNotifier {
await KeyValueStorage(hideListenedKey).saveBool(backup.hideListened);
await KeyValueStorage(notificationLayoutKey)
.saveInt(backup.notificationLayout);
await showNotesFontStorage.saveInt(backup.showNotesFont);
if (backup.locale == '') {
await localeStorage.saveStringList([]);
await S.load(Locale(Intl.systemLocale));
@ -539,6 +576,7 @@ class SettingState extends ChangeNotifier {
await _getAutoUpdate();
await _getDownloadUsingData();
await _getSleepTimerData();
await _getShowNotesFonts();
await _getUpdateInterval().then((value) async {
if (_autoUpdate) {
await cancelWork();

View File

@ -26,6 +26,7 @@ class SettingsBackup {
final String locale;
final bool hideListened;
final int notificationLayout;
final int showNotesFont;
SettingsBackup(
{this.theme,
this.accentColor,
@ -53,7 +54,8 @@ class SettingsBackup {
this.playerHeight,
this.locale,
this.hideListened,
this.notificationLayout});
this.notificationLayout,
this.showNotesFont});
Map<String, Object> toJson() {
return {
@ -82,7 +84,8 @@ class SettingsBackup {
'playerHeight': playerHeight,
'locale': locale,
'hideListened': hideListened,
'notificationLayout': notificationLayout
'notificationLayout': notificationLayout,
'showNotesFont': showNotesFont
};
}
@ -114,6 +117,7 @@ class SettingsBackup {
playerHeight: json['playerHeight'] as int,
locale: json['locale'] as String,
hideListened: json['hideListened'] as bool,
notificationLayout: json['notificationLayout'] as int);
notificationLayout: json['notificationLayout'] as int,
showNotesFont: json['showNotesFont'] as int);
}
}