Skip to content

Commit

Permalink
✨ Hide controls on media click
Browse files Browse the repository at this point in the history
  • Loading branch information
wrngwrld committed Feb 18, 2024
1 parent 3732c89 commit c8b0c10
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 164 deletions.
8 changes: 8 additions & 0 deletions lib/blocs/gallery_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> setCurrentPage(int page) async {
currentPage = page;
Expand All @@ -20,4 +22,10 @@ class GalleryProvider with ChangeNotifier {

notifyListeners();
}

Future<void> setControlsVisible(bool visible) async {
_controlsVisible = visible;

notifyListeners();
}
}
313 changes: 158 additions & 155 deletions lib/pages/media_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,175 +144,178 @@ class _MediaPageState extends State<MediaPage> {
? 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) =>
Expand Down
Loading

0 comments on commit c8b0c10

Please sign in to comment.