2022-01-23 23:56:26 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2022-01-19 13:47:54 +01:00
|
|
|
import 'package:get_it/get_it.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
final SharedPreferences _prefs = GetIt.instance.get<SharedPreferences>();
|
|
|
|
|
2022-01-23 23:56:26 +01:00
|
|
|
enum JapaneseFont {
|
|
|
|
none,
|
|
|
|
droidSansJapanese,
|
|
|
|
notoSansCJK,
|
|
|
|
notoSerifCJK,
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Methods on JapaneseFont {
|
|
|
|
TextStyle get textStyle {
|
|
|
|
String? fontFamily;
|
|
|
|
switch (this) {
|
|
|
|
case JapaneseFont.droidSansJapanese:
|
|
|
|
fontFamily = 'Droid Sans Japanese';
|
|
|
|
break;
|
|
|
|
case JapaneseFont.notoSansCJK:
|
|
|
|
fontFamily = 'Noto Sans CJK';
|
|
|
|
break;
|
|
|
|
case JapaneseFont.notoSerifCJK:
|
|
|
|
fontFamily = 'Noto Serif CJK';
|
|
|
|
break;
|
|
|
|
case JapaneseFont.none:
|
|
|
|
}
|
|
|
|
return TextStyle(fontFamily: fontFamily);
|
|
|
|
}
|
|
|
|
|
|
|
|
String get name =>
|
|
|
|
{
|
|
|
|
JapaneseFont.none: 'Default',
|
|
|
|
JapaneseFont.droidSansJapanese: 'Droid Sans Japanese',
|
|
|
|
JapaneseFont.notoSansCJK: 'Noto Sans CJK',
|
|
|
|
JapaneseFont.notoSerifCJK: 'Noto Serif CJK',
|
|
|
|
}[this] ??
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
|
2022-01-25 00:54:21 +01:00
|
|
|
const String appVersion = '0.1 Beta';
|
|
|
|
|
2022-01-19 13:47:54 +01:00
|
|
|
const Map<String, dynamic> _defaults = {
|
|
|
|
'romajiEnabled': false,
|
2022-01-23 18:27:00 +01:00
|
|
|
'extensiveSearch': true,
|
2022-01-19 13:47:54 +01:00
|
|
|
'darkThemeEnabled': false,
|
|
|
|
'autoThemeEnabled': false,
|
2022-01-23 23:56:26 +01:00
|
|
|
'japaneseFont': JapaneseFont.droidSansJapanese,
|
2022-01-19 13:47:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
bool _getSettingOrDefault(String settingName) =>
|
|
|
|
_prefs.getBool(settingName) ?? _defaults[settingName];
|
|
|
|
|
|
|
|
bool get romajiEnabled => _getSettingOrDefault('romajiEnabled');
|
2022-01-23 18:27:00 +01:00
|
|
|
bool get extensiveSearchEnabled => _getSettingOrDefault('extensiveSearch');
|
2022-01-19 13:47:54 +01:00
|
|
|
bool get darkThemeEnabled => _getSettingOrDefault('darkThemeEnabled');
|
|
|
|
bool get autoThemeEnabled => _getSettingOrDefault('autoThemeEnabled');
|
2022-01-23 23:56:26 +01:00
|
|
|
JapaneseFont get japaneseFont {
|
|
|
|
final int? i = _prefs.getInt('japaneseFont');
|
|
|
|
return (i != null) ? JapaneseFont.values[i] : _defaults['japaneseFont'];
|
|
|
|
}
|
2022-01-19 13:47:54 +01:00
|
|
|
|
|
|
|
set romajiEnabled(b) => _prefs.setBool('romajiEnabled', b);
|
2022-01-23 18:27:00 +01:00
|
|
|
set extensiveSearchEnabled(b) => _prefs.setBool('extensiveSearch', b);
|
2022-01-19 13:47:54 +01:00
|
|
|
set darkThemeEnabled(b) => _prefs.setBool('darkThemeEnabled', b);
|
|
|
|
set autoThemeEnabled(b) => _prefs.setBool('autoThemeEnabled', b);
|
2022-01-23 23:56:26 +01:00
|
|
|
set japaneseFont(JapaneseFont jf) => _prefs.setInt('japaneseFont', jf.index);
|