- TatuPalette.scheme aceita softenPrimary e passa a usar a seed como primary, onPrimary por contraste e surfaceTint, em vez da paleta tonal do Material 3 - nova opcao AppSettings.softenThemeColor (default false, ou seja cor exacta) - interruptor 'Suavizar cor do tema' em Configuracoes > Aparencia, com l10n en/pt - a opcao e sincronizada via account data (soften_theme_color) e mantida localmente como fallback, tal como a cor do tema - setApplicationAccountColor e updateApplicationAccountConfig preservam o novo campo - um unico sync de account data actualiza cor e opcao - testes de serializacao e round-trip para o novo campo
164 lines
4.8 KiB
Dart
164 lines
4.8 KiB
Dart
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
|
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
import 'package:tatchat/config/setting_keys.dart';
|
|
import 'package:tatchat/utils/account_config.dart';
|
|
import 'package:tatchat/utils/file_selector.dart';
|
|
import 'package:tatchat/widgets/future_loading_dialog.dart';
|
|
import 'package:tatchat/widgets/theme_builder.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import '../../widgets/matrix.dart';
|
|
import 'settings_style_view.dart';
|
|
|
|
class SettingsStyle extends StatefulWidget {
|
|
const SettingsStyle({super.key});
|
|
|
|
@override
|
|
SettingsStyleController createState() => SettingsStyleController();
|
|
}
|
|
|
|
class SettingsStyleController extends State<SettingsStyle> {
|
|
Future<void> setChatColor(Color? color) async {
|
|
final client = Matrix.of(context).client;
|
|
final themeController = ThemeController.of(context);
|
|
AppSettings.colorSchemeSeedInt.setItem(
|
|
color?.toARGB32() ?? AppSettings.colorSchemeSeedInt.defaultValue,
|
|
);
|
|
await themeController.setPrimaryColor(color);
|
|
try {
|
|
await client.setApplicationAccountColor(color?.toARGB32());
|
|
} catch (e, s) {
|
|
Logs().e('Unable to save chat color', e, s);
|
|
}
|
|
}
|
|
|
|
Future<void> setWallpaper() async {
|
|
final client = Matrix.of(context).client;
|
|
final picked = await selectFiles(context, type: FileType.image);
|
|
final pickedFile = picked.firstOrNull;
|
|
if (pickedFile == null) return;
|
|
if (!mounted) return;
|
|
|
|
await showFutureLoadingDialog(
|
|
context: context,
|
|
future: () async {
|
|
final url = await client.uploadContent(
|
|
await pickedFile.readAsBytes(),
|
|
filename: pickedFile.name,
|
|
);
|
|
await client.updateApplicationAccountConfig(
|
|
ApplicationAccountConfig(wallpaperUrl: url),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
double get wallpaperOpacity =>
|
|
_wallpaperOpacity ??
|
|
Matrix.of(context).client.applicationAccountConfig.wallpaperOpacity ??
|
|
0.5;
|
|
|
|
double? _wallpaperOpacity;
|
|
|
|
Future<void> saveWallpaperOpacity(double opacity) async {
|
|
final client = Matrix.of(context).client;
|
|
final result = await showFutureLoadingDialog(
|
|
context: context,
|
|
future: () => client.updateApplicationAccountConfig(
|
|
ApplicationAccountConfig(wallpaperOpacity: opacity),
|
|
),
|
|
);
|
|
if (result.isValue) return;
|
|
|
|
setState(() {
|
|
_wallpaperOpacity = client.applicationAccountConfig.wallpaperOpacity;
|
|
});
|
|
}
|
|
|
|
void updateWallpaperOpacity(double opacity) {
|
|
setState(() {
|
|
_wallpaperOpacity = opacity;
|
|
});
|
|
}
|
|
|
|
double get wallpaperBlur =>
|
|
_wallpaperBlur ??
|
|
Matrix.of(context).client.applicationAccountConfig.wallpaperBlur ??
|
|
0.5;
|
|
double? _wallpaperBlur;
|
|
|
|
Future<void> saveWallpaperBlur(double blur) async {
|
|
final client = Matrix.of(context).client;
|
|
final result = await showFutureLoadingDialog(
|
|
context: context,
|
|
future: () => client.updateApplicationAccountConfig(
|
|
ApplicationAccountConfig(wallpaperBlur: blur),
|
|
),
|
|
);
|
|
if (result.isValue) return;
|
|
|
|
setState(() {
|
|
_wallpaperBlur = client.applicationAccountConfig.wallpaperBlur;
|
|
});
|
|
}
|
|
|
|
void updateWallpaperBlur(double blur) {
|
|
setState(() {
|
|
_wallpaperBlur = blur;
|
|
});
|
|
}
|
|
|
|
void deleteChatWallpaper() {
|
|
final client = Matrix.of(context).client;
|
|
showFutureLoadingDialog(
|
|
context: context,
|
|
future: () => client.setApplicationAccountConfig(
|
|
ApplicationAccountConfig(
|
|
wallpaperUrl: null,
|
|
wallpaperBlur: null,
|
|
primaryColor: client.applicationAccountConfig.primaryColor,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
ThemeMode get currentTheme => ThemeController.of(context).themeMode;
|
|
Color? get currentColor => ThemeController.of(context).primaryColor;
|
|
|
|
bool get softenThemeColor => ThemeController.of(context).softenPrimaryColor;
|
|
|
|
Future<void> setSoftenThemeColor(bool soften) async {
|
|
await ThemeController.of(context).setSoftenPrimaryColor(soften);
|
|
setState(() {});
|
|
}
|
|
|
|
void switchTheme(ThemeMode? newTheme) {
|
|
if (newTheme == null) return;
|
|
switch (newTheme) {
|
|
case ThemeMode.light:
|
|
ThemeController.of(context).setThemeMode(ThemeMode.light);
|
|
break;
|
|
case ThemeMode.dark:
|
|
ThemeController.of(context).setThemeMode(ThemeMode.dark);
|
|
break;
|
|
case ThemeMode.system:
|
|
ThemeController.of(context).setThemeMode(ThemeMode.system);
|
|
break;
|
|
}
|
|
setState(() {});
|
|
}
|
|
|
|
Future<void> changeFontSizeFactor(double d) async {
|
|
await AppSettings.fontSizeFactor.setItem(d);
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => SettingsStyleView(this);
|
|
}
|