2021-07-06 23:21:25 +00:00
import ' dart:io ' ;
import ' package:flutter/cupertino.dart ' ;
2023-08-29 14:05:41 +00:00
import " package:flutter/foundation.dart " ;
2021-07-06 23:21:25 +00:00
import ' package:flutter/material.dart ' ;
2023-08-29 22:30:04 +00:00
import " package:logging/logging.dart " ;
2023-04-07 05:41:42 +00:00
import " package:photos/generated/l10n.dart " ;
2023-08-25 04:39:30 +00:00
import ' package:photos/models/file/file.dart ' ;
import ' package:photos/models/file/file_type.dart ' ;
import ' package:photos/models/file/trash_file.dart ' ;
2023-08-28 05:58:02 +00:00
import ' package:photos/models/selected_files.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 ' ;
2023-02-22 09:50:33 +00:00
import " package:photos/ui/actions/file/file_actions.dart " ;
2023-06-06 09:57:17 +00:00
import ' package:photos/ui/collections/collection_action_sheet.dart ' ;
2021-10-12 22:51:19 +00:00
import ' package:photos/utils/delete_file_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
2023-08-24 16:27:35 +00:00
class FileBottomBar extends StatefulWidget {
2023-08-24 16:56:24 +00:00
final EnteFile file ;
final Function ( EnteFile ) onEditRequested ;
final Function ( EnteFile ) onFileRemoved ;
2021-09-15 20:40:08 +00:00
final bool showOnlyInfoButton ;
2023-02-22 10:54:31 +00:00
final int ? userID ;
2023-07-03 12:41:44 +00:00
final ValueNotifier < bool > enableFullScreenNotifier ;
2021-07-06 23:21:25 +00:00
2023-08-24 16:27:35 +00:00
const FileBottomBar (
2021-07-11 08:01:47 +00:00
this . file ,
2021-09-15 20:40:08 +00:00
this . onEditRequested ,
this . showOnlyInfoButton , {
2023-02-22 10:54:31 +00:00
required this . onFileRemoved ,
2023-07-03 12:41:44 +00:00
required this . enableFullScreenNotifier ,
2023-02-22 10:54:31 +00:00
this . userID ,
2022-12-30 12:10:17 +00:00
Key ? key ,
2021-07-06 23:21:25 +00:00
} ) : super ( key: key ) ;
@ override
2023-08-24 16:27:35 +00:00
FileBottomBarState createState ( ) = > FileBottomBarState ( ) ;
2021-07-06 23:21:25 +00:00
}
2023-08-24 16:27:35 +00:00
class FileBottomBarState extends State < FileBottomBar > {
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
}
2021-10-04 09:51:45 +00:00
void safeRefresh ( ) {
if ( mounted ) {
setState ( ( ) { } ) ;
}
}
2021-07-06 23:21:25 +00:00
Widget _getBottomBar ( ) {
2023-08-29 22:30:04 +00:00
Logger ( " FileBottomBar " ) . fine ( " building bottom bar $ {widget.file
. generatedID } " );
2022-08-29 14:43:31 +00:00
final List < Widget > children = [ ] ;
2023-02-22 10:54:31 +00:00
final bool isOwnedByUser =
widget . file . ownerID = = null | | widget . file . ownerID = = widget . userID ;
2023-08-29 14:05:41 +00:00
if ( kDebugMode ) {
children . add (
Text (
widget . file . generatedID ? . toString ( ) ? ? ' null ' ,
2023-08-29 22:30:04 +00:00
style: const TextStyle ( color: Colors . white ) ,
2023-08-29 14:05: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: " 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 {
2023-03-20 05:46:51 +00:00
await _displayDetails ( widget . file ) ;
2022-11-05 05:23:21 +00:00
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 ) ;
}
2023-02-22 10:54:31 +00:00
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
) ,
) ,
) ;
}
2023-02-22 10:54:31 +00:00
if ( isOwnedByUser ) {
2021-10-04 07:08:41 +00:00
children . add (
Tooltip (
2023-04-07 05:41:42 +00:00
message: S . of ( context ) . delete ,
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 (
2023-02-22 10:54:31 +00:00
Platform . isAndroid
? Icons . delete_outline
: CupertinoIcons . delete ,
2022-05-13 06:28:12 +00:00
color: Colors . white ,
) ,
2021-10-04 09:51:45 +00:00
onPressed: ( ) async {
2023-02-22 10:54:31 +00:00
await _showSingleFileDeleteSheet ( widget . file ) ;
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 (
2023-04-07 05:41:42 +00:00
message: S . of ( context ) . 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 ;
2023-07-03 12:41:44 +00:00
return ValueListenableBuilder (
valueListenable: widget . enableFullScreenNotifier ,
builder: ( BuildContext context , bool isFullScreen , _ ) {
return IgnorePointer (
ignoring: isFullScreen ,
child: AnimatedOpacity (
opacity: isFullScreen ? 0 : 1 ,
duration: const Duration ( milliseconds: 150 ) ,
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-11-05 04:41:21 +00:00
) ,
2023-07-03 12:41:44 +00:00
) ,
child: Padding (
padding: EdgeInsets . only ( bottom: safeAreaBottomPadding ) ,
child: Column (
mainAxisSize: MainAxisSize . min ,
children: [
widget . file . caption ? . isNotEmpty ? ? false
? Padding (
padding: const EdgeInsets . fromLTRB (
16 ,
28 ,
16 ,
12 ,
) ,
child: Text (
widget . file . caption ! ,
overflow: TextOverflow . ellipsis ,
maxLines: 4 ,
style: getEnteTextTheme ( context )
. small
. copyWith ( color: textBaseDark ) ,
textAlign: TextAlign . center ,
) ,
)
: 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
) ,
2023-07-03 12:41:44 +00:00
) ;
} ,
2021-07-06 23:21:25 +00:00
) ;
}
2023-08-24 16:56:24 +00:00
Future < void > _showSingleFileDeleteSheet ( EnteFile file ) async {
2023-02-22 10:54:31 +00:00
await showSingleFileDeleteSheet (
context ,
file ,
onFileRemoved: widget . onFileRemoved ,
) ;
}
2021-10-12 21:40:22 +00:00
void _addTrashOptions ( List < Widget > children ) {
children . add (
Tooltip (
2023-04-07 05:41:42 +00:00
message: S . of ( context ) . 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 ) ;
2023-02-14 10:13:34 +00:00
showCollectionActionSheet (
2022-06-11 08:23:52 +00:00
context ,
2023-02-14 10:13:34 +00:00
selectedFiles: selectedFiles ,
2023-01-25 04:57:40 +00:00
actionType: CollectionActionType . restoreFiles ,
2022-06-11 08:23:52 +00:00
) ;
2021-10-12 21:40:22 +00:00
} ,
) ,
) ,
) ,
) ;
children . add (
Tooltip (
2023-04-07 05:41:42 +00:00
message: S . of ( context ) . 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 > [ ] ;
2022-12-30 12:10:17 +00:00
trashedFile . add ( widget . file as TrashFile ) ;
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
} ,
) ,
) ,
) ,
) ;
}
2023-08-24 16:56:24 +00:00
Future < void > _displayDetails ( EnteFile file ) async {
2023-03-20 05:46:51 +00:00
await showDetailsSheet ( context , file ) ;
2021-07-06 23:21:25 +00:00
}
}