2022-09-07 08:30:09 +00:00
// @dart=2.9
2021-07-06 23:21:25 +00:00
import ' dart:io ' ;
import ' package:flutter/cupertino.dart ' ;
import ' package:flutter/material.dart ' ;
2022-11-02 13:56:59 +00:00
import ' package:modal_bottom_sheet/modal_bottom_sheet.dart ' ;
2021-10-13 17:22:17 +00:00
import ' package:page_transition/page_transition.dart ' ;
2021-10-04 07:08:41 +00:00
import ' package:photos/core/configuration.dart ' ;
2021-07-06 23:21:25 +00:00
import ' package:photos/models/file.dart ' ;
import ' package:photos/models/file_type.dart ' ;
2021-10-03 21:56:22 +00:00
import ' package:photos/models/magic_metadata.dart ' ;
2021-10-13 17:22:17 +00:00
import ' package:photos/models/selected_files.dart ' ;
2021-10-12 21:40:22 +00:00
import ' package:photos/models/trash_file.dart ' ;
2022-11-02 13:30:56 +00:00
import ' package:photos/services/collections_service.dart ' ;
2022-11-03 08:51:31 +00:00
import ' package:photos/theme/colors.dart ' ;
2022-11-03 03:08:27 +00:00
import ' package:photos/theme/ente_theme.dart ' ;
2021-10-17 13:03:02 +00:00
import ' package:photos/ui/create_collection_page.dart ' ;
2022-09-07 03:42:30 +00:00
import ' package:photos/ui/viewer/file/file_info_widget.dart ' ;
2021-10-12 22:51:19 +00:00
import ' package:photos/utils/delete_file_util.dart ' ;
2021-10-30 05:43:56 +00:00
import ' package:photos/utils/magic_util.dart ' ;
2021-07-06 23:21:25 +00:00
import ' package:photos/utils/share_util.dart ' ;
2021-10-12 22:51:19 +00:00
2021-07-06 23:21:25 +00:00
class FadingBottomBar extends StatefulWidget {
final File file ;
final Function ( File ) onEditRequested ;
2021-09-15 20:40:08 +00:00
final bool showOnlyInfoButton ;
2021-07-06 23:21:25 +00:00
2022-07-04 08:43:01 +00:00
const FadingBottomBar (
2021-07-11 08:01:47 +00:00
this . file ,
2021-09-15 20:40:08 +00:00
this . onEditRequested ,
this . showOnlyInfoButton , {
2021-07-06 23:21:25 +00:00
Key key ,
} ) : super ( key: key ) ;
@ override
FadingBottomBarState createState ( ) = > FadingBottomBarState ( ) ;
}
class FadingBottomBarState extends State < FadingBottomBar > {
bool _shouldHide = false ;
2022-04-22 16:04:34 +00:00
final GlobalKey shareButtonKey = GlobalKey ( ) ;
2021-07-06 23:21:25 +00:00
@ override
Widget build ( BuildContext context ) {
2022-05-13 08:48:13 +00:00
return _getBottomBar ( ) ;
2021-07-06 23:21:25 +00:00
}
void hide ( ) {
setState ( ( ) {
_shouldHide = true ;
} ) ;
}
void show ( ) {
setState ( ( ) {
_shouldHide = false ;
} ) ;
}
2021-10-04 09:51:45 +00:00
void safeRefresh ( ) {
if ( mounted ) {
setState ( ( ) { } ) ;
}
}
2021-07-06 23:21:25 +00:00
Widget _getBottomBar ( ) {
2022-08-29 14:43:31 +00:00
final List < Widget > children = [ ] ;
2021-07-06 23:21:25 +00:00
children . add (
2021-10-03 21:58:33 +00:00
Tooltip (
2022-05-17 11:38:21 +00:00
message: " Info " ,
2021-10-03 21:58:33 +00:00
child: Padding (
padding: const EdgeInsets . only ( top: 12 , bottom: 12 ) ,
child: IconButton (
icon: Icon (
2022-05-13 06:28:12 +00:00
Platform . isAndroid ? Icons . info_outline : CupertinoIcons . info ,
color: Colors . white ,
) ,
2022-11-05 05:23:21 +00:00
onPressed: ( ) async {
await _displayInfo ( widget . file ) ;
safeRefresh ( ) ; //to instantly show the new caption if keypad is closed after pressing 'done' - here the caption will be updated before the bottom sheet is closed
await Future . delayed (
const Duration ( milliseconds: 500 ) ,
) ; //Waiting for some time till the caption gets updated in db if the user closes the bottom sheet without pressing 'done'
safeRefresh ( ) ;
2021-10-03 21:58:33 +00:00
} ,
) ,
2021-07-06 23:21:25 +00:00
) ,
) ,
) ;
2021-10-12 21:40:22 +00:00
if ( widget . file is TrashFile ) {
_addTrashOptions ( children ) ;
}
2022-11-06 08:34:06 +00:00
final bool isUploadedByUser = widget . file . uploadedFileID ! = null & &
2022-11-02 13:30:56 +00:00
widget . file . ownerID = = Configuration . instance . getUserID ( ) ;
bool isFileHidden = false ;
if ( isUploadedByUser ) {
isFileHidden = CollectionsService . instance
. getCollectionByID ( widget . file . collectionID )
? . isHidden ( ) ? ?
false ;
}
2021-10-12 21:40:22 +00:00
if ( ! widget . showOnlyInfoButton & & widget . file is ! TrashFile ) {
2021-09-15 20:40:08 +00:00
if ( widget . file . fileType = = FileType . image | |
widget . file . fileType = = FileType . livePhoto ) {
children . add (
2021-10-03 21:58:33 +00:00
Tooltip (
2022-05-17 11:38:21 +00:00
message: " Edit " ,
2021-10-03 21:58:33 +00:00
child: Padding (
padding: const EdgeInsets . only ( top: 12 , bottom: 12 ) ,
child: IconButton (
2022-07-04 06:02:17 +00:00
icon: const Icon (
2022-05-13 06:28:12 +00:00
Icons . tune_outlined ,
color: Colors . white ,
) ,
2021-10-03 21:58:33 +00:00
onPressed: ( ) {
widget . onEditRequested ( widget . file ) ;
} ,
) ,
2021-09-15 20:40:08 +00:00
) ,
) ,
) ;
}
2022-11-02 13:30:56 +00:00
if ( isUploadedByUser & & ! isFileHidden ) {
2022-08-29 14:43:31 +00:00
final bool isArchived =
2022-09-19 11:52:20 +00:00
widget . file . magicMetadata . visibility = = visibilityArchive ;
2021-10-04 07:08:41 +00:00
children . add (
Tooltip (
2022-10-31 09:56:59 +00:00
message: isArchived ? " Unarchive " : " Archive " ,
2021-10-04 07:08:41 +00:00
child: Padding (
padding: const EdgeInsets . only ( top: 12 , bottom: 12 ) ,
child: IconButton (
2022-05-13 06:28:12 +00:00
icon: Icon (
2022-10-31 09:56:59 +00:00
isArchived ? Icons . unarchive : Icons . archive_outlined ,
2022-05-13 06:28:12 +00:00
color: Colors . white ,
) ,
2021-10-04 09:51:45 +00:00
onPressed: ( ) async {
await changeVisibility (
2021-10-04 07:08:41 +00:00
context ,
[ widget . file ] ,
2022-09-19 11:52:20 +00:00
isArchived ? visibilityVisible : visibilityArchive ,
2021-10-04 07:08:41 +00:00
) ;
2021-10-04 09:51:45 +00:00
safeRefresh ( ) ;
2021-10-04 07:08:41 +00:00
} ,
2021-10-03 21:57:09 +00:00
) ,
) ,
2021-10-03 21:56:22 +00:00
) ,
2021-10-04 07:08:41 +00:00
) ;
}
2021-07-06 23:21:25 +00:00
children . add (
2021-10-03 21:58:33 +00:00
Tooltip (
2022-05-17 11:38:21 +00:00
message: " Share " ,
2021-10-03 21:58:33 +00:00
child: Padding (
padding: const EdgeInsets . only ( top: 12 , bottom: 12 ) ,
child: IconButton (
2022-04-22 16:04:34 +00:00
key: shareButtonKey ,
2022-05-13 06:28:12 +00:00
icon: Icon (
Platform . isAndroid
? Icons . share_outlined
: CupertinoIcons . share ,
color: Colors . white ,
) ,
2021-10-03 21:58:33 +00:00
onPressed: ( ) {
2022-04-22 16:04:34 +00:00
share ( context , [ widget . file ] , shareButtonKey: shareButtonKey ) ;
2021-10-03 21:58:33 +00:00
} ,
) ,
2021-07-06 23:21:25 +00:00
) ,
) ,
) ;
}
2022-08-29 14:43:31 +00:00
final safeAreaBottomPadding = MediaQuery . of ( context ) . padding . bottom * . 5 ;
2022-07-01 03:39:57 +00:00
return IgnorePointer (
ignoring: _shouldHide ,
child: AnimatedOpacity (
2022-07-03 09:45:00 +00:00
opacity: _shouldHide ? 0 : 1 ,
2022-07-04 06:02:17 +00:00
duration: const Duration ( milliseconds: 150 ) ,
2022-07-01 03:39:57 +00:00
child: Align (
alignment: Alignment . bottomCenter ,
child: Container (
decoration: BoxDecoration (
gradient: LinearGradient (
begin: Alignment . topCenter ,
end: Alignment . bottomCenter ,
colors: [
Colors . transparent ,
Colors . black . withOpacity ( 0.6 ) ,
Colors . black . withOpacity ( 0.72 ) ,
] ,
stops: const [ 0 , 0.8 , 1 ] ,
) ,
2022-06-07 14:11:06 +00:00
) ,
2022-07-01 03:39:57 +00:00
child: Padding (
padding: EdgeInsets . only ( bottom: safeAreaBottomPadding ) ,
2022-11-05 04:41:21 +00:00
child: Column (
mainAxisSize: MainAxisSize . min ,
children: [
2022-11-05 12:01:25 +00:00
widget . file . caption ? . isNotEmpty ? ? false
2022-11-05 04:41:21 +00:00
? Padding (
padding: const EdgeInsets . fromLTRB (
16 ,
28 ,
16 ,
12 ,
) ,
child: Text (
widget . file . caption ,
style: getEnteTextTheme ( context )
. small
. copyWith ( color: textBaseDark ) ,
2022-11-05 05:58:11 +00:00
textAlign: TextAlign . center ,
2022-11-05 04:41:21 +00:00
) ,
)
: const SizedBox . shrink ( ) ,
Row (
mainAxisAlignment: MainAxisAlignment . spaceAround ,
children: children ,
) ,
] ,
2022-07-01 03:39:57 +00:00
) ,
2021-07-06 23:21:25 +00:00
) ,
2021-09-15 20:40:08 +00:00
) ,
) ,
2021-07-06 23:21:25 +00:00
) ,
) ;
}
2021-10-12 21:40:22 +00:00
void _addTrashOptions ( List < Widget > children ) {
children . add (
Tooltip (
2022-05-17 11:38:21 +00:00
message: " Restore " ,
2021-10-12 21:40:22 +00:00
child: Padding (
padding: const EdgeInsets . only ( top: 12 , bottom: 12 ) ,
child: IconButton (
2022-07-04 06:02:17 +00:00
icon: const Icon (
2022-06-17 02:32:55 +00:00
Icons . restore_outlined ,
color: Colors . white ,
) ,
2021-10-12 21:40:22 +00:00
onPressed: ( ) {
2021-10-17 16:50:25 +00:00
final selectedFiles = SelectedFiles ( ) ;
selectedFiles . toggleSelection ( widget . file ) ;
2021-10-13 17:22:17 +00:00
Navigator . push (
2022-06-11 08:23:52 +00:00
context ,
PageTransition (
type: PageTransitionType . bottomToTop ,
child: CreateCollectionPage (
selectedFiles ,
null ,
actionType: CollectionActionType . restoreFiles ,
) ,
) ,
) ;
2021-10-12 21:40:22 +00:00
} ,
) ,
) ,
) ,
) ;
children . add (
Tooltip (
2022-05-17 11:38:21 +00:00
message: " Delete " ,
2021-10-12 21:40:22 +00:00
child: Padding (
padding: const EdgeInsets . only ( top: 12 , bottom: 12 ) ,
child: IconButton (
2022-07-04 06:02:17 +00:00
icon: const Icon (
2022-06-17 02:32:55 +00:00
Icons . delete_forever_outlined ,
color: Colors . white ,
) ,
2021-10-12 22:51:19 +00:00
onPressed: ( ) async {
final trashedFile = < TrashFile > [ ] ;
trashedFile . add ( widget . file ) ;
2021-10-13 09:25:04 +00:00
if ( await deleteFromTrash ( context , trashedFile ) = = true ) {
Navigator . pop ( context ) ;
}
2021-10-12 21:40:22 +00:00
} ,
) ,
) ,
) ,
) ;
}
2021-07-06 23:21:25 +00:00
Future < void > _displayInfo ( File file ) async {
2022-11-03 08:51:31 +00:00
final colorScheme = getEnteColorScheme ( context ) ;
return showBarModalBottomSheet (
topControl: const SizedBox . shrink ( ) ,
shape: RoundedRectangleBorder ( borderRadius: BorderRadius . circular ( 0 ) ) ,
2022-11-08 09:27:39 +00:00
backgroundColor: colorScheme . backgroundElevated ,
2022-11-07 08:16:00 +00:00
barrierColor: backdropMutedDark ,
2021-07-06 23:21:25 +00:00
context: context ,
builder: ( BuildContext context ) {
2022-11-04 07:07:58 +00:00
return Padding (
padding:
EdgeInsets . only ( bottom: MediaQuery . of ( context ) . viewInsets . bottom ) ,
child: FileInfoWidget ( file ) ,
) ;
2021-07-06 23:21:25 +00:00
} ,
) ;
}
}