move video player into another places
make pure black toggleable
This commit is contained in:
parent
9d7ed55d24
commit
92b3097307
|
|
@ -2031,6 +2031,11 @@
|
||||||
"type": "String",
|
"type": "String",
|
||||||
"placeholders": {}
|
"placeholders": {}
|
||||||
},
|
},
|
||||||
|
"pureBlackToggle": "Pure Black",
|
||||||
|
"@pureBlackToggle": {
|
||||||
|
"type": "String",
|
||||||
|
"placeholders": {}
|
||||||
|
},
|
||||||
"singlesignon": "Single Sign on",
|
"singlesignon": "Single Sign on",
|
||||||
"@singlesignon": {
|
"@singlesignon": {
|
||||||
"type": "String",
|
"type": "String",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
abstract class SettingKeys {
|
abstract class SettingKeys {
|
||||||
|
static const String pureBlack = 'xyz.extera.next.pureBlack';
|
||||||
static const String renderHtml = 'chat.fluffy.renderHtml';
|
static const String renderHtml = 'chat.fluffy.renderHtml';
|
||||||
static const String hideRedactedEvents = 'chat.fluffy.hideRedactedEvents';
|
static const String hideRedactedEvents = 'chat.fluffy.hideRedactedEvents';
|
||||||
static const String hideUnknownEvents = 'chat.fluffy.hideUnknownEvents';
|
static const String hideUnknownEvents = 'chat.fluffy.hideUnknownEvents';
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,38 @@ abstract class FluffyThemes {
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Brightness brightness, [
|
Brightness brightness, [
|
||||||
Color? seed,
|
Color? seed,
|
||||||
|
bool? pureBlack,
|
||||||
]) {
|
]) {
|
||||||
|
final extraDarkColors = (brightness == Brightness.dark && pureBlack == true)
|
||||||
|
? {
|
||||||
|
'surface': const Color.fromARGB(255, 0, 0, 0),
|
||||||
|
'surfaceBright': const Color.fromARGB(255, 0, 0, 0),
|
||||||
|
'surfaceContainer': const Color.fromARGB(255, 22, 22, 22),
|
||||||
|
'surfaceContainerHigh': const Color.fromARGB(255, 33, 33, 33),
|
||||||
|
'surfaceContainerHighest': const Color.fromARGB(255, 33, 33, 33),
|
||||||
|
'surfaceContainerLow': const Color.fromARGB(255, 22, 22, 22),
|
||||||
|
'surfaceContainerLowest': const Color.fromARGB(255, 22, 22, 22),
|
||||||
|
'surfaceDim': const Color.fromARGB(255, 0, 0, 0),
|
||||||
|
'surfaceTint': const Color.fromARGB(255, 11, 11, 11),
|
||||||
|
'surfaceVariant': const Color.fromARGB(255, 0, 0, 0),
|
||||||
|
'background': const Color.fromARGB(255, 0, 0, 0),
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
|
||||||
final colorScheme = ColorScheme.fromSeed(
|
final colorScheme = ColorScheme.fromSeed(
|
||||||
brightness: brightness,
|
brightness: brightness,
|
||||||
seedColor: seed ?? AppConfig.colorSchemeSeed ?? AppConfig.primaryColor,
|
seedColor: seed ?? AppConfig.colorSchemeSeed ?? AppConfig.primaryColor,
|
||||||
|
surface: extraDarkColors['surface'],
|
||||||
|
surfaceBright: extraDarkColors['surfaceBright'],
|
||||||
|
surfaceContainer: extraDarkColors['surfaceContainer'],
|
||||||
|
surfaceContainerHigh: extraDarkColors['surfaceContainerHigh'],
|
||||||
|
surfaceContainerHighest: extraDarkColors['surfaceContainerHighest'],
|
||||||
|
surfaceContainerLow: extraDarkColors['surfaceContainerLow'],
|
||||||
|
surfaceContainerLowest: extraDarkColors['surfaceContainerLowest'],
|
||||||
|
surfaceDim: extraDarkColors['surfaceDim'],
|
||||||
|
surfaceTint: extraDarkColors['surfaceTint'],
|
||||||
|
surfaceVariant: extraDarkColors['surfaceVariant'],
|
||||||
|
background: extraDarkColors['background'],
|
||||||
);
|
);
|
||||||
final isColumnMode = FluffyThemes.isColumnMode(context);
|
final isColumnMode = FluffyThemes.isColumnMode(context);
|
||||||
return ThemeData(
|
return ThemeData(
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ class MessageContent extends StatelessWidget {
|
||||||
linkColor: linkColor,
|
linkColor: linkColor,
|
||||||
);
|
);
|
||||||
case MessageTypes.Video:
|
case MessageTypes.Video:
|
||||||
return EventVideoPlayer(event, textColor: textColor);
|
return EventVideoPlayer(event, textColor, linkColor, timeline: timeline,);
|
||||||
case MessageTypes.File:
|
case MessageTypes.File:
|
||||||
return MessageDownloadContent(
|
return MessageDownloadContent(
|
||||||
event,
|
event,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:fluffychat/pages/chat/events/html_message.dart';
|
import 'package:fluffychat/pages/chat/events/html_message.dart';
|
||||||
|
import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
|
||||||
|
import 'package:fluffychat/widgets/mxc_image.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
|
@ -22,116 +24,40 @@ import 'package:fluffychat/utils/url_launcher.dart';
|
||||||
import 'package:fluffychat/widgets/blur_hash.dart';
|
import 'package:fluffychat/widgets/blur_hash.dart';
|
||||||
import '../../../utils/error_reporter.dart';
|
import '../../../utils/error_reporter.dart';
|
||||||
|
|
||||||
class EventVideoPlayer extends StatefulWidget {
|
class EventVideoPlayer extends StatelessWidget {
|
||||||
final Event event;
|
final Event event;
|
||||||
final Color? textColor;
|
final Timeline? timeline;
|
||||||
final Color? linkColor;
|
final Color textColor;
|
||||||
|
final Color linkColor;
|
||||||
|
|
||||||
const EventVideoPlayer(
|
const EventVideoPlayer(
|
||||||
this.event, {
|
this.event,
|
||||||
this.textColor,
|
this.textColor,
|
||||||
this.linkColor,
|
this.linkColor, {
|
||||||
|
this.timeline,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
|
||||||
EventVideoPlayerState createState() => EventVideoPlayerState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class EventVideoPlayerState extends State<EventVideoPlayer> {
|
|
||||||
ChewieController? _chewieController;
|
|
||||||
VideoPlayerController? _videoPlayerController;
|
|
||||||
bool _isDownloading = false;
|
|
||||||
|
|
||||||
// The video_player package only doesn't support Windows and Linux.
|
|
||||||
final _supportsVideoPlayer =
|
|
||||||
!PlatformInfos.isWindows && !PlatformInfos.isLinux;
|
|
||||||
|
|
||||||
void _downloadAction() async {
|
|
||||||
if (!_supportsVideoPlayer) {
|
|
||||||
widget.event.saveFile(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(() => _isDownloading = true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
final videoFile = await widget.event.downloadAndDecryptAttachment();
|
|
||||||
|
|
||||||
// Dispose the controllers if we already have them.
|
|
||||||
_disposeControllers();
|
|
||||||
late VideoPlayerController videoPlayerController;
|
|
||||||
|
|
||||||
// Create the VideoPlayerController from the contents of videoFile.
|
|
||||||
if (kIsWeb) {
|
|
||||||
final blob = html.Blob([videoFile.bytes]);
|
|
||||||
final networkUri = Uri.parse(html.Url.createObjectUrlFromBlob(blob));
|
|
||||||
videoPlayerController = VideoPlayerController.networkUrl(networkUri);
|
|
||||||
} else {
|
|
||||||
final tempDir = await getTemporaryDirectory();
|
|
||||||
final fileName = Uri.encodeComponent(
|
|
||||||
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last,
|
|
||||||
);
|
|
||||||
final file = File('${tempDir.path}/${fileName}_${videoFile.name}');
|
|
||||||
if (await file.exists() == false) {
|
|
||||||
await file.writeAsBytes(videoFile.bytes);
|
|
||||||
}
|
|
||||||
videoPlayerController = VideoPlayerController.file(file);
|
|
||||||
}
|
|
||||||
_videoPlayerController = videoPlayerController;
|
|
||||||
|
|
||||||
await videoPlayerController.initialize();
|
|
||||||
|
|
||||||
// Create a ChewieController on top.
|
|
||||||
_chewieController = ChewieController(
|
|
||||||
videoPlayerController: videoPlayerController,
|
|
||||||
useRootNavigator: !kIsWeb,
|
|
||||||
autoPlay: true,
|
|
||||||
autoInitialize: true,
|
|
||||||
);
|
|
||||||
} on IOException catch (e) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(e.toLocalizedString(context)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} catch (e, s) {
|
|
||||||
ErrorReporter(context, 'Unable to play video').onErrorCallback(e, s);
|
|
||||||
} finally {
|
|
||||||
setState(() => _isDownloading = false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _disposeControllers() {
|
|
||||||
_chewieController?.dispose();
|
|
||||||
_videoPlayerController?.dispose();
|
|
||||||
_chewieController = null;
|
|
||||||
_videoPlayerController = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_disposeControllers();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
static const String fallbackBlurHash = 'L5H2EC=PM+yV0g-mq.wG9c010J}I';
|
static const String fallbackBlurHash = 'L5H2EC=PM+yV0g-mq.wG9c010J}I';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final supportsVideoPlayer = PlatformInfos.supportsVideoPlayer;
|
||||||
|
|
||||||
final hasThumbnail = widget.event.hasThumbnail;
|
final blurHash = (event.infoMap as Map<String, dynamic>)
|
||||||
final blurHash = (widget.event.infoMap as Map<String, dynamic>)
|
|
||||||
.tryGet<String>('xyz.amorgan.blurhash') ??
|
.tryGet<String>('xyz.amorgan.blurhash') ??
|
||||||
fallbackBlurHash;
|
fallbackBlurHash;
|
||||||
final fileDescription = widget.event.fileDescription;
|
final fileDescription = event.fileDescription;
|
||||||
final textColor = widget.textColor;
|
final infoMap = event.content.tryGetMap<String, Object?>('info');
|
||||||
final linkColor = widget.linkColor;
|
final videoWidth = infoMap?.tryGet<int>('w') ?? 400;
|
||||||
|
final videoHeight = infoMap?.tryGet<int>('h') ?? 300;
|
||||||
|
const height = 300.0;
|
||||||
|
final width = videoWidth * (height / videoHeight);
|
||||||
|
|
||||||
const width = 300.0;
|
final durationInt = infoMap?.tryGet<int>('duration');
|
||||||
|
final duration =
|
||||||
|
durationInt == null ? null : Duration(milliseconds: durationInt);
|
||||||
|
|
||||||
final chewieController = _chewieController;
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
|
|
@ -139,55 +65,72 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
||||||
Material(
|
Material(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () => supportsVideoPlayer
|
||||||
|
? showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => ImageViewer(
|
||||||
|
event,
|
||||||
|
timeline: timeline,
|
||||||
|
outerContext: context,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: event.saveFile(context),
|
||||||
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: width,
|
width: width,
|
||||||
child: chewieController != null
|
height: height,
|
||||||
? Center(child: Chewie(controller: chewieController))
|
child: Stack(
|
||||||
: Stack(
|
|
||||||
children: [
|
children: [
|
||||||
if (hasThumbnail)
|
if (event.hasThumbnail)
|
||||||
Center(
|
MxcImage(
|
||||||
child: ImageBubble(
|
event: event,
|
||||||
widget.event,
|
isThumbnail: true,
|
||||||
tapToView: false,
|
width: width,
|
||||||
textColor: widget.textColor,
|
height: height,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (context) => BlurHash(
|
||||||
|
blurhash: blurHash,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
fit: BoxFit.cover,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
BlurHash(
|
BlurHash(
|
||||||
blurhash: blurHash,
|
blurhash: blurHash,
|
||||||
width: width,
|
width: width,
|
||||||
height: width,
|
height: height,
|
||||||
|
fit: BoxFit.cover,
|
||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
child: IconButton(
|
child: CircleAvatar(
|
||||||
style: IconButton.styleFrom(
|
child: supportsVideoPlayer
|
||||||
backgroundColor: theme.colorScheme.surface,
|
? const Icon(Icons.play_arrow_outlined)
|
||||||
),
|
|
||||||
icon: _isDownloading
|
|
||||||
? const SizedBox(
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
child: CircularProgressIndicator.adaptive(
|
|
||||||
strokeWidth: 2,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: _supportsVideoPlayer
|
|
||||||
? const Icon(Icons.play_circle_outlined)
|
|
||||||
: const Icon(Icons.file_download_outlined),
|
: const Icon(Icons.file_download_outlined),
|
||||||
tooltip: _isDownloading
|
|
||||||
? L10n.of(context).loadingPleaseWait
|
|
||||||
: L10n.of(context).videoWithSize(
|
|
||||||
widget.event.sizeString ?? '?MB',
|
|
||||||
),
|
),
|
||||||
onPressed: _isDownloading ? null : _downloadAction,
|
),
|
||||||
|
if (duration != null)
|
||||||
|
Positioned(
|
||||||
|
bottom: 8,
|
||||||
|
left: 16,
|
||||||
|
child: Text(
|
||||||
|
'${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
backgroundColor: Colors.black.withAlpha(32),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (fileDescription != null && textColor != null && linkColor != null && !widget.event.isRichFileDescription)
|
),
|
||||||
|
if (fileDescription != null &&
|
||||||
|
textColor != null &&
|
||||||
|
linkColor != null &&
|
||||||
|
!event.isRichFileDescription)
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: width,
|
width: width,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
|
@ -215,7 +158,10 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (fileDescription != null && textColor != null && linkColor != null && widget.event.isRichFileDescription)
|
if (fileDescription != null &&
|
||||||
|
textColor != null &&
|
||||||
|
linkColor != null &&
|
||||||
|
event.isRichFileDescription)
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: width,
|
width: width,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
|
@ -226,9 +172,8 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
||||||
child: HtmlMessage(
|
child: HtmlMessage(
|
||||||
html: fileDescription,
|
html: fileDescription,
|
||||||
textColor: textColor,
|
textColor: textColor,
|
||||||
room: widget.event.room,
|
room: event.room,
|
||||||
fontSize:
|
fontSize: AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||||
AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
|
||||||
linkStyle: TextStyle(
|
linkStyle: TextStyle(
|
||||||
color: linkColor,
|
color: linkColor,
|
||||||
fontSize:
|
fontSize:
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class ChatSearchImagesTab extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
final borderRadius = BorderRadius.circular(AppConfig.borderRadius / 2);
|
final borderRadius = BorderRadius.circular(AppConfig.borderRadius / 2);
|
||||||
return StreamBuilder(
|
return StreamBuilder(
|
||||||
stream: searchStream,
|
stream: searchStream,
|
||||||
|
|
@ -156,7 +157,7 @@ class ChatSearchImagesTab extends StatelessWidget {
|
||||||
return Material(
|
return Material(
|
||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
child: EventVideoPlayer(event),
|
child: EventVideoPlayer(event, theme.colorScheme.onSurface, theme.colorScheme.primary),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return InkWell(
|
return InkWell(
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,13 @@ class ImageViewerController extends State<ImageViewer> {
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
allEvents = widget.timeline?.events
|
allEvents = widget.timeline?.events
|
||||||
.where((event) => event.messageType == MessageTypes.Image)
|
.where(
|
||||||
|
(event) => {
|
||||||
|
MessageTypes.Image,
|
||||||
|
MessageTypes.Sticker,
|
||||||
|
if (PlatformInfos.supportsVideoPlayer) MessageTypes.Video,
|
||||||
|
}.contains(event.messageType),
|
||||||
|
)
|
||||||
.toList()
|
.toList()
|
||||||
.reversed
|
.reversed
|
||||||
.toList() ??
|
.toList() ??
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/pages/image_viewer/video_player.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:fluffychat/widgets/hover_builder.dart';
|
import 'package:fluffychat/widgets/hover_builder.dart';
|
||||||
import 'package:fluffychat/widgets/mxc_image.dart';
|
import 'package:fluffychat/widgets/mxc_image.dart';
|
||||||
|
|
@ -75,19 +77,36 @@ class ImageViewerView extends StatelessWidget {
|
||||||
child: PageView.builder(
|
child: PageView.builder(
|
||||||
controller: controller.pageController,
|
controller: controller.pageController,
|
||||||
itemCount: controller.allEvents.length,
|
itemCount: controller.allEvents.length,
|
||||||
itemBuilder: (context, i) => InteractiveViewer(
|
itemBuilder: (context, i) {
|
||||||
|
final event = controller.allEvents[i];
|
||||||
|
switch (event.messageType) {
|
||||||
|
case MessageTypes.Video:
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 52.0),
|
||||||
|
child: Center(
|
||||||
|
child: GestureDetector(
|
||||||
|
// Ignore taps to not go back here:
|
||||||
|
onTap: () {},
|
||||||
|
child: EventVideoPlayer(event),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
case MessageTypes.Image:
|
||||||
|
case MessageTypes.Sticker:
|
||||||
|
default:
|
||||||
|
return InteractiveViewer(
|
||||||
minScale: 1.0,
|
minScale: 1.0,
|
||||||
maxScale: 10.0,
|
maxScale: 10.0,
|
||||||
onInteractionEnd: controller.onInteractionEnds,
|
onInteractionEnd: controller.onInteractionEnds,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Hero(
|
child: Hero(
|
||||||
tag: controller.allEvents[i].eventId,
|
tag: event.eventId,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
// Ignore taps to not go back here:
|
// Ignore taps to not go back here:
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
child: MxcImage(
|
child: MxcImage(
|
||||||
key: ValueKey(controller.allEvents[i].eventId),
|
key: ValueKey(event.eventId),
|
||||||
event: controller.allEvents[i],
|
event: event,
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
isThumbnail: false,
|
isThumbnail: false,
|
||||||
animated: true,
|
animated: true,
|
||||||
|
|
@ -95,7 +114,9 @@ class ImageViewerView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (hovered && controller.canGoBack)
|
if (hovered && controller.canGoBack)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,152 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:chewie/chewie.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:universal_html/html.dart' as html;
|
||||||
|
import 'package:video_player/video_player.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
|
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
|
||||||
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
|
import 'package:fluffychat/widgets/blur_hash.dart';
|
||||||
|
import '../../../utils/error_reporter.dart';
|
||||||
|
import '../../widgets/mxc_image.dart';
|
||||||
|
|
||||||
|
class EventVideoPlayer extends StatefulWidget {
|
||||||
|
final Event event;
|
||||||
|
|
||||||
|
const EventVideoPlayer(
|
||||||
|
this.event, {
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
EventVideoPlayerState createState() => EventVideoPlayerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class EventVideoPlayerState extends State<EventVideoPlayer> {
|
||||||
|
ChewieController? _chewieController;
|
||||||
|
VideoPlayerController? _videoPlayerController;
|
||||||
|
|
||||||
|
// The video_player package only doesn't support Windows and Linux.
|
||||||
|
final _supportsVideoPlayer =
|
||||||
|
!PlatformInfos.isWindows && !PlatformInfos.isLinux;
|
||||||
|
|
||||||
|
void _downloadAction() async {
|
||||||
|
if (!_supportsVideoPlayer) {
|
||||||
|
widget.event.saveFile(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final videoFile = await widget.event.downloadAndDecryptAttachment();
|
||||||
|
|
||||||
|
// Dispose the controllers if we already have them.
|
||||||
|
_disposeControllers();
|
||||||
|
late VideoPlayerController videoPlayerController;
|
||||||
|
|
||||||
|
// Create the VideoPlayerController from the contents of videoFile.
|
||||||
|
if (kIsWeb) {
|
||||||
|
final blob = html.Blob([videoFile.bytes]);
|
||||||
|
final networkUri = Uri.parse(html.Url.createObjectUrlFromBlob(blob));
|
||||||
|
videoPlayerController = VideoPlayerController.networkUrl(networkUri);
|
||||||
|
} else {
|
||||||
|
final tempDir = await getTemporaryDirectory();
|
||||||
|
final fileName = Uri.encodeComponent(
|
||||||
|
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last,
|
||||||
|
);
|
||||||
|
final file = File('${tempDir.path}/${fileName}_${videoFile.name}');
|
||||||
|
if (await file.exists() == false) {
|
||||||
|
await file.writeAsBytes(videoFile.bytes);
|
||||||
|
}
|
||||||
|
videoPlayerController = VideoPlayerController.file(file);
|
||||||
|
}
|
||||||
|
_videoPlayerController = videoPlayerController;
|
||||||
|
|
||||||
|
await videoPlayerController.initialize();
|
||||||
|
|
||||||
|
// Create a ChewieController on top.
|
||||||
|
_chewieController = ChewieController(
|
||||||
|
videoPlayerController: videoPlayerController,
|
||||||
|
useRootNavigator: !kIsWeb,
|
||||||
|
autoPlay: true,
|
||||||
|
autoInitialize: true,
|
||||||
|
looping: true,
|
||||||
|
);
|
||||||
|
} on IOException catch (e) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(e.toLocalizedString(context)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (e, s) {
|
||||||
|
ErrorReporter(context, 'Unable to play video').onErrorCallback(e, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _disposeControllers() {
|
||||||
|
_chewieController?.dispose();
|
||||||
|
_videoPlayerController?.dispose();
|
||||||
|
_chewieController = null;
|
||||||
|
_videoPlayerController = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_disposeControllers();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
_downloadAction();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static const String fallbackBlurHash = 'L5H2EC=PM+yV0g-mq.wG9c010J}I';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final hasThumbnail = widget.event.hasThumbnail;
|
||||||
|
final blurHash = (widget.event.infoMap as Map<String, dynamic>)
|
||||||
|
.tryGet<String>('xyz.amorgan.blurhash') ??
|
||||||
|
fallbackBlurHash;
|
||||||
|
|
||||||
|
const width = 300.0;
|
||||||
|
|
||||||
|
final chewieController = _chewieController;
|
||||||
|
return chewieController != null
|
||||||
|
? Center(child: Chewie(controller: chewieController))
|
||||||
|
: Stack(
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: hasThumbnail
|
||||||
|
? MxcImage(
|
||||||
|
event: widget.event,
|
||||||
|
isThumbnail: true,
|
||||||
|
width: width,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (context) => BlurHash(
|
||||||
|
blurhash: blurHash,
|
||||||
|
width: width,
|
||||||
|
height: width,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: BlurHash(
|
||||||
|
blurhash: blurHash,
|
||||||
|
width: width,
|
||||||
|
height: width,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Center(child: CircularProgressIndicator.adaptive()),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:fluffychat/widgets/theme_builder.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:dynamic_color/dynamic_color.dart';
|
import 'package:dynamic_color/dynamic_color.dart';
|
||||||
|
|
@ -66,6 +67,12 @@ class SettingsStyleView extends StatelessWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
SettingsSwitchListTile.adaptive(
|
||||||
|
title: L10n.of(context).pureBlackToggle,
|
||||||
|
onChanged: (b) => ThemeController.of(context).setPureBlack(b),
|
||||||
|
storeKey: SettingKeys.pureBlack,
|
||||||
|
defaultValue: ThemeController.of(context).pureBlack,
|
||||||
|
),
|
||||||
Divider(
|
Divider(
|
||||||
color: theme.dividerColor,
|
color: theme.dividerColor,
|
||||||
),
|
),
|
||||||
|
|
@ -226,7 +233,7 @@ class SettingsStyleView extends StatelessWidget {
|
||||||
vertical: 8,
|
vertical: 8,
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
'погнали в роблокс?',
|
'Рассказать шутку?',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: theme.onBubbleColor,
|
color: theme.onBubbleColor,
|
||||||
fontSize: AppConfig.messageFontSize *
|
fontSize: AppConfig.messageFontSize *
|
||||||
|
|
@ -259,7 +266,7 @@ class SettingsStyleView extends StatelessWidget {
|
||||||
vertical: 8,
|
vertical: 8,
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Го, в toilet tower defense',
|
'Давай',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: theme.colorScheme.onSurface,
|
color: theme.colorScheme.onSurface,
|
||||||
fontSize: AppConfig.messageFontSize *
|
fontSize: AppConfig.messageFontSize *
|
||||||
|
|
@ -270,6 +277,38 @@ class SettingsStyleView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
left: 12 + 12 + Avatar.defaultSize,
|
||||||
|
right: 12,
|
||||||
|
top: accountConfig.wallpaperUrl == null
|
||||||
|
? 0
|
||||||
|
: 12,
|
||||||
|
bottom: 12,
|
||||||
|
),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.bubbleColor,
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
AppConfig.borderRadius,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
vertical: 8,
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
'Видит заяц как лиса кушает помидор. Он спрашивает: "лиса, а что это ты кушаешь?", она отвечает - помидор.\nЗаяц просит: "А можно мне тоже?", на что лиса отвечает "Нет, но в той стороне медведь раздаёт помидоры.".\nЗаяц поскакал куда лиса указала, а чтобы не забыть, всю дорогу говорил "помидор". Вдруг, он упал и забыл это слово.\n"Как там было..." - подумал заяц, и вспомнил: "А, точно, поморда!"\nЗаяц допрыгивает до того места, и спрашивает медведя: "Медведь, а можно мне поморда?".\nНу и медведь шарахнул битой ему по физиономии.',
|
||||||
|
style: TextStyle(
|
||||||
|
color: theme.onBubbleColor,
|
||||||
|
fontSize: AppConfig.messageFontSize *
|
||||||
|
AppConfig.fontSizeFactor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ abstract class PlatformInfos {
|
||||||
|
|
||||||
static bool get usesTouchscreen => !isMobile;
|
static bool get usesTouchscreen => !isMobile;
|
||||||
|
|
||||||
|
static bool get supportsVideoPlayer => !isWindows && !isLinux;
|
||||||
|
|
||||||
/// Web could also record in theory but currently only wav which is too large
|
/// Web could also record in theory but currently only wav which is too large
|
||||||
static bool get platformCanRecord => (isMobile || isMacOS);
|
static bool get platformCanRecord => (isMobile || isMacOS);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,12 @@ class FluffyChatApp extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ThemeBuilder(
|
return ThemeBuilder(
|
||||||
builder: (context, themeMode, primaryColor) => MaterialApp.router(
|
builder: (context, themeMode, primaryColor, pureBlack) => MaterialApp.router(
|
||||||
title: AppConfig.applicationName,
|
title: AppConfig.applicationName,
|
||||||
themeMode: themeMode,
|
themeMode: themeMode,
|
||||||
theme: FluffyThemes.buildTheme(context, Brightness.light, primaryColor),
|
theme: FluffyThemes.buildTheme(context, Brightness.light, primaryColor, pureBlack),
|
||||||
darkTheme:
|
darkTheme:
|
||||||
FluffyThemes.buildTheme(context, Brightness.dark, primaryColor),
|
FluffyThemes.buildTheme(context, Brightness.dark, primaryColor, pureBlack),
|
||||||
scrollBehavior: CustomScrollBehavior(),
|
scrollBehavior: CustomScrollBehavior(),
|
||||||
localizationsDelegates: L10n.localizationsDelegates,
|
localizationsDelegates: L10n.localizationsDelegates,
|
||||||
supportedLocales: L10n.supportedLocales,
|
supportedLocales: L10n.supportedLocales,
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,18 @@ class ThemeBuilder extends StatefulWidget {
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
ThemeMode themeMode,
|
ThemeMode themeMode,
|
||||||
Color? primaryColor,
|
Color? primaryColor,
|
||||||
|
bool pureBlack,
|
||||||
) builder;
|
) builder;
|
||||||
|
|
||||||
final String themeModeSettingsKey;
|
final String themeModeSettingsKey;
|
||||||
final String primaryColorSettingsKey;
|
final String primaryColorSettingsKey;
|
||||||
|
final String pureBlackSettingsKey;
|
||||||
|
|
||||||
const ThemeBuilder({
|
const ThemeBuilder({
|
||||||
required this.builder,
|
required this.builder,
|
||||||
this.themeModeSettingsKey = 'theme_mode',
|
this.themeModeSettingsKey = 'theme_mode',
|
||||||
this.primaryColorSettingsKey = 'primary_color',
|
this.primaryColorSettingsKey = 'primary_color',
|
||||||
|
this.pureBlackSettingsKey = 'pure_black',
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -32,11 +35,14 @@ class ThemeController extends State<ThemeBuilder> {
|
||||||
SharedPreferences? _sharedPreferences;
|
SharedPreferences? _sharedPreferences;
|
||||||
ThemeMode? _themeMode;
|
ThemeMode? _themeMode;
|
||||||
Color? _primaryColor;
|
Color? _primaryColor;
|
||||||
|
bool? _pureBlack;
|
||||||
|
|
||||||
ThemeMode get themeMode => _themeMode ?? ThemeMode.system;
|
ThemeMode get themeMode => _themeMode ?? ThemeMode.system;
|
||||||
|
|
||||||
Color? get primaryColor => _primaryColor;
|
Color? get primaryColor => _primaryColor;
|
||||||
|
|
||||||
|
bool get pureBlack => _pureBlack ?? false;
|
||||||
|
|
||||||
static ThemeController of(BuildContext context) =>
|
static ThemeController of(BuildContext context) =>
|
||||||
Provider.of<ThemeController>(
|
Provider.of<ThemeController>(
|
||||||
context,
|
context,
|
||||||
|
|
@ -49,11 +55,13 @@ class ThemeController extends State<ThemeBuilder> {
|
||||||
|
|
||||||
final rawThemeMode = preferences.getString(widget.themeModeSettingsKey);
|
final rawThemeMode = preferences.getString(widget.themeModeSettingsKey);
|
||||||
final rawColor = preferences.getInt(widget.primaryColorSettingsKey);
|
final rawColor = preferences.getInt(widget.primaryColorSettingsKey);
|
||||||
|
final rawPureBlack = preferences.getBool(widget.pureBlackSettingsKey);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_themeMode = ThemeMode.values
|
_themeMode = ThemeMode.values
|
||||||
.singleWhereOrNull((value) => value.name == rawThemeMode);
|
.singleWhereOrNull((value) => value.name == rawThemeMode);
|
||||||
_primaryColor = rawColor == null ? null : Color(rawColor);
|
_primaryColor = rawColor == null ? null : Color(rawColor);
|
||||||
|
_pureBlack = rawPureBlack;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,6 +90,15 @@ class ThemeController extends State<ThemeBuilder> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> setPureBlack(bool newPureBlack) async {
|
||||||
|
final preferences =
|
||||||
|
_sharedPreferences ??= await SharedPreferences.getInstance();
|
||||||
|
await preferences.setBool(widget.pureBlackSettingsKey, newPureBlack);
|
||||||
|
setState(() {
|
||||||
|
_pureBlack = newPureBlack;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
WidgetsBinding.instance.addPostFrameCallback(_loadData);
|
WidgetsBinding.instance.addPostFrameCallback(_loadData);
|
||||||
|
|
@ -97,6 +114,7 @@ class ThemeController extends State<ThemeBuilder> {
|
||||||
context,
|
context,
|
||||||
themeMode,
|
themeMode,
|
||||||
primaryColor ?? light?.primary,
|
primaryColor ?? light?.primary,
|
||||||
|
pureBlack,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
import 'package:matrix/encryption/utils/key_verification.dart';
|
import 'package:matrix/encryption/utils/key_verification.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart';
|
|
||||||
|
|
||||||
Future<Client> prepareTestClient({
|
Future<Client> prepareTestClient({
|
||||||
bool loggedIn = false,
|
bool loggedIn = false,
|
||||||
Uri? homeserver,
|
Uri? homeserver,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue