fix: move use activity image background setting into pangea user-specific style settings
This commit is contained in:
parent
ef09e58e94
commit
d99936dc62
6 changed files with 80 additions and 26 deletions
|
|
@ -35,8 +35,6 @@ abstract class SettingKeys {
|
|||
static const String displayNavigationRail =
|
||||
'chat.fluffy.display_navigation_rail';
|
||||
// #Pangea
|
||||
static const String useActivityImageAsChatBackground =
|
||||
'pangea.use_activity_image_as_chat_background';
|
||||
static const String volume = 'pangea.volume';
|
||||
static const String showedActivityMenu =
|
||||
'pangea.showed_activity_menu_tutorial';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/user/style_settings_repo.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'settings_chat_view.dart';
|
||||
|
||||
class SettingsChat extends StatefulWidget {
|
||||
|
|
@ -10,6 +13,15 @@ class SettingsChat extends StatefulWidget {
|
|||
}
|
||||
|
||||
class SettingsChatController extends State<SettingsChat> {
|
||||
// #Pangea
|
||||
Future<void> setUseActivityImageBackground(bool value) async {
|
||||
final userId = Matrix.of(context).client.userID!;
|
||||
AppConfig.useActivityImageAsChatBackground = value;
|
||||
setState(() {});
|
||||
await StyleSettingsRepo.setUseActivityImageBackground(userId, value);
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SettingsChatView(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,12 +80,10 @@ class SettingsChatView extends StatelessWidget {
|
|||
),
|
||||
|
||||
// #Pangea
|
||||
SettingsSwitchListTile.adaptive(
|
||||
title: L10n.of(context).useActivityImageAsChatBackground,
|
||||
onChanged: (b) =>
|
||||
AppConfig.useActivityImageAsChatBackground = b,
|
||||
storeKey: SettingKeys.useActivityImageAsChatBackground,
|
||||
defaultValue: AppConfig.useActivityImageAsChatBackground,
|
||||
SwitchListTile.adaptive(
|
||||
value: AppConfig.useActivityImageAsChatBackground,
|
||||
title: Text(L10n.of(context).useActivityImageAsChatBackground),
|
||||
onChanged: controller.setUseActivityImageBackground,
|
||||
),
|
||||
// Divider(color: theme.dividerColor),
|
||||
// ListTile(
|
||||
|
|
|
|||
|
|
@ -66,8 +66,10 @@ class PangeaController {
|
|||
});
|
||||
subscriptionController.reinitialize();
|
||||
|
||||
StyleSettingsRepo.fontSizeFactor(userID!).then((factor) {
|
||||
AppConfig.fontSizeFactor = factor;
|
||||
StyleSettingsRepo.settings(userID!).then((settings) {
|
||||
AppConfig.fontSizeFactor = settings.fontSizeFactor;
|
||||
AppConfig.useActivityImageAsChatBackground =
|
||||
settings.useActivityImageBackground;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,39 @@
|
|||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
class _StyleSettings {
|
||||
final double fontSizeFactor;
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
|
||||
const _StyleSettings({
|
||||
class StyleSettings {
|
||||
final double fontSizeFactor;
|
||||
final bool useActivityImageBackground;
|
||||
|
||||
const StyleSettings({
|
||||
this.fontSizeFactor = 1.0,
|
||||
this.useActivityImageBackground = true,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'fontSizeFactor': fontSizeFactor,
|
||||
'useActivityImageBackground': useActivityImageBackground,
|
||||
};
|
||||
}
|
||||
|
||||
factory _StyleSettings.fromJson(Map<String, dynamic> json) {
|
||||
return _StyleSettings(
|
||||
factory StyleSettings.fromJson(Map<String, dynamic> json) {
|
||||
return StyleSettings(
|
||||
fontSizeFactor: (json['fontSizeFactor'] as num?)?.toDouble() ?? 1.0,
|
||||
useActivityImageBackground:
|
||||
json['useActivityImageBackground'] as bool? ?? true,
|
||||
);
|
||||
}
|
||||
|
||||
StyleSettings copyWith({
|
||||
double? fontSizeFactor,
|
||||
bool? useActivityImageBackground,
|
||||
}) {
|
||||
return StyleSettings(
|
||||
fontSizeFactor: fontSizeFactor ?? this.fontSizeFactor,
|
||||
useActivityImageBackground:
|
||||
useActivityImageBackground ?? this.useActivityImageBackground,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -23,18 +41,42 @@ class _StyleSettings {
|
|||
class StyleSettingsRepo {
|
||||
static final GetStorage _storage = GetStorage("style_settings");
|
||||
|
||||
static Future<double> fontSizeFactor(String userId) async {
|
||||
static String _storageKey(String userId) => '${userId}_style_settings';
|
||||
|
||||
static Future<StyleSettings> settings(String userId) async {
|
||||
await GetStorage.init("style_settings");
|
||||
final json =
|
||||
_storage.read<Map<String, dynamic>>('${userId}_style_settings');
|
||||
final settings =
|
||||
json != null ? _StyleSettings.fromJson(json) : const _StyleSettings();
|
||||
return settings.fontSizeFactor;
|
||||
final key = _storageKey(userId);
|
||||
final json = _storage.read<Map<String, dynamic>>(key);
|
||||
if (json == null) return const StyleSettings();
|
||||
try {
|
||||
return StyleSettings.fromJson(json);
|
||||
} catch (e, s) {
|
||||
ErrorHandler.logError(
|
||||
e: e,
|
||||
s: s,
|
||||
data: {
|
||||
"settings_entry": json,
|
||||
},
|
||||
);
|
||||
_storage.remove(key);
|
||||
return const StyleSettings();
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> setFontSizeFactor(String userId, double factor) async {
|
||||
await GetStorage.init("style_settings");
|
||||
final settings = _StyleSettings(fontSizeFactor: factor);
|
||||
await _storage.write('${userId}_style_settings', settings.toJson());
|
||||
final currentSettings = await settings(userId);
|
||||
final updatedSettings = currentSettings.copyWith(fontSizeFactor: factor);
|
||||
await _storage.write(_storageKey(userId), updatedSettings.toJson());
|
||||
}
|
||||
|
||||
static Future<void> setUseActivityImageBackground(
|
||||
String userId,
|
||||
bool useBackground,
|
||||
) async {
|
||||
final currentSettings = await settings(userId);
|
||||
final updatedSettings = currentSettings.copyWith(
|
||||
useActivityImageBackground: useBackground,
|
||||
);
|
||||
await _storage.write(_storageKey(userId), updatedSettings.toJson());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -567,8 +567,10 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
// double.tryParse(store.getString(SettingKeys.fontSizeFactor) ?? '') ??
|
||||
// AppConfig.fontSizeFactor;
|
||||
if (client.isLogged()) {
|
||||
StyleSettingsRepo.fontSizeFactor(client.userID!).then((factor) {
|
||||
AppConfig.fontSizeFactor = factor;
|
||||
StyleSettingsRepo.settings(client.userID!).then((settings) {
|
||||
AppConfig.fontSizeFactor = settings.fontSizeFactor;
|
||||
AppConfig.useActivityImageAsChatBackground =
|
||||
settings.useActivityImageBackground;
|
||||
});
|
||||
}
|
||||
// Pangea#
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue