feat: New account data wallpaper feature
This commit is contained in:
parent
26f4e99006
commit
3b9245c8c7
11 changed files with 262 additions and 34 deletions
|
|
@ -1,7 +1,12 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/utils/account_config.dart';
|
||||
import 'package:fluffychat/widgets/app_lock.dart';
|
||||
import 'package:fluffychat/widgets/theme_builder.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import 'settings_style_view.dart';
|
||||
|
|
@ -19,6 +24,51 @@ class SettingsStyleController extends State<SettingsStyle> {
|
|||
ThemeController.of(context).setPrimaryColor(color);
|
||||
}
|
||||
|
||||
void setWallpaper() async {
|
||||
final client = Matrix.of(context).client;
|
||||
final picked = await AppLock.of(context).pauseWhile(
|
||||
FilePicker.platform.pickFiles(
|
||||
type: FileType.image,
|
||||
withData: true,
|
||||
),
|
||||
);
|
||||
final pickedFile = picked?.files.firstOrNull;
|
||||
if (pickedFile == null) return;
|
||||
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
final url = await client.uploadContent(
|
||||
pickedFile.bytes!,
|
||||
filename: pickedFile.name,
|
||||
);
|
||||
await client.updateApplicationAccountConfig(
|
||||
ApplicationAccountConfig(wallpaperUrl: url),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void setChatWallpaperOpacity(double opacity) {
|
||||
final client = Matrix.of(context).client;
|
||||
showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => client.updateApplicationAccountConfig(
|
||||
ApplicationAccountConfig(wallpaperOpacity: opacity),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void deleteChatWallpaper() => showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.setApplicationAccountConfig(
|
||||
const ApplicationAccountConfig(
|
||||
wallpaperUrl: null,
|
||||
wallpaperOpacity: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
ThemeMode get currentTheme => ThemeController.of(context).themeMode;
|
||||
Color? get currentColor => ThemeController.of(context).primaryColor;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/utils/account_config.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:fluffychat/widgets/mxc_image.dart';
|
||||
import '../../config/app_config.dart';
|
||||
import 'settings_style.dart';
|
||||
|
||||
|
|
@ -15,6 +19,7 @@ class SettingsStyleView extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const colorPickerSize = 32.0;
|
||||
final client = Matrix.of(context).client;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: const Center(child: BackButton()),
|
||||
|
|
@ -166,27 +171,104 @@ class SettingsStyleView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Material(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
child: Text(
|
||||
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
fontSize:
|
||||
AppConfig.messageFontSize * AppConfig.fontSizeFactor,
|
||||
),
|
||||
),
|
||||
),
|
||||
StreamBuilder(
|
||||
stream: client.onAccountData.stream.where(
|
||||
(data) =>
|
||||
data.type ==
|
||||
ApplicationAccountConfigExtension.accountDataKey,
|
||||
),
|
||||
builder: (context, snapshot) {
|
||||
final accountConfig = client.applicationAccountConfig;
|
||||
final wallpaperOpacity = accountConfig.wallpaperOpacity ?? 1;
|
||||
final wallpaperOpacityIsDefault = wallpaperOpacity == 1;
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
duration: FluffyThemes.animationDuration,
|
||||
curve: FluffyThemes.animationCurve,
|
||||
alignment: Alignment.centerLeft,
|
||||
decoration: const BoxDecoration(),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: Stack(
|
||||
children: [
|
||||
if (accountConfig.wallpaperUrl != null)
|
||||
Opacity(
|
||||
opacity: wallpaperOpacity,
|
||||
child: MxcImage(
|
||||
uri: accountConfig.wallpaperUrl,
|
||||
fit: BoxFit.cover,
|
||||
isThumbnail: true,
|
||||
width: FluffyThemes.columnWidth * 2,
|
||||
height: 156,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 12 + 12 + Avatar.defaultSize,
|
||||
right: 12,
|
||||
top: accountConfig.wallpaperUrl == null ? 0 : 12,
|
||||
bottom: 12,
|
||||
),
|
||||
child: Material(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(
|
||||
AppConfig.borderRadius,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
child: Text(
|
||||
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimaryContainer,
|
||||
fontSize: AppConfig.messageFontSize *
|
||||
AppConfig.fontSizeFactor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(L10n.of(context)!.wallpaper),
|
||||
leading: const Icon(Icons.photo_outlined),
|
||||
trailing: accountConfig.wallpaperUrl == null
|
||||
? null
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.delete_outlined),
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
onPressed: controller.deleteChatWallpaper,
|
||||
),
|
||||
onTap: controller.setWallpaper,
|
||||
),
|
||||
AnimatedSize(
|
||||
duration: FluffyThemes.animationDuration,
|
||||
curve: FluffyThemes.animationCurve,
|
||||
child: accountConfig.wallpaperUrl != null
|
||||
? SwitchListTile.adaptive(
|
||||
title: Text(L10n.of(context)!.transparent),
|
||||
secondary: const Icon(Icons.blur_linear_outlined),
|
||||
value: !wallpaperOpacityIsDefault,
|
||||
onChanged: (_) =>
|
||||
controller.setChatWallpaperOpacity(
|
||||
wallpaperOpacityIsDefault ? 0.4 : 1,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(L10n.of(context)!.fontSize),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue