1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-20 20:13:55 +01:00
git-touch-android-ios-app/lib/models/code.dart

95 lines
2.4 KiB
Dart
Raw Normal View History

import 'package:fimber/fimber.dart';
2019-09-15 11:36:09 +02:00
import 'package:flutter/foundation.dart';
import 'package:flutter_highlight/theme_map.dart';
2019-09-15 12:27:46 +02:00
import 'package:git_touch/utils/utils.dart';
2019-09-15 11:36:09 +02:00
import 'package:shared_preferences/shared_preferences.dart';
class CodeModel with ChangeNotifier {
static var themes = themeMap.keys.toList();
static const fontSizes = [12, 13, 14, 15, 16, 17, 18, 19, 20];
2019-09-15 12:27:46 +02:00
static const fontFamilies = [
'System',
'Fira Code',
'Inconsolata',
'PT Mono',
'Source Code Pro',
'Ubuntu Mono'
];
2019-09-15 11:36:09 +02:00
2020-01-12 10:13:48 +01:00
String _theme = 'github-gist';
String _themeDark = 'vs2015';
int _fontSize = 14;
2019-09-15 11:36:09 +02:00
String _fontFamily = 'System';
String get theme => _theme;
2020-01-12 10:13:48 +01:00
String get themeDark => _themeDark;
2019-09-15 11:36:09 +02:00
int get fontSize => _fontSize;
String get fontFamily => _fontFamily;
2019-09-15 12:27:46 +02:00
String get fontFamilyUsed =>
2019-10-02 10:09:54 +02:00
_fontFamily == 'System' ? CommonStyle.monospace : _fontFamily;
2019-09-15 11:36:09 +02:00
2019-11-05 08:09:54 +01:00
Future<void> init() async {
2019-09-15 11:36:09 +02:00
var prefs = await SharedPreferences.getInstance();
2020-01-16 05:52:47 +01:00
var vh = prefs.getString(StorageKeys.codeTheme);
var vdh = prefs.getString(StorageKeys.codeThemeDark);
var vs = prefs.getInt(StorageKeys.iCodeFontSize);
var vf = prefs.getString(StorageKeys.codeFontFamily);
2019-09-15 11:36:09 +02:00
Fimber.d('read code: $vh, $vs, $vf');
2019-09-15 11:36:09 +02:00
if (themeMap.keys.contains(vh)) {
_theme = vh;
}
2020-01-12 10:13:48 +01:00
if (themeMap.keys.contains(vdh)) {
_themeDark = vdh;
}
2019-09-15 11:36:09 +02:00
if (fontSizes.contains(vs)) {
_fontSize = vs;
}
if (fontFamilies.contains(vf)) {
_fontFamily = vf;
}
notifyListeners();
}
setTheme(String v) async {
var prefs = await SharedPreferences.getInstance();
2020-01-16 05:52:47 +01:00
await prefs.setString(StorageKeys.codeTheme, v);
Fimber.d('write code theme: $v');
2019-09-15 11:36:09 +02:00
_theme = v;
notifyListeners();
}
2020-01-12 10:13:48 +01:00
setThemeDark(String v) async {
var prefs = await SharedPreferences.getInstance();
2020-01-16 05:52:47 +01:00
await prefs.setString(StorageKeys.codeThemeDark, v);
2020-01-12 10:13:48 +01:00
Fimber.d('write code theme dark: $v');
_themeDark = v;
notifyListeners();
}
2019-09-15 11:36:09 +02:00
setFontSize(int v) async {
var prefs = await SharedPreferences.getInstance();
2020-01-16 05:52:47 +01:00
await prefs.setInt(StorageKeys.iCodeFontSize, v);
Fimber.d('write code font size: $v');
2019-09-15 11:36:09 +02:00
_fontSize = v;
notifyListeners();
}
setFontFamily(String v) async {
var prefs = await SharedPreferences.getInstance();
2020-01-16 05:52:47 +01:00
await prefs.setString(StorageKeys.codeFontFamily, v);
Fimber.d('write code font family: $v');
2019-09-15 11:36:09 +02:00
_fontFamily = v;
notifyListeners();
}
}