diff --git a/lib/blocs/gallery_model.dart b/lib/blocs/gallery_model.dart index f61715e..bd3cace 100644 --- a/lib/blocs/gallery_model.dart +++ b/lib/blocs/gallery_model.dart @@ -5,9 +5,11 @@ class GalleryProvider with ChangeNotifier { int currentPage = 0; String currentMedia = ''; + bool _controlsVisible = true; int getCurrentPage() => currentPage; String getCurrentMedia() => currentMedia; + bool getControlsVisible() => _controlsVisible; Future setCurrentPage(int page) async { currentPage = page; @@ -20,4 +22,10 @@ class GalleryProvider with ChangeNotifier { notifyListeners(); } + + Future setControlsVisible(bool visible) async { + _controlsVisible = visible; + + notifyListeners(); + } } diff --git a/lib/pages/media_page.dart b/lib/pages/media_page.dart index 718289c..6c58616 100644 --- a/lib/pages/media_page.dart +++ b/lib/pages/media_page.dart @@ -144,175 +144,178 @@ class _MediaPageState extends State { ? CupertinoColors.systemGroupedBackground : CupertinoColors.black, extendBodyBehindAppBar: true, - appBar: CupertinoNavigationBar( - backgroundColor: theme.getTheme() == ThemeData.light() - ? CupertinoColors.systemGroupedBackground.withOpacity(0.7) - : CupertinoColors.black.withOpacity(0.7), - border: Border.all(color: Colors.transparent), - leading: MediaQuery( - data: MediaQueryData( - textScaleFactor: MediaQuery.textScaleFactorOf(context), - ), - child: Transform.translate( - offset: const Offset(-16, 0), - child: CupertinoNavigationBarBackButton( - onPressed: () => Navigator.of(context).pop(), - ), - ), - ), - middle: MediaQuery( - data: MediaQueryData( - textScaleFactor: MediaQuery.textScaleFactorOf(context), - ), - child: Column( - children: [ - Text( - '${media[index].fileName}${media[index].ext}', - style: TextStyle( - color: theme.getTheme() == ThemeData.dark() - ? Colors.white - : Colors.black, + appBar: gallery.getControlsVisible() + ? CupertinoNavigationBar( + backgroundColor: theme.getTheme() == ThemeData.light() + ? CupertinoColors.systemGroupedBackground.withOpacity(0.7) + : CupertinoColors.black.withOpacity(0.7), + border: Border.all(color: Colors.transparent), + leading: MediaQuery( + data: MediaQueryData( + textScaleFactor: MediaQuery.textScaleFactorOf(context), + ), + child: Transform.translate( + offset: const Offset(-16, 0), + child: CupertinoNavigationBarBackButton( + onPressed: () => Navigator.of(context).pop(), + ), ), - maxLines: 1, - overflow: TextOverflow.ellipsis, ), - Text( - '${index + 1}/${media.length}', - style: TextStyle( - color: theme.getTheme() == ThemeData.dark() - ? Colors.white - : Colors.black, + middle: MediaQuery( + data: MediaQueryData( + textScaleFactor: MediaQuery.textScaleFactorOf(context), + ), + child: Column( + children: [ + Text( + '${media[index].fileName}${media[index].ext}', + style: TextStyle( + color: theme.getTheme() == ThemeData.dark() + ? Colors.white + : Colors.black, + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + Text( + '${index + 1}/${media.length}', + style: TextStyle( + color: theme.getTheme() == ThemeData.dark() + ? Colors.white + : Colors.black, + ), + ), + ], ), ), - ], - ), - ), - trailing: Row( - mainAxisSize: MainAxisSize.min, - children: [ - if (!isSaved) - CupertinoButton( - padding: EdgeInsets.zero, - child: const Icon(CupertinoIcons.bookmark), - onPressed: () => { - savedAttachments.addSavedAttachments( - _scaffoldKey.currentContext ?? context, - widget.board ?? '', - media[index].videoName, - ) - }, - ) - else - CupertinoButton( - padding: EdgeInsets.zero, - child: const Icon(CupertinoIcons.bookmark_fill), - onPressed: () => { - showCupertinoDialog( - barrierDismissible: true, - context: context, - builder: (context) { - return StatefulBuilder( - builder: (context, setState) { - return CupertinoAlertDialog( - title: const Text('Delete Attachment?'), + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (!isSaved) + CupertinoButton( + padding: EdgeInsets.zero, + child: const Icon(CupertinoIcons.bookmark), + onPressed: () => { + savedAttachments.addSavedAttachments( + _scaffoldKey.currentContext ?? context, + widget.board ?? '', + media[index].videoName, + ) + }, + ) + else + CupertinoButton( + padding: EdgeInsets.zero, + child: const Icon(CupertinoIcons.bookmark_fill), + onPressed: () => { + showCupertinoDialog( + barrierDismissible: true, + context: context, + builder: (context) { + return StatefulBuilder( + builder: (context, setState) { + return CupertinoAlertDialog( + title: const Text('Delete Attachment?'), + actions: [ + CupertinoDialogAction( + child: const Text( + 'Cancel', + style: TextStyle( + color: CupertinoColors.activeBlue, + ), + ), + onPressed: () => { + Navigator.pop(context), + }, + ), + CupertinoDialogAction( + child: const Text( + 'Delete', + style: TextStyle( + color: CupertinoColors.activeBlue, + ), + ), + onPressed: () => { + savedAttachments + .removeSavedAttachments( + media[index].videoName) + .then( + (value) => { + Navigator.pop(context), + }, + ), + }, + ), + ], + ); + }, + ); + }, + ), + }, + ), + SizedBox( + width: 20, + child: CupertinoButton( + padding: EdgeInsets.zero, + onPressed: () { + showCupertinoModalPopup( + context: context, + builder: (BuildContext context) => + CupertinoActionSheet( actions: [ - CupertinoDialogAction( - child: const Text( - 'Cancel', - style: TextStyle( - color: CupertinoColors.activeBlue, - ), + if (!isSaved) + CupertinoActionSheetAction( + child: const Text('Open in Browser'), + onPressed: () { + launchURL( + 'https://i.4cdn.org/${widget.board}/${media[index].videoName}', + ); + Navigator.pop(context); + }, ), - onPressed: () => { - Navigator.pop(context), + CupertinoActionSheetAction( + child: const Text('Share'), + onPressed: () { + shareMedia( + 'https://i.4cdn.org/${widget.board}/${media[index].videoName}', + media[index].videoName, + _scaffoldKey.currentContext ?? context, + isSaved: isSaved, + ); + Navigator.pop(context); }, ), - CupertinoDialogAction( - child: const Text( - 'Delete', - style: TextStyle( - color: CupertinoColors.activeBlue, - ), - ), - onPressed: () => { - savedAttachments - .removeSavedAttachments( - media[index].videoName) - .then( - (value) => { - Navigator.pop(context), - }, - ), + CupertinoActionSheetAction( + child: const Text('Download'), + onPressed: () { + saveVideo( + 'https://i.4cdn.org/${widget.board}/${media[index].videoName}', + media[index].videoName, + _scaffoldKey.currentContext ?? context, + showSnackBar: true, + isSaved: isSaved, + ); + Navigator.pop(context); }, ), ], - ); - }, - ); - }, - ), - }, - ), - SizedBox( - width: 20, - child: CupertinoButton( - padding: EdgeInsets.zero, - onPressed: () { - showCupertinoModalPopup( - context: context, - builder: (BuildContext context) => CupertinoActionSheet( - actions: [ - if (!isSaved) - CupertinoActionSheetAction( - child: const Text('Open in Browser'), - onPressed: () { - launchURL( - 'https://i.4cdn.org/${widget.board}/${media[index].videoName}', - ); - Navigator.pop(context); - }, + cancelButton: CupertinoActionSheetAction( + child: const Text('Cancel'), + onPressed: () { + Navigator.pop(context); + }, + ), ), - CupertinoActionSheetAction( - child: const Text('Share'), - onPressed: () { - shareMedia( - 'https://i.4cdn.org/${widget.board}/${media[index].videoName}', - media[index].videoName, - _scaffoldKey.currentContext ?? context, - isSaved: isSaved, - ); - Navigator.pop(context); - }, - ), - CupertinoActionSheetAction( - child: const Text('Download'), - onPressed: () { - saveVideo( - 'https://i.4cdn.org/${widget.board}/${media[index].videoName}', - media[index].videoName, - _scaffoldKey.currentContext ?? context, - showSnackBar: true, - isSaved: isSaved, - ); - Navigator.pop(context); - }, - ), - ], - cancelButton: CupertinoActionSheetAction( - child: const Text('Cancel'), - onPressed: () { - Navigator.pop(context); - }, - ), + ); + }, + child: const Icon(Icons.ios_share), ), - ); - }, - child: const Icon(Icons.ios_share), + ), + ], ), - ), - ], - ), - ), + ) + : null, body: PageView.custom( controller: controller, onPageChanged: (pageIndex) => diff --git a/lib/widgets/webm_player.dart b/lib/widgets/webm_player.dart index 933c87a..05abca5 100644 --- a/lib/widgets/webm_player.dart +++ b/lib/widgets/webm_player.dart @@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:flutter_chan/API/save_videos.dart'; +import 'package:flutter_chan/blocs/gallery_model.dart'; import 'package:flutter_chan/blocs/saved_attachments_model.dart'; import 'package:flutter_vlc_player/flutter_vlc_player.dart'; import 'package:provider/provider.dart'; @@ -186,23 +187,26 @@ class VLCPlayerState extends State { final SavedAttachmentsProvider savedAttachmentsProvider = Provider.of(context); final SettingsProvider settings = Provider.of(context); + final GalleryProvider galleryProvider = + Provider.of(context, listen: false); if (widget.isAsset || !settings.getUseCachingOnVideos()) { _videoPlayerController.addListener(listener); - return videoWidget(savedAttachmentsProvider); + return videoWidget(savedAttachmentsProvider, galleryProvider); } else { return FutureBuilder( future: cachedVideo, builder: (context, AsyncSnapshot snapshot) { return snapshot.hasData - ? videoWidget(savedAttachmentsProvider) + ? videoWidget(savedAttachmentsProvider, galleryProvider) : const CupertinoActivityIndicator(); }, ); } } - Stack videoWidget(SavedAttachmentsProvider savedAttachmentsProvider) { + Stack videoWidget(SavedAttachmentsProvider savedAttachmentsProvider, + GalleryProvider galleryProvider) { try { if (_videoPlayerController.value.isInitialized && mounted) { if (savedAttachmentsProvider.playing) { @@ -246,16 +250,26 @@ class VLCPlayerState extends State { Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - VlcPlayer( - controller: _videoPlayerController, - aspectRatio: _videoPlayerController.value.aspectRatio, - placeholder: - const Center(child: CupertinoActivityIndicator()), + GestureDetector( + onTap: () { + setState(() { + galleryProvider.setControlsVisible( + !galleryProvider.getControlsVisible()); + }); + }, + child: AbsorbPointer( + child: VlcPlayer( + controller: _videoPlayerController, + aspectRatio: _videoPlayerController.value.aspectRatio, + placeholder: + const Center(child: CupertinoActivityIndicator()), + ), + ), ), ], ), Opacity( - opacity: controlsVisible ? 1 : 0, + opacity: galleryProvider.getControlsVisible() ? 1 : 0, child: SafeArea( child: Column( children: [