Add settings
This commit is contained in:
parent
4f6d03c5cb
commit
7138f9b76c
|
@ -3,6 +3,7 @@ import 'dart:convert';
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:lemmy_api_client/v3.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
|
@ -44,6 +45,64 @@ class ConfigStore extends ChangeNotifier {
|
|||
save();
|
||||
}
|
||||
|
||||
late bool _showAvatars;
|
||||
@JsonKey(defaultValue: true)
|
||||
bool get showAvatars => _showAvatars;
|
||||
set showAvatars(bool showAvatars) {
|
||||
_showAvatars = showAvatars;
|
||||
notifyListeners();
|
||||
save();
|
||||
}
|
||||
|
||||
late bool _showNsfw;
|
||||
@JsonKey(defaultValue: false)
|
||||
bool get showNsfw => _showNsfw;
|
||||
set showNsfw(bool showNsfw) {
|
||||
_showNsfw = showNsfw;
|
||||
notifyListeners();
|
||||
save();
|
||||
}
|
||||
|
||||
late bool _showScores;
|
||||
@JsonKey(defaultValue: true)
|
||||
bool get showScores => _showScores;
|
||||
set showScores(bool showScores) {
|
||||
_showScores = showScores;
|
||||
notifyListeners();
|
||||
save();
|
||||
}
|
||||
|
||||
void importLemmyUserSettings(LocalUserSettings localUserSettings) {
|
||||
// themes from lemmy-ui that are dark mode
|
||||
// const darkModeLemmyUiThemes = {
|
||||
// 'solar',
|
||||
// 'cyborg',
|
||||
// 'darkly',
|
||||
// 'vaporwave-dark',
|
||||
// // TODO: is it dark theme?
|
||||
// 'i386',
|
||||
// };
|
||||
|
||||
_showAvatars = localUserSettings.showAvatars;
|
||||
_showNsfw = localUserSettings.showNsfw;
|
||||
// TODO: should these also be imported? If so, how?
|
||||
// _theme = darkModeLemmyUiThemes.contains(localUserSettings.theme)
|
||||
// ? ThemeMode.dark
|
||||
// : ThemeMode.light;
|
||||
// _locale = L10n.supportedLocales.contains(Locale(localUserSettings.lang))
|
||||
// ? Locale(localUserSettings.lang)
|
||||
// : _locale;
|
||||
// TODO: add when it is released
|
||||
// _showScores = localUserSettings.showScores;
|
||||
|
||||
// TODO: should these even be supported? Or we should use our own per-community setting
|
||||
// SortType defaultSortType
|
||||
// PostListingType defaultListingType
|
||||
|
||||
notifyListeners();
|
||||
save();
|
||||
}
|
||||
|
||||
static Future<ConfigStore> load() async {
|
||||
final prefs = await _prefs;
|
||||
|
||||
|
|
|
@ -11,7 +11,10 @@ ConfigStore _$ConfigStoreFromJson(Map<String, dynamic> json) {
|
|||
..theme = _$enumDecodeNullable(_$ThemeModeEnumMap, json['theme']) ??
|
||||
ThemeMode.system
|
||||
..amoledDarkMode = json['amoledDarkMode'] as bool? ?? false
|
||||
..locale = LocaleSerde.fromJson(json['locale'] as String?);
|
||||
..locale = LocaleSerde.fromJson(json['locale'] as String?)
|
||||
..showAvatars = json['showAvatars'] as bool? ?? true
|
||||
..showNsfw = json['showNsfw'] as bool? ?? false
|
||||
..showScores = json['showScores'] as bool? ?? true;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$ConfigStoreToJson(ConfigStore instance) =>
|
||||
|
@ -19,6 +22,9 @@ Map<String, dynamic> _$ConfigStoreToJson(ConfigStore instance) =>
|
|||
'theme': _$ThemeModeEnumMap[instance.theme],
|
||||
'amoledDarkMode': instance.amoledDarkMode,
|
||||
'locale': LocaleSerde.toJson(instance.locale),
|
||||
'showAvatars': instance.showAvatars,
|
||||
'showNsfw': instance.showNsfw,
|
||||
'showScores': instance.showScores,
|
||||
};
|
||||
|
||||
K _$enumDecode<K, V>(
|
||||
|
|
Loading…
Reference in New Issue