Reapply "Добавил кастомизацию+, убрал жесты потому что они мне жизнь сломали"

This reverts commit e5beed10d9.
This commit is contained in:
jganenok
2025-12-05 18:42:29 +07:00
parent e5beed10d9
commit dd6e9107f4
7 changed files with 1234 additions and 260 deletions

View File

@@ -2000,10 +2000,40 @@ class _ChatsScreenState extends State<ChatsScreen>
if (widget.hasScaffold) { if (widget.hasScaffold) {
return Builder( return Builder(
builder: (context) { builder: (context) {
final theme = context.watch<ThemeProvider>();
BoxDecoration? chatsListDecoration;
if (theme.chatsListBackgroundType == ChatsListBackgroundType.gradient) {
chatsListDecoration = BoxDecoration(
gradient: LinearGradient(
colors: [
theme.chatsListGradientColor1,
theme.chatsListGradientColor2,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
);
} else if (theme.chatsListBackgroundType == ChatsListBackgroundType.image &&
theme.chatsListImagePath != null &&
theme.chatsListImagePath!.isNotEmpty) {
chatsListDecoration = BoxDecoration(
image: DecorationImage(
image: FileImage(File(theme.chatsListImagePath!)),
fit: BoxFit.cover,
),
);
}
return Scaffold( return Scaffold(
appBar: _buildAppBar(context), appBar: _buildAppBar(context),
drawer: _buildAppDrawer(context), drawer: _buildAppDrawer(context),
body: Row(children: [Expanded(child: bodyContent)]), body: chatsListDecoration != null
? Container(
decoration: chatsListDecoration,
child: Row(children: [Expanded(child: bodyContent)]),
)
: Row(children: [Expanded(child: bodyContent)]),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () { onPressed: () {
_showAddMenu(context); _showAddMenu(context);
@@ -2048,7 +2078,30 @@ class _ChatsScreenState extends State<ChatsScreen>
right: 16.0, right: 16.0,
bottom: 16.0, bottom: 16.0,
), ),
decoration: BoxDecoration(color: colors.primaryContainer), decoration: () {
if (themeProvider.drawerBackgroundType == DrawerBackgroundType.gradient) {
return BoxDecoration(
gradient: LinearGradient(
colors: [
themeProvider.drawerGradientColor1,
themeProvider.drawerGradientColor2,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
);
} else if (themeProvider.drawerBackgroundType == DrawerBackgroundType.image &&
themeProvider.drawerImagePath != null &&
themeProvider.drawerImagePath!.isNotEmpty) {
return BoxDecoration(
image: DecorationImage(
image: FileImage(File(themeProvider.drawerImagePath!)),
fit: BoxFit.cover,
),
);
}
return BoxDecoration(color: colors.primaryContainer);
}(),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -2273,18 +2326,32 @@ class _ChatsScreenState extends State<ChatsScreen>
); );
}).toList(), }).toList(),
ListTile( Container(
leading: const Icon(Icons.add_circle_outline), decoration: themeProvider.useGradientForAddAccountButton
title: const Text('Добавить аккаунт'), ? BoxDecoration(
onTap: () { gradient: LinearGradient(
Navigator.pop(context); colors: [
Navigator.of(context).push( themeProvider.addAccountButtonGradientColor1,
MaterialPageRoute( themeProvider.addAccountButtonGradientColor2,
builder: (context) => ],
const PhoneEntryScreen(), begin: Alignment.centerLeft,
), end: Alignment.centerRight,
); ),
}, )
: null,
child: ListTile(
leading: const Icon(Icons.add_circle_outline),
title: const Text('Добавить аккаунт'),
onTap: () {
Navigator.pop(context);
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
const PhoneEntryScreen(),
),
);
},
),
), ),
], ],
) )
@@ -2296,89 +2363,90 @@ class _ChatsScreenState extends State<ChatsScreen>
}, },
), ),
Expanded( Expanded(
child: Column( child: () {
children: [ final menuColumn = Column(
_buildAccountsSection(context, colors), children: [
ListTile( _buildAccountsSection(context, colors),
leading: const Icon(Icons.person_outline), ListTile(
title: const Text('Мой профиль'), leading: const Icon(Icons.person_outline),
onTap: () { title: const Text('Мой профиль'),
Navigator.pop(context); // Закрыть Drawer onTap: () {
_navigateToProfileEdit(); // Этот метод у вас уже есть Navigator.pop(context);
}, _navigateToProfileEdit();
), },
ListTile( ),
leading: const Icon(Icons.call_outlined), ListTile(
title: const Text('Звонки'), leading: const Icon(Icons.call_outlined),
onTap: () { title: const Text('Звонки'),
Navigator.pop(context); // Закрыть Drawer onTap: () {
Navigator.of(context).push( Navigator.pop(context);
MaterialPageRoute( Navigator.of(context).push(
builder: (context) => const CallsScreen(), MaterialPageRoute(
), builder: (context) => const CallsScreen(),
); ),
}, );
), },
ListTile( ),
leading: const Icon(Icons.music_note), ListTile(
title: const Text('Музыка'), leading: const Icon(Icons.music_note),
onTap: () { title: const Text('Музыка'),
Navigator.pop(context); onTap: () {
Navigator.of(context).push( Navigator.pop(context);
MaterialPageRoute( Navigator.of(context).push(
builder: (context) => const MusicLibraryScreen(), MaterialPageRoute(
), builder: (context) => const MusicLibraryScreen(),
); ),
}, );
), },
ListTile( ),
leading: _isReconnecting ListTile(
? SizedBox( leading: _isReconnecting
width: 24, ? SizedBox(
height: 24, width: 24,
child: CircularProgressIndicator( height: 24,
strokeWidth: 2, child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>( strokeWidth: 2,
colors.primary, valueColor: AlwaysStoppedAnimation<Color>(
colors.primary,
),
), ),
), )
) : const Icon(Icons.refresh),
: const Icon(Icons.refresh), title: const Text('Переподключиться'),
title: const Text('Переподключиться'), enabled: !_isReconnecting,
enabled: !_isReconnecting, onTap: () async {
onTap: () async { if (_isReconnecting) return;
if (_isReconnecting) return;
setState(() { setState(() {
_isReconnecting = true; _isReconnecting = true;
}); });
try { try {
await ApiService.instance.performFullReconnection(); await ApiService.instance.performFullReconnection();
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: const Text( content: const Text(
'Переподключение выполнено успешно', 'Переподключение выполнено успешно',
),
backgroundColor: colors.primaryContainer,
duration: const Duration(seconds: 2),
), ),
backgroundColor: colors.primaryContainer, );
duration: const Duration(seconds: 2), Navigator.pop(context);
), }
); } catch (e) {
Navigator.pop(context); if (mounted) {
} ScaffoldMessenger.of(context).showSnackBar(
} catch (e) { SnackBar(
if (mounted) { content: Text('Ошибка переподключения: $e'),
ScaffoldMessenger.of(context).showSnackBar( backgroundColor: colors.error,
SnackBar( duration: const Duration(seconds: 3),
content: Text('Ошибка переподключения: $e'), ),
backgroundColor: colors.error, );
duration: const Duration(seconds: 3), }
), } finally {
); if (mounted) {
}
} finally {
if (mounted) {
setState(() { setState(() {
_isReconnecting = false; _isReconnecting = false;
}); });
@@ -2428,21 +2496,49 @@ class _ChatsScreenState extends State<ChatsScreen>
} }
}, },
), ),
const Spacer(), const Spacer(),
const Divider(height: 1, indent: 16, endIndent: 16), const Divider(height: 1, indent: 16, endIndent: 16),
ListTile( ListTile(
leading: Icon(Icons.logout, color: colors.error), leading: Icon(Icons.logout, color: colors.error),
title: Text('Выйти', style: TextStyle(color: colors.error)), title: Text('Выйти', style: TextStyle(color: colors.error)),
onTap: () { onTap: () {
Navigator.pop(context); // Закрыть Drawer Navigator.pop(context);
_showLogoutDialog(); _showLogoutDialog();
}, },
), ),
const SizedBox(height: 8), // Небольшой отступ снизу const SizedBox(height: 8),
], ],
), );
if (themeProvider.drawerBackgroundType == DrawerBackgroundType.gradient) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
themeProvider.drawerGradientColor2,
themeProvider.drawerGradientColor1,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: menuColumn,
);
} else if (themeProvider.drawerBackgroundType == DrawerBackgroundType.image &&
themeProvider.drawerImagePath != null &&
themeProvider.drawerImagePath!.isNotEmpty) {
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage(File(themeProvider.drawerImagePath!)),
fit: BoxFit.cover,
),
),
child: menuColumn,
);
}
return menuColumn;
}(),
), ),
], ],
), ),
@@ -3035,14 +3131,46 @@ class _ChatsScreenState extends State<ChatsScreen>
), ),
]; ];
return Container( final themeProvider = context.watch<ThemeProvider>();
height: 48,
decoration: BoxDecoration( BoxDecoration? folderTabsDecoration;
color: colors.surface, if (themeProvider.folderTabsBackgroundType == FolderTabsBackgroundType.gradient) {
folderTabsDecoration = BoxDecoration(
gradient: LinearGradient(
colors: [
themeProvider.folderTabsGradientColor1,
themeProvider.folderTabsGradientColor2,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
border: Border( border: Border(
bottom: BorderSide(color: colors.outline.withOpacity(0.2), width: 1), bottom: BorderSide(color: colors.outline.withOpacity(0.2), width: 1),
), ),
), );
} else if (themeProvider.folderTabsBackgroundType == FolderTabsBackgroundType.image &&
themeProvider.folderTabsImagePath != null &&
themeProvider.folderTabsImagePath!.isNotEmpty) {
folderTabsDecoration = BoxDecoration(
image: DecorationImage(
image: FileImage(File(themeProvider.folderTabsImagePath!)),
fit: BoxFit.cover,
),
border: Border(
bottom: BorderSide(color: colors.outline.withOpacity(0.2), width: 1),
),
);
}
return Container(
height: 48,
decoration: folderTabsDecoration ??
BoxDecoration(
color: colors.surface,
border: Border(
bottom: BorderSide(color: colors.outline.withOpacity(0.2), width: 1),
),
),
child: Stack( child: Stack(
children: [ children: [
Row( Row(
@@ -3751,9 +3879,36 @@ class _ChatsScreenState extends State<ChatsScreen>
AppBar _buildAppBar(BuildContext context) { AppBar _buildAppBar(BuildContext context) {
final colors = Theme.of(context).colorScheme; final colors = Theme.of(context).colorScheme;
final themeProvider = context.watch<ThemeProvider>();
BoxDecoration? appBarDecoration;
if (themeProvider.appBarBackgroundType == AppBarBackgroundType.gradient) {
appBarDecoration = BoxDecoration(
gradient: LinearGradient(
colors: [
themeProvider.appBarGradientColor1,
themeProvider.appBarGradientColor2,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
);
} else if (themeProvider.appBarBackgroundType == AppBarBackgroundType.image &&
themeProvider.appBarImagePath != null &&
themeProvider.appBarImagePath!.isNotEmpty) {
appBarDecoration = BoxDecoration(
image: DecorationImage(
image: FileImage(File(themeProvider.appBarImagePath!)),
fit: BoxFit.cover,
),
);
}
return AppBar( return AppBar(
titleSpacing: 4.0, titleSpacing: 4.0,
flexibleSpace: appBarDecoration != null
? Container(decoration: appBarDecoration)
: null,
leading: _isSearchExpanded leading: _isSearchExpanded
? IconButton( ? IconButton(

View File

@@ -6,6 +6,7 @@ import 'package:gwid/screens/settings/settings_screen.dart';
import 'package:gwid/screens/phone_entry_screen.dart'; import 'package:gwid/screens/phone_entry_screen.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:gwid/utils/theme_provider.dart'; import 'package:gwid/utils/theme_provider.dart';
import 'package:gwid/api/api_service.dart';
class ProfileMenuDialog extends StatefulWidget { class ProfileMenuDialog extends StatefulWidget {
final Profile? myProfile; final Profile? myProfile;
@@ -195,12 +196,26 @@ class _ProfileMenuDialogState extends State<ProfileMenuDialog> {
onTap: () async { onTap: () async {
if (context.mounted) { if (context.mounted) {
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pushAndRemoveUntil( try {
MaterialPageRoute( await ApiService.instance.logout();
builder: (_) => const PhoneEntryScreen(), if (context.mounted) {
), Navigator.of(context).pushAndRemoveUntil(
(route) => false, MaterialPageRoute(
); builder: (_) => const PhoneEntryScreen(),
),
(route) => false,
);
}
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Ошибка при выходе: $e'),
backgroundColor: Theme.of(context).colorScheme.error,
),
);
}
}
} }
}, },
), ),

View File

@@ -242,7 +242,6 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
title: const Text("Выбрать видео"), title: const Text("Выбрать видео"),
trailing: const Icon(Icons.chevron_right), trailing: const Icon(Icons.chevron_right),
onTap: () async { onTap: () async {
final result = await FilePicker.platform.pickFiles( final result = await FilePicker.platform.pickFiles(
type: FileType.video, type: FileType.video,
); );
@@ -292,7 +291,8 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
max: 1.0, max: 1.0,
divisions: 18, divisions: 18,
onChanged: (value) => theme.setMessageTextOpacity(value), onChanged: (value) => theme.setMessageTextOpacity(value),
displayValue: "${(theme.messageTextOpacity * 100).round()}%", displayValue:
"${(theme.messageTextOpacity * 100).round()}%",
), ),
_SliderTile( _SliderTile(
icon: Icons.blur_circular, icon: Icons.blur_circular,
@@ -301,7 +301,8 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
min: 0.0, min: 0.0,
max: 0.5, max: 0.5,
divisions: 10, divisions: 10,
onChanged: (value) => theme.setMessageShadowIntensity(value), onChanged: (value) =>
theme.setMessageShadowIntensity(value),
displayValue: displayValue:
"${(theme.messageShadowIntensity * 100).round()}%", "${(theme.messageShadowIntensity * 100).round()}%",
), ),
@@ -313,7 +314,8 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
max: 1.0, max: 1.0,
divisions: 18, divisions: 18,
onChanged: (value) => theme.setMessageMenuOpacity(value), onChanged: (value) => theme.setMessageMenuOpacity(value),
displayValue: "${(theme.messageMenuOpacity * 100).round()}%", displayValue:
"${(theme.messageMenuOpacity * 100).round()}%",
), ),
_SliderTile( _SliderTile(
icon: Icons.blur_on, icon: Icons.blur_on,
@@ -368,7 +370,8 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
value: theme.messageBubbleType, value: theme.messageBubbleType,
underline: const SizedBox.shrink(), underline: const SizedBox.shrink(),
onChanged: (value) { onChanged: (value) {
if (value != null) theme.setMessageBubbleType(value); if (value != null)
theme.setMessageBubbleType(value);
}, },
items: MessageBubbleType.values.map((type) { items: MessageBubbleType.values.map((type) {
return DropdownMenuItem( return DropdownMenuItem(
@@ -390,7 +393,8 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
opacity: isSystemTheme ? 0.5 : 1.0, opacity: isSystemTheme ? 0.5 : 1.0,
child: GestureDetector( child: GestureDetector(
onTap: () async { onTap: () async {
final initial = myBubbleColorToShow ?? myBubbleFallback; final initial =
myBubbleColorToShow ?? myBubbleFallback;
_showColorPicker( _showColorPicker(
context, context,
initialColor: initial, initialColor: initial,
@@ -425,14 +429,16 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
_showColorPicker( _showColorPicker(
context, context,
initialColor: initial, initialColor: initial,
onColorChanged: (color) => theirBubbleSetter(color), onColorChanged: (color) =>
theirBubbleSetter(color),
); );
}, },
child: Container( child: Container(
width: 40, width: 40,
height: 40, height: 40,
decoration: BoxDecoration( decoration: BoxDecoration(
color: theirBubbleColorToShow ?? theirBubbleFallback, color:
theirBubbleColorToShow ?? theirBubbleFallback,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.grey), border: Border.all(color: Colors.grey),
), ),
@@ -457,7 +463,8 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
title: "Цвет панели ответа", title: "Цвет панели ответа",
subtitle: "Фиксированный цвет", subtitle: "Фиксированный цвет",
color: theme.customReplyColor ?? Colors.blue, color: theme.customReplyColor ?? Colors.blue,
onColorChanged: (color) => theme.setCustomReplyColor(color), onColorChanged: (color) =>
theme.setCustomReplyColor(color),
), ),
], ],
], ],
@@ -485,7 +492,8 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
max: 1.0, max: 1.0,
divisions: 20, divisions: 20,
onChanged: (value) => theme.setProfileDialogOpacity(value), onChanged: (value) => theme.setProfileDialogOpacity(value),
displayValue: "${(theme.profileDialogOpacity * 100).round()}%", displayValue:
"${(theme.profileDialogOpacity * 100).round()}%",
), ),
_SliderTile( _SliderTile(
icon: Icons.blur_on, icon: Icons.blur_on,
@@ -517,6 +525,323 @@ class _CustomizationScreenState extends State<CustomizationScreen> {
], ],
), ),
const SizedBox(height: 24), const SizedBox(height: 24),
_ExpandableSection(
title: "Кастомизация+",
initiallyExpanded: false,
children: [
_CustomSettingTile(
icon: Icons.format_color_fill,
title: "Фон списка чатов",
subtitle: "Выберите тип фона для списка чатов",
child: DropdownButton<ChatsListBackgroundType>(
value: theme.chatsListBackgroundType,
underline: const SizedBox.shrink(),
onChanged: (value) {
if (value != null) theme.setChatsListBackgroundType(value);
},
items: ChatsListBackgroundType.values.map((type) {
return DropdownMenuItem(
value: type,
child: Text(type.displayName),
);
}).toList(),
),
),
if (theme.chatsListBackgroundType ==
ChatsListBackgroundType.gradient) ...[
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 1",
subtitle: "Начальный цвет градиента",
color: theme.chatsListGradientColor1,
onColorChanged: (color) =>
theme.setChatsListGradientColor1(color),
),
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 2",
subtitle: "Конечный цвет градиента",
color: theme.chatsListGradientColor2,
onColorChanged: (color) =>
theme.setChatsListGradientColor2(color),
),
],
if (theme.chatsListBackgroundType ==
ChatsListBackgroundType.image) ...[
const Divider(height: 24),
ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.photo_library_outlined),
title: const Text("Выбрать изображение"),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
final picker = ImagePicker();
final image = await picker.pickImage(
source: ImageSource.gallery,
);
if (image != null) {
theme.setChatsListImagePath(image.path);
}
},
),
if (theme.chatsListImagePath?.isNotEmpty == true) ...[
ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(
Icons.delete_outline,
color: Colors.redAccent,
),
title: const Text(
"Удалить изображение",
style: TextStyle(color: Colors.redAccent),
),
onTap: () => theme.setChatsListImagePath(null),
),
],
],
const Divider(height: 24),
_CustomSettingTile(
icon: Icons.view_sidebar,
title: "Фон боковой панели",
subtitle: "Выберите тип фона для боковой панели",
child: DropdownButton<DrawerBackgroundType>(
value: theme.drawerBackgroundType,
underline: const SizedBox.shrink(),
onChanged: (value) {
if (value != null) theme.setDrawerBackgroundType(value);
},
items: DrawerBackgroundType.values.map((type) {
return DropdownMenuItem(
value: type,
child: Text(type.displayName),
);
}).toList(),
),
),
if (theme.drawerBackgroundType ==
DrawerBackgroundType.gradient) ...[
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 1",
subtitle: "Начальный цвет градиента",
color: theme.drawerGradientColor1,
onColorChanged: (color) =>
theme.setDrawerGradientColor1(color),
),
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 2",
subtitle: "Конечный цвет градиента",
color: theme.drawerGradientColor2,
onColorChanged: (color) =>
theme.setDrawerGradientColor2(color),
),
],
if (theme.drawerBackgroundType == DrawerBackgroundType.image) ...[
const Divider(height: 24),
ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.photo_library_outlined),
title: const Text("Выбрать изображение"),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
final picker = ImagePicker();
final image = await picker.pickImage(
source: ImageSource.gallery,
);
if (image != null) {
theme.setDrawerImagePath(image.path);
}
},
),
if (theme.drawerImagePath?.isNotEmpty == true) ...[
ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(
Icons.delete_outline,
color: Colors.redAccent,
),
title: const Text(
"Удалить изображение",
style: TextStyle(color: Colors.redAccent),
),
onTap: () => theme.setDrawerImagePath(null),
),
],
],
const Divider(height: 24),
_CustomSettingTile(
icon: Icons.person_add,
title: "Градиент для кнопки добавления аккаунта",
subtitle: "Применить градиент к кнопке в drawer",
child: Switch(
value: theme.useGradientForAddAccountButton,
onChanged: (value) =>
theme.setUseGradientForAddAccountButton(value),
),
),
if (theme.useGradientForAddAccountButton) ...[
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 1",
subtitle: "Начальный цвет градиента",
color: theme.addAccountButtonGradientColor1,
onColorChanged: (color) =>
theme.setAddAccountButtonGradientColor1(color),
),
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 2",
subtitle: "Конечный цвет градиента",
color: theme.addAccountButtonGradientColor2,
onColorChanged: (color) =>
theme.setAddAccountButtonGradientColor2(color),
),
],
const Divider(height: 24),
_CustomSettingTile(
icon: Icons.view_headline,
title: "Фон верхней панели",
subtitle: "Выберите тип фона для AppBar (поиск, Сферум и т.д.)",
child: DropdownButton<AppBarBackgroundType>(
value: theme.appBarBackgroundType,
underline: const SizedBox.shrink(),
onChanged: (value) {
if (value != null) theme.setAppBarBackgroundType(value);
},
items: AppBarBackgroundType.values.map((type) {
return DropdownMenuItem(
value: type,
child: Text(type.displayName),
);
}).toList(),
),
),
if (theme.appBarBackgroundType ==
AppBarBackgroundType.gradient) ...[
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 1",
subtitle: "Начальный цвет градиента",
color: theme.appBarGradientColor1,
onColorChanged: (color) =>
theme.setAppBarGradientColor1(color),
),
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 2",
subtitle: "Конечный цвет градиента",
color: theme.appBarGradientColor2,
onColorChanged: (color) =>
theme.setAppBarGradientColor2(color),
),
],
if (theme.appBarBackgroundType == AppBarBackgroundType.image) ...[
const Divider(height: 24),
ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.photo_library_outlined),
title: const Text("Выбрать изображение"),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
final picker = ImagePicker();
final image = await picker.pickImage(
source: ImageSource.gallery,
);
if (image != null) {
theme.setAppBarImagePath(image.path);
}
},
),
if (theme.appBarImagePath?.isNotEmpty == true) ...[
ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(
Icons.delete_outline,
color: Colors.redAccent,
),
title: const Text(
"Удалить изображение",
style: TextStyle(color: Colors.redAccent),
),
onTap: () => theme.setAppBarImagePath(null),
),
],
],
const Divider(height: 24),
_CustomSettingTile(
icon: Icons.folder,
title: "Фон панели папок",
subtitle: "Выберите тип фона для панели с именами папок",
child: DropdownButton<FolderTabsBackgroundType>(
value: theme.folderTabsBackgroundType,
underline: const SizedBox.shrink(),
onChanged: (value) {
if (value != null) theme.setFolderTabsBackgroundType(value);
},
items: FolderTabsBackgroundType.values.map((type) {
return DropdownMenuItem(
value: type,
child: Text(type.displayName),
);
}).toList(),
),
),
if (theme.folderTabsBackgroundType ==
FolderTabsBackgroundType.gradient) ...[
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 1",
subtitle: "Начальный цвет градиента",
color: theme.folderTabsGradientColor1,
onColorChanged: (color) =>
theme.setFolderTabsGradientColor1(color),
),
const SizedBox(height: 16),
_ColorPickerTile(
title: "Цвет 2",
subtitle: "Конечный цвет градиента",
color: theme.folderTabsGradientColor2,
onColorChanged: (color) =>
theme.setFolderTabsGradientColor2(color),
),
],
if (theme.folderTabsBackgroundType ==
FolderTabsBackgroundType.image) ...[
const Divider(height: 24),
ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.photo_library_outlined),
title: const Text("Выбрать изображение"),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
final picker = ImagePicker();
final image = await picker.pickImage(
source: ImageSource.gallery,
);
if (image != null) {
theme.setFolderTabsImagePath(image.path);
}
},
),
if (theme.folderTabsImagePath?.isNotEmpty == true) ...[
ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(
Icons.delete_outline,
color: Colors.redAccent,
),
title: const Text(
"Удалить изображение",
style: TextStyle(color: Colors.redAccent),
),
onTap: () => theme.setFolderTabsImagePath(null),
),
],
],
],
),
const SizedBox(height: 24),
_ModernSection( _ModernSection(
title: "Панели чата", title: "Панели чата",
children: [ children: [
@@ -1388,7 +1713,6 @@ class _ChatWallpaperPreview extends StatelessWidget {
); );
} }
case ChatWallpaperType.video: case ChatWallpaperType.video:
if (Platform.isWindows) { if (Platform.isWindows) {
return Container( return Container(
color: isDarkTheme ? Colors.grey[850] : Colors.grey[200], color: isDarkTheme ? Colors.grey[850] : Colors.grey[200],
@@ -1572,7 +1896,10 @@ class _ExpandableSectionState extends State<_ExpandableSection> {
onTap: () => setState(() => _isExpanded = !_isExpanded), onTap: () => setState(() => _isExpanded = !_isExpanded),
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 4.0), padding: const EdgeInsets.symmetric(
vertical: 12.0,
horizontal: 4.0,
),
child: Row( child: Row(
children: [ children: [
Text( Text(
@@ -1591,10 +1918,7 @@ class _ExpandableSectionState extends State<_ExpandableSection> {
), ),
), ),
), ),
if (_isExpanded) ...[ if (_isExpanded) ...[const SizedBox(height: 8), ...widget.children],
const SizedBox(height: 8),
...widget.children,
],
], ],
); );
} }
@@ -1646,10 +1970,7 @@ class _MessageBubblesPreview extends StatelessWidget {
children: [ children: [
const Spacer(), const Spacer(),
Expanded( Expanded(
child: ChatMessageBubble( child: ChatMessageBubble(message: mockMyMessage, isMe: true),
message: mockMyMessage,
isMe: true,
),
), ),
], ],
), ),
@@ -1708,16 +2029,10 @@ class _DialogPreview extends StatelessWidget {
decoration: BoxDecoration( decoration: BoxDecoration(
color: colors.surface.withOpacity(theme.profileDialogOpacity), color: colors.surface.withOpacity(theme.profileDialogOpacity),
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
border: Border.all( border: Border.all(color: colors.outline.withOpacity(0.2)),
color: colors.outline.withOpacity(0.2),
),
), ),
child: Center( child: Center(
child: Icon( child: Icon(Icons.person, color: colors.onSurface, size: 32),
Icons.person,
color: colors.onSurface,
size: 32,
),
), ),
), ),
), ),
@@ -1831,7 +2146,9 @@ class _PanelsPreview extends StatelessWidget {
), ),
child: Container( child: Container(
height: 30, height: 30,
color: colors.surface.withOpacity(theme.bottomBarOpacity), color: colors.surface.withOpacity(
theme.bottomBarOpacity,
),
child: Row( child: Row(
children: [ children: [
const SizedBox(width: 12), const SizedBox(width: 12),

View File

@@ -40,7 +40,12 @@ class AvatarCacheService {
final timestamp = _imageCacheTimestamps[cacheKey]; final timestamp = _imageCacheTimestamps[cacheKey];
if (timestamp != null && !_isExpired(timestamp, _imageTTL)) { if (timestamp != null && !_isExpired(timestamp, _imageTTL)) {
final imageData = _imageMemoryCache[cacheKey]!; final imageData = _imageMemoryCache[cacheKey]!;
return MemoryImage(imageData); if (_isValidImageData(imageData)) {
return MemoryImage(imageData);
} else {
_imageMemoryCache.remove(cacheKey);
_imageCacheTimestamps.remove(cacheKey);
}
} else { } else {
_imageMemoryCache.remove(cacheKey); _imageMemoryCache.remove(cacheKey);
_imageCacheTimestamps.remove(cacheKey); _imageCacheTimestamps.remove(cacheKey);
@@ -52,20 +57,25 @@ class AvatarCacheService {
customKey: cacheKey, customKey: cacheKey,
); );
if (cachedFile != null && await cachedFile.exists()) { if (cachedFile != null && await cachedFile.exists()) {
final imageData = await cachedFile.readAsBytes(); try {
final imageData = await cachedFile.readAsBytes();
if (_isValidImageData(imageData)) {
_imageMemoryCache[cacheKey] = imageData;
_imageCacheTimestamps[cacheKey] = DateTime.now();
_imageMemoryCache[cacheKey] = imageData; if (_imageMemoryCache.length > _maxMemoryImages) {
_imageCacheTimestamps[cacheKey] = DateTime.now(); await _evictOldestImages();
}
if (_imageMemoryCache.length > _maxMemoryImages) { return MemoryImage(imageData);
await _evictOldestImages(); }
} catch (e) {
print('Ошибка чтения кешированного файла аватарки: $e');
} }
return MemoryImage(imageData);
} }
final imageData = await _downloadImage(avatarUrl); final imageData = await _downloadImage(avatarUrl);
if (imageData != null) { if (imageData != null && _isValidImageData(imageData)) {
await _cacheService.cacheFile(avatarUrl, customKey: cacheKey); await _cacheService.cacheFile(avatarUrl, customKey: cacheKey);
_imageMemoryCache[cacheKey] = imageData; _imageMemoryCache[cacheKey] = imageData;
@@ -73,6 +83,8 @@ class AvatarCacheService {
return MemoryImage(imageData); return MemoryImage(imageData);
} }
return NetworkImage(avatarUrl);
} catch (e) { } catch (e) {
print('Ошибка получения аватарки: $e'); print('Ошибка получения аватарки: $e');
} }
@@ -111,6 +123,11 @@ class AvatarCacheService {
return null; return null;
} }
if (!_isValidImageData(imageData)) {
print('Невалидные данные изображения для $url');
return null;
}
return imageData; return imageData;
} }
} catch (e) { } catch (e) {
@@ -119,6 +136,34 @@ class AvatarCacheService {
return null; return null;
} }
bool _isValidImageData(Uint8List data) {
if (data.isEmpty) return false;
if (data.length < 4) return false;
final header = data.sublist(0, 4);
final pngHeader = [0x89, 0x50, 0x4E, 0x47];
final jpegHeader = [0xFF, 0xD8, 0xFF];
final gifHeader = [0x47, 0x49, 0x46, 0x38];
final webpHeader = [0x52, 0x49, 0x46, 0x46];
bool isValid = false;
if (header[0] == pngHeader[0] && header[1] == pngHeader[1] &&
header[2] == pngHeader[2] && header[3] == pngHeader[3]) {
isValid = true;
} else if (header[0] == jpegHeader[0] && header[1] == jpegHeader[1] &&
header[2] == jpegHeader[2]) {
isValid = true;
} else if (header[0] == gifHeader[0] && header[1] == gifHeader[1] &&
header[2] == gifHeader[2] && header[3] == gifHeader[3]) {
isValid = true;
} else if (header[0] == webpHeader[0] && header[1] == webpHeader[1] &&
header[2] == webpHeader[2] && header[3] == webpHeader[3]) {
isValid = true;
}
return isValid;
}
String _generateCacheKey(String url, int? userId) { String _generateCacheKey(String url, int? userId) {
if (userId != null) { if (userId != null) {
return 'avatar_${userId}_${_hashUrl(url)}'; return 'avatar_${userId}_${_hashUrl(url)}';

View File

@@ -6,6 +6,14 @@ enum AppTheme { system, light, dark, black }
enum ChatWallpaperType { solid, gradient, image, video } enum ChatWallpaperType { solid, gradient, image, video }
enum FolderTabsBackgroundType { none, gradient, image }
enum DrawerBackgroundType { none, gradient, image }
enum ChatsListBackgroundType { none, gradient, image }
enum AppBarBackgroundType { none, gradient, image }
enum TransitionOption { systemDefault, slide } enum TransitionOption { systemDefault, slide }
enum UIMode { both, burgerOnly, panelOnly } enum UIMode { both, burgerOnly, panelOnly }
@@ -47,6 +55,58 @@ extension ChatWallpaperTypeExtension on ChatWallpaperType {
} }
} }
extension FolderTabsBackgroundTypeExtension on FolderTabsBackgroundType {
String get displayName {
switch (this) {
case FolderTabsBackgroundType.none:
return 'Нет';
case FolderTabsBackgroundType.gradient:
return 'Градиент';
case FolderTabsBackgroundType.image:
return 'Фото';
}
}
}
extension DrawerBackgroundTypeExtension on DrawerBackgroundType {
String get displayName {
switch (this) {
case DrawerBackgroundType.none:
return 'Нет';
case DrawerBackgroundType.gradient:
return 'Градиент';
case DrawerBackgroundType.image:
return 'Фото';
}
}
}
extension ChatsListBackgroundTypeExtension on ChatsListBackgroundType {
String get displayName {
switch (this) {
case ChatsListBackgroundType.none:
return 'Нет';
case ChatsListBackgroundType.gradient:
return 'Градиент';
case ChatsListBackgroundType.image:
return 'Фото';
}
}
}
extension AppBarBackgroundTypeExtension on AppBarBackgroundType {
String get displayName {
switch (this) {
case AppBarBackgroundType.none:
return 'Нет';
case AppBarBackgroundType.gradient:
return 'Градиент';
case AppBarBackgroundType.image:
return 'Фото';
}
}
}
class CustomThemePreset { class CustomThemePreset {
String id; String id;
String name; String name;
@@ -105,6 +165,30 @@ class CustomThemePreset {
bool useAutoReplyColor; bool useAutoReplyColor;
Color? customReplyColor; Color? customReplyColor;
bool useGradientForChatsList;
ChatsListBackgroundType chatsListBackgroundType;
String? chatsListImagePath;
bool useGradientForDrawer;
DrawerBackgroundType drawerBackgroundType;
String? drawerImagePath;
bool useGradientForAddAccountButton;
bool useGradientForAppBar;
AppBarBackgroundType appBarBackgroundType;
String? appBarImagePath;
bool useGradientForFolderTabs;
FolderTabsBackgroundType folderTabsBackgroundType;
String? folderTabsImagePath;
Color chatsListGradientColor1;
Color chatsListGradientColor2;
Color drawerGradientColor1;
Color drawerGradientColor2;
Color addAccountButtonGradientColor1;
Color addAccountButtonGradientColor2;
Color appBarGradientColor1;
Color appBarGradientColor2;
Color folderTabsGradientColor1;
Color folderTabsGradientColor2;
CustomThemePreset({ CustomThemePreset({
required this.id, required this.id,
required this.name, required this.name,
@@ -155,6 +239,29 @@ class CustomThemePreset {
this.useDesktopLayout = true, this.useDesktopLayout = true,
this.useAutoReplyColor = true, this.useAutoReplyColor = true,
this.customReplyColor, this.customReplyColor,
this.useGradientForChatsList = false,
this.chatsListBackgroundType = ChatsListBackgroundType.none,
this.chatsListImagePath,
this.useGradientForDrawer = false,
this.drawerBackgroundType = DrawerBackgroundType.none,
this.drawerImagePath,
this.useGradientForAddAccountButton = false,
this.useGradientForAppBar = false,
this.appBarBackgroundType = AppBarBackgroundType.none,
this.appBarImagePath,
this.useGradientForFolderTabs = false,
this.folderTabsBackgroundType = FolderTabsBackgroundType.none,
this.folderTabsImagePath,
this.chatsListGradientColor1 = const Color(0xFF1E1E1E),
this.chatsListGradientColor2 = const Color(0xFF2D2D2D),
this.drawerGradientColor1 = const Color(0xFF1E1E1E),
this.drawerGradientColor2 = const Color(0xFF2D2D2D),
this.addAccountButtonGradientColor1 = const Color(0xFF1E1E1E),
this.addAccountButtonGradientColor2 = const Color(0xFF2D2D2D),
this.appBarGradientColor1 = const Color(0xFF1E1E1E),
this.appBarGradientColor2 = const Color(0xFF2D2D2D),
this.folderTabsGradientColor1 = const Color(0xFF1E1E1E),
this.folderTabsGradientColor2 = const Color(0xFF2D2D2D),
}); });
factory CustomThemePreset.createDefault() { factory CustomThemePreset.createDefault() {
@@ -211,6 +318,29 @@ class CustomThemePreset {
bool? useDesktopLayout, bool? useDesktopLayout,
bool? useAutoReplyColor, bool? useAutoReplyColor,
Color? customReplyColor, Color? customReplyColor,
bool? useGradientForChatsList,
ChatsListBackgroundType? chatsListBackgroundType,
String? chatsListImagePath,
bool? useGradientForDrawer,
DrawerBackgroundType? drawerBackgroundType,
String? drawerImagePath,
bool? useGradientForAddAccountButton,
bool? useGradientForAppBar,
AppBarBackgroundType? appBarBackgroundType,
String? appBarImagePath,
bool? useGradientForFolderTabs,
FolderTabsBackgroundType? folderTabsBackgroundType,
String? folderTabsImagePath,
Color? chatsListGradientColor1,
Color? chatsListGradientColor2,
Color? drawerGradientColor1,
Color? drawerGradientColor2,
Color? addAccountButtonGradientColor1,
Color? addAccountButtonGradientColor2,
Color? appBarGradientColor1,
Color? appBarGradientColor2,
Color? folderTabsGradientColor1,
Color? folderTabsGradientColor2,
}) { }) {
return CustomThemePreset( return CustomThemePreset(
id: id ?? this.id, id: id ?? this.id,
@@ -271,6 +401,29 @@ class CustomThemePreset {
useDesktopLayout: useDesktopLayout ?? this.useDesktopLayout, useDesktopLayout: useDesktopLayout ?? this.useDesktopLayout,
useAutoReplyColor: useAutoReplyColor ?? this.useAutoReplyColor, useAutoReplyColor: useAutoReplyColor ?? this.useAutoReplyColor,
customReplyColor: customReplyColor ?? this.customReplyColor, customReplyColor: customReplyColor ?? this.customReplyColor,
useGradientForChatsList: useGradientForChatsList ?? this.useGradientForChatsList,
chatsListBackgroundType: chatsListBackgroundType ?? this.chatsListBackgroundType,
chatsListImagePath: chatsListImagePath ?? this.chatsListImagePath,
useGradientForDrawer: useGradientForDrawer ?? this.useGradientForDrawer,
drawerBackgroundType: drawerBackgroundType ?? this.drawerBackgroundType,
drawerImagePath: drawerImagePath ?? this.drawerImagePath,
useGradientForAddAccountButton: useGradientForAddAccountButton ?? this.useGradientForAddAccountButton,
useGradientForAppBar: useGradientForAppBar ?? this.useGradientForAppBar,
appBarBackgroundType: appBarBackgroundType ?? this.appBarBackgroundType,
appBarImagePath: appBarImagePath ?? this.appBarImagePath,
useGradientForFolderTabs: useGradientForFolderTabs ?? this.useGradientForFolderTabs,
folderTabsBackgroundType: folderTabsBackgroundType ?? this.folderTabsBackgroundType,
folderTabsImagePath: folderTabsImagePath ?? this.folderTabsImagePath,
chatsListGradientColor1: chatsListGradientColor1 ?? this.chatsListGradientColor1,
chatsListGradientColor2: chatsListGradientColor2 ?? this.chatsListGradientColor2,
drawerGradientColor1: drawerGradientColor1 ?? this.drawerGradientColor1,
drawerGradientColor2: drawerGradientColor2 ?? this.drawerGradientColor2,
addAccountButtonGradientColor1: addAccountButtonGradientColor1 ?? this.addAccountButtonGradientColor1,
addAccountButtonGradientColor2: addAccountButtonGradientColor2 ?? this.addAccountButtonGradientColor2,
appBarGradientColor1: appBarGradientColor1 ?? this.appBarGradientColor1,
appBarGradientColor2: appBarGradientColor2 ?? this.appBarGradientColor2,
folderTabsGradientColor1: folderTabsGradientColor1 ?? this.folderTabsGradientColor1,
folderTabsGradientColor2: folderTabsGradientColor2 ?? this.folderTabsGradientColor2,
); );
} }
@@ -325,6 +478,29 @@ class CustomThemePreset {
'useDesktopLayout': useDesktopLayout, 'useDesktopLayout': useDesktopLayout,
'useAutoReplyColor': useAutoReplyColor, 'useAutoReplyColor': useAutoReplyColor,
'customReplyColor': customReplyColor?.value, 'customReplyColor': customReplyColor?.value,
'useGradientForChatsList': useGradientForChatsList,
'chatsListBackgroundType': chatsListBackgroundType.index,
'chatsListImagePath': chatsListImagePath,
'useGradientForDrawer': useGradientForDrawer,
'drawerBackgroundType': drawerBackgroundType.index,
'drawerImagePath': drawerImagePath,
'useGradientForAddAccountButton': useGradientForAddAccountButton,
'useGradientForAppBar': useGradientForAppBar,
'appBarBackgroundType': appBarBackgroundType.index,
'appBarImagePath': appBarImagePath,
'useGradientForFolderTabs': useGradientForFolderTabs,
'folderTabsBackgroundType': folderTabsBackgroundType.index,
'folderTabsImagePath': folderTabsImagePath,
'chatsListGradientColor1': chatsListGradientColor1.value,
'chatsListGradientColor2': chatsListGradientColor2.value,
'drawerGradientColor1': drawerGradientColor1.value,
'drawerGradientColor2': drawerGradientColor2.value,
'addAccountButtonGradientColor1': addAccountButtonGradientColor1.value,
'addAccountButtonGradientColor2': addAccountButtonGradientColor2.value,
'appBarGradientColor1': appBarGradientColor1.value,
'appBarGradientColor2': appBarGradientColor2.value,
'folderTabsGradientColor1': folderTabsGradientColor1.value,
'folderTabsGradientColor2': folderTabsGradientColor2.value,
}; };
} }
@@ -422,6 +598,57 @@ class CustomThemePreset {
customReplyColor: json['customReplyColor'] != null customReplyColor: json['customReplyColor'] != null
? Color(json['customReplyColor'] as int) ? Color(json['customReplyColor'] as int)
: null, : null,
useGradientForChatsList: json['useGradientForChatsList'] as bool? ?? false,
chatsListBackgroundType: ChatsListBackgroundType.values[
json['chatsListBackgroundType'] as int? ?? 0
],
chatsListImagePath: json['chatsListImagePath'] as String?,
useGradientForDrawer: json['useGradientForDrawer'] as bool? ?? false,
drawerBackgroundType: DrawerBackgroundType.values[
json['drawerBackgroundType'] as int? ?? 0
],
drawerImagePath: json['drawerImagePath'] as String?,
useGradientForAddAccountButton: json['useGradientForAddAccountButton'] as bool? ?? false,
useGradientForAppBar: json['useGradientForAppBar'] as bool? ?? false,
appBarBackgroundType: AppBarBackgroundType.values[
json['appBarBackgroundType'] as int? ?? 0
],
appBarImagePath: json['appBarImagePath'] as String?,
useGradientForFolderTabs: json['useGradientForFolderTabs'] as bool? ?? false,
folderTabsBackgroundType: FolderTabsBackgroundType.values[
json['folderTabsBackgroundType'] as int? ?? 0
],
folderTabsImagePath: json['folderTabsImagePath'] as String?,
chatsListGradientColor1: Color(
json['chatsListGradientColor1'] as int? ?? const Color(0xFF1E1E1E).value,
),
chatsListGradientColor2: Color(
json['chatsListGradientColor2'] as int? ?? const Color(0xFF2D2D2D).value,
),
drawerGradientColor1: Color(
json['drawerGradientColor1'] as int? ?? const Color(0xFF1E1E1E).value,
),
drawerGradientColor2: Color(
json['drawerGradientColor2'] as int? ?? const Color(0xFF2D2D2D).value,
),
addAccountButtonGradientColor1: Color(
json['addAccountButtonGradientColor1'] as int? ?? const Color(0xFF1E1E1E).value,
),
addAccountButtonGradientColor2: Color(
json['addAccountButtonGradientColor2'] as int? ?? const Color(0xFF2D2D2D).value,
),
appBarGradientColor1: Color(
json['appBarGradientColor1'] as int? ?? const Color(0xFF1E1E1E).value,
),
appBarGradientColor2: Color(
json['appBarGradientColor2'] as int? ?? const Color(0xFF2D2D2D).value,
),
folderTabsGradientColor1: Color(
json['folderTabsGradientColor1'] as int? ?? const Color(0xFF1E1E1E).value,
),
folderTabsGradientColor2: Color(
json['folderTabsGradientColor2'] as int? ?? const Color(0xFF2D2D2D).value,
),
); );
} }
} }
@@ -552,6 +779,29 @@ class ThemeProvider with ChangeNotifier {
bool get useDesktopLayout => _activeTheme.useDesktopLayout; bool get useDesktopLayout => _activeTheme.useDesktopLayout;
bool get useAutoReplyColor => _activeTheme.useAutoReplyColor; bool get useAutoReplyColor => _activeTheme.useAutoReplyColor;
Color? get customReplyColor => _activeTheme.customReplyColor; Color? get customReplyColor => _activeTheme.customReplyColor;
bool get useGradientForChatsList => _activeTheme.useGradientForChatsList;
ChatsListBackgroundType get chatsListBackgroundType => _activeTheme.chatsListBackgroundType;
String? get chatsListImagePath => _activeTheme.chatsListImagePath;
bool get useGradientForDrawer => _activeTheme.useGradientForDrawer;
DrawerBackgroundType get drawerBackgroundType => _activeTheme.drawerBackgroundType;
String? get drawerImagePath => _activeTheme.drawerImagePath;
bool get useGradientForAddAccountButton => _activeTheme.useGradientForAddAccountButton;
bool get useGradientForAppBar => _activeTheme.useGradientForAppBar;
AppBarBackgroundType get appBarBackgroundType => _activeTheme.appBarBackgroundType;
String? get appBarImagePath => _activeTheme.appBarImagePath;
bool get useGradientForFolderTabs => _activeTheme.useGradientForFolderTabs;
FolderTabsBackgroundType get folderTabsBackgroundType => _activeTheme.folderTabsBackgroundType;
String? get folderTabsImagePath => _activeTheme.folderTabsImagePath;
Color get chatsListGradientColor1 => _activeTheme.chatsListGradientColor1;
Color get chatsListGradientColor2 => _activeTheme.chatsListGradientColor2;
Color get drawerGradientColor1 => _activeTheme.drawerGradientColor1;
Color get drawerGradientColor2 => _activeTheme.drawerGradientColor2;
Color get addAccountButtonGradientColor1 => _activeTheme.addAccountButtonGradientColor1;
Color get addAccountButtonGradientColor2 => _activeTheme.addAccountButtonGradientColor2;
Color get appBarGradientColor1 => _activeTheme.appBarGradientColor1;
Color get appBarGradientColor2 => _activeTheme.appBarGradientColor2;
Color get folderTabsGradientColor1 => _activeTheme.folderTabsGradientColor1;
Color get folderTabsGradientColor2 => _activeTheme.folderTabsGradientColor2;
bool get highQualityPhotos => _highQualityPhotos; bool get highQualityPhotos => _highQualityPhotos;
bool get blockBypass => _blockBypass; bool get blockBypass => _blockBypass;
@@ -1218,6 +1468,144 @@ class ThemeProvider with ChangeNotifier {
await _saveActiveTheme(); await _saveActiveTheme();
} }
Future<void> setUseGradientForChatsList(bool value) async {
_activeTheme = _activeTheme.copyWith(useGradientForChatsList: value);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setChatsListBackgroundType(ChatsListBackgroundType type) async {
_activeTheme = _activeTheme.copyWith(chatsListBackgroundType: type);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setChatsListImagePath(String? path) async {
_activeTheme = _activeTheme.copyWith(chatsListImagePath: path);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setUseGradientForDrawer(bool value) async {
_activeTheme = _activeTheme.copyWith(useGradientForDrawer: value);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setDrawerBackgroundType(DrawerBackgroundType type) async {
_activeTheme = _activeTheme.copyWith(drawerBackgroundType: type);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setDrawerImagePath(String? path) async {
_activeTheme = _activeTheme.copyWith(drawerImagePath: path);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setChatsListGradientColor1(Color color) async {
_activeTheme = _activeTheme.copyWith(chatsListGradientColor1: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setChatsListGradientColor2(Color color) async {
_activeTheme = _activeTheme.copyWith(chatsListGradientColor2: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setDrawerGradientColor1(Color color) async {
_activeTheme = _activeTheme.copyWith(drawerGradientColor1: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setDrawerGradientColor2(Color color) async {
_activeTheme = _activeTheme.copyWith(drawerGradientColor2: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setUseGradientForAddAccountButton(bool value) async {
_activeTheme = _activeTheme.copyWith(useGradientForAddAccountButton: value);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setAddAccountButtonGradientColor1(Color color) async {
_activeTheme = _activeTheme.copyWith(addAccountButtonGradientColor1: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setAddAccountButtonGradientColor2(Color color) async {
_activeTheme = _activeTheme.copyWith(addAccountButtonGradientColor2: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setUseGradientForAppBar(bool value) async {
_activeTheme = _activeTheme.copyWith(useGradientForAppBar: value);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setAppBarGradientColor1(Color color) async {
_activeTheme = _activeTheme.copyWith(appBarGradientColor1: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setAppBarGradientColor2(Color color) async {
_activeTheme = _activeTheme.copyWith(appBarGradientColor2: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setAppBarBackgroundType(AppBarBackgroundType type) async {
_activeTheme = _activeTheme.copyWith(appBarBackgroundType: type);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setAppBarImagePath(String? path) async {
_activeTheme = _activeTheme.copyWith(appBarImagePath: path);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setUseGradientForFolderTabs(bool value) async {
_activeTheme = _activeTheme.copyWith(useGradientForFolderTabs: value);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setFolderTabsGradientColor1(Color color) async {
_activeTheme = _activeTheme.copyWith(folderTabsGradientColor1: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setFolderTabsGradientColor2(Color color) async {
_activeTheme = _activeTheme.copyWith(folderTabsGradientColor2: color);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setFolderTabsBackgroundType(FolderTabsBackgroundType type) async {
_activeTheme = _activeTheme.copyWith(folderTabsBackgroundType: type);
notifyListeners();
await _saveActiveTheme();
}
Future<void> setFolderTabsImagePath(String? path) async {
_activeTheme = _activeTheme.copyWith(folderTabsImagePath: path);
notifyListeners();
await _saveActiveTheme();
}
void toggleTheme() { void toggleTheme() {
if (appTheme == AppTheme.light) { if (appTheme == AppTheme.light) {
setTheme(AppTheme.dark); setTheme(AppTheme.dark);

View File

@@ -657,9 +657,7 @@ class ChatMessageBubble extends StatelessWidget {
Uint8List? lowQualityBytes, Uint8List? lowQualityBytes,
int? videoType, int? videoType,
}) { }) {
// Логика открытия плеера
void openFullScreenVideo() async { void openFullScreenVideo() async {
// Показываем индикатор загрузки, пока получаем URL
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
@@ -669,12 +667,12 @@ class ChatMessageBubble extends StatelessWidget {
try { try {
final videoUrl = await ApiService.instance.getVideoUrl( final videoUrl = await ApiService.instance.getVideoUrl(
videoId, videoId,
chatId!, // chatId из `build` chatId!,
messageId, messageId,
); );
if (!context.mounted) return; // [!code ++] Проверка правильным способом if (!context.mounted) return;
Navigator.pop(context); // Убираем индикатор Navigator.pop(context);
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
@@ -682,8 +680,8 @@ class ChatMessageBubble extends StatelessWidget {
), ),
); );
} catch (e) { } catch (e) {
if (!context.mounted) return; // [!code ++] Проверка правильным способом if (!context.mounted) return;
Navigator.pop(context); // Убираем индикатор Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text('Не удалось загрузить видео: $e'), content: Text('Не удалось загрузить видео: $e'),
@@ -705,55 +703,58 @@ class ChatMessageBubble extends StatelessWidget {
); );
} }
return GestureDetector( return RepaintBoundary(
onTap: openFullScreenVideo, key: ValueKey('video_preview_boundary_${messageId}_$videoId'),
child: AspectRatio( child: GestureDetector(
aspectRatio: 16 / 9, onTap: openFullScreenVideo,
child: ClipRRect( child: AspectRatio(
borderRadius: BorderRadius.circular(12), aspectRatio: 16 / 9,
child: Stack( child: ClipRRect(
alignment: Alignment.center, borderRadius: BorderRadius.circular(12),
fit: StackFit.expand, child: Stack(
children: [ alignment: Alignment.center,
// Если у нас есть ХОТЬ ЧТО-ТО (блюр или URL), показываем ProgressiveImage fit: StackFit.expand,
(highQualityUrl != null && highQualityUrl.isNotEmpty) || children: [
(lowQualityBytes != null) (highQualityUrl != null && highQualityUrl.isNotEmpty) ||
? _ProgressiveNetworkImage( (lowQualityBytes != null)
url: highQualityUrl ?? '', ? _ProgressiveNetworkImage(
previewBytes: lowQualityBytes, key: ValueKey('video_preview_image_${messageId}_$videoId'),
width: 220, url: highQualityUrl ?? '',
height: 160, previewBytes: lowQualityBytes,
fit: BoxFit.cover, width: 220,
keepAlive: false, height: 160,
) fit: BoxFit.cover,
: Container( keepAlive: true,
color: Colors.black26, )
child: const Center( : Container(
child: Icon( color: Colors.black26,
Icons.video_library_outlined, child: const Center(
color: Colors.white, child: Icon(
size: 40, Icons.video_library_outlined,
color: Colors.white,
size: 40,
),
), ),
), ),
), Container(
Container( decoration: BoxDecoration(
decoration: BoxDecoration( color: Colors.black.withOpacity(0.15),
color: Colors.black.withOpacity(0.15), ),
child: Icon(
Icons.play_circle_filled_outlined,
color: Colors.white.withOpacity(0.95),
size: 50,
shadows: const [
Shadow(
color: Colors.black38,
blurRadius: 4,
offset: Offset(0, 2),
),
],
),
), ),
child: Icon( ],
Icons.play_circle_filled_outlined, ),
color: Colors.white.withOpacity(0.95),
size: 50,
shadows: const [
Shadow(
color: Colors.black38,
blurRadius: 4,
offset: Offset(0, 2),
),
],
),
),
],
), ),
), ),
), ),
@@ -2004,13 +2005,16 @@ class ChatMessageBubble extends StatelessWidget {
padding: const EdgeInsets.only(bottom: 4.0), padding: const EdgeInsets.only(bottom: 4.0),
child: ConstrainedBox( child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300), constraints: const BoxConstraints(maxWidth: 300),
child: _buildVideoPreview( child: RepaintBoundary(
context: context, key: ValueKey('video_preview_${message.id}_$videoId'),
videoId: videoId, child: _buildVideoPreview(
messageId: message.id, context: context,
highQualityUrl: highQualityThumbnailUrl, videoId: videoId,
lowQualityBytes: previewBytes, messageId: message.id,
videoType: videoType, highQualityUrl: highQualityThumbnailUrl,
lowQualityBytes: previewBytes,
videoType: videoType,
),
), ),
), ),
), ),
@@ -2179,13 +2183,16 @@ class ChatMessageBubble extends StatelessWidget {
widgets.add( widgets.add(
Padding( Padding(
padding: const EdgeInsets.only(bottom: 4.0), padding: const EdgeInsets.only(bottom: 4.0),
child: _buildVideoPreview( child: RepaintBoundary(
context: context, key: ValueKey('video_preview_${message.id}_$videoId'),
videoId: videoId, child: _buildVideoPreview(
messageId: message.id, context: context,
highQualityUrl: highQualityThumbnailUrl, videoId: videoId,
lowQualityBytes: previewBytes, messageId: message.id,
videoType: videoType, highQualityUrl: highQualityThumbnailUrl,
lowQualityBytes: previewBytes,
videoType: videoType,
),
), ),
), ),
); );

View File

@@ -2,6 +2,7 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gwid/models/chat.dart'; import 'package:gwid/models/chat.dart';
import 'package:gwid/models/contact.dart'; import 'package:gwid/models/contact.dart';
import 'package:gwid/services/avatar_cache_service.dart';
class GroupAvatars extends StatelessWidget { class GroupAvatars extends StatelessWidget {
final Chat chat; final Chat chat;
@@ -39,13 +40,13 @@ class GroupAvatars extends StatelessWidget {
double adaptiveAvatarSize; double adaptiveAvatarSize;
if (totalParticipants <= 2) { if (totalParticipants <= 2) {
adaptiveAvatarSize = adaptiveAvatarSize =
avatarSize * 1.5; // Большие аватары для 1-2 участников avatarSize * 1.5;
} else if (totalParticipants <= 4) { } else if (totalParticipants <= 4) {
adaptiveAvatarSize = adaptiveAvatarSize =
avatarSize * 1.2; // Средние аватары для 3-4 участников avatarSize * 1.2;
} else { } else {
adaptiveAvatarSize = adaptiveAvatarSize =
avatarSize * 0.8; // Маленькие аватары для 5+ участников avatarSize * 0.8;
} }
return SizedBox( return SizedBox(
@@ -114,45 +115,91 @@ class GroupAvatars extends StatelessWidget {
) { ) {
final colors = Theme.of(context).colorScheme; final colors = Theme.of(context).colorScheme;
return Container( if (contact == null || contact.photoBaseUrl == null || contact.photoBaseUrl!.isEmpty) {
width: size, return Container(
height: size, width: size,
decoration: BoxDecoration( height: size,
shape: BoxShape.circle, decoration: BoxDecoration(
border: Border.all(color: colors.surface, width: 2), shape: BoxShape.circle,
boxShadow: [ border: Border.all(color: colors.surface, width: 2),
BoxShadow( boxShadow: [
color: colors.shadow.withOpacity(0.3), BoxShadow(
blurRadius: 4, color: colors.shadow.withOpacity(0.3),
offset: const Offset(0, 2), blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: CircleAvatar(
radius: size / 2,
backgroundColor: contact != null
? colors.primaryContainer
: colors.secondaryContainer,
child: Text(
contact?.name.isNotEmpty == true
? contact!.name[0].toUpperCase()
: participantId.toString().substring(
participantId.toString().length - 1,
),
style: TextStyle(
color: contact != null
? colors.onPrimaryContainer
: colors.onSecondaryContainer,
fontSize: size * 0.5,
fontWeight: FontWeight.w600,
),
), ),
], ),
), );
child: CircleAvatar( }
radius: size / 2,
backgroundColor: contact != null return FutureBuilder<ImageProvider?>(
? colors.primaryContainer future: AvatarCacheService().getAvatar(contact.photoBaseUrl, userId: participantId),
: colors.secondaryContainer, builder: (context, snapshot) {
backgroundImage: contact?.photoBaseUrl != null ImageProvider? imageProvider;
? NetworkImage(contact!.photoBaseUrl!) if (snapshot.hasData && snapshot.data != null) {
: null, imageProvider = snapshot.data;
child: contact?.photoBaseUrl == null } else {
? Text( imageProvider = NetworkImage(contact.photoBaseUrl!);
contact?.name.isNotEmpty == true }
? contact!.name[0].toUpperCase()
: participantId.toString().substring( return Container(
participantId.toString().length - 1, width: size,
), // Последняя цифра ID height: size,
style: TextStyle( decoration: BoxDecoration(
color: contact != null shape: BoxShape.circle,
? colors.onPrimaryContainer border: Border.all(color: colors.surface, width: 2),
: colors.onSecondaryContainer, boxShadow: [
fontSize: size * 0.5, BoxShadow(
fontWeight: FontWeight.w600, color: colors.shadow.withOpacity(0.3),
), blurRadius: 4,
) offset: const Offset(0, 2),
: null, ),
), ],
),
child: CircleAvatar(
radius: size / 2,
backgroundColor: colors.primaryContainer,
backgroundImage: imageProvider,
onBackgroundImageError: (exception, stackTrace) {
},
child: imageProvider == null
? Text(
contact.name.isNotEmpty
? contact.name[0].toUpperCase()
: participantId.toString().substring(
participantId.toString().length - 1,
),
style: TextStyle(
color: colors.onPrimaryContainer,
fontSize: size * 0.5,
fontWeight: FontWeight.w600,
),
)
: null,
),
);
},
); );
} }