control_bottom_app_bar.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import 'dart:io';
  2. import 'package:easy_localization/easy_localization.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:hooks_riverpod/hooks_riverpod.dart';
  5. import 'package:immich_mobile/modules/album/ui/add_to_album_sliverlist.dart';
  6. import 'package:immich_mobile/modules/home/ui/delete_dialog.dart';
  7. import 'package:immich_mobile/modules/home/ui/upload_dialog.dart';
  8. import 'package:immich_mobile/shared/models/asset.dart';
  9. import 'package:immich_mobile/shared/ui/drag_sheet.dart';
  10. import 'package:immich_mobile/shared/models/album.dart';
  11. class ControlBottomAppBar extends ConsumerWidget {
  12. final void Function() onShare;
  13. final void Function() onFavorite;
  14. final void Function() onArchive;
  15. final void Function() onDelete;
  16. final Function(Album album) onAddToAlbum;
  17. final void Function() onCreateNewAlbum;
  18. final void Function() onUpload;
  19. final List<Album> albums;
  20. final List<Album> sharedAlbums;
  21. final bool enabled;
  22. final AssetState selectionAssetState;
  23. const ControlBottomAppBar({
  24. Key? key,
  25. required this.onShare,
  26. required this.onFavorite,
  27. required this.onArchive,
  28. required this.onDelete,
  29. required this.sharedAlbums,
  30. required this.albums,
  31. required this.onAddToAlbum,
  32. required this.onCreateNewAlbum,
  33. required this.onUpload,
  34. this.selectionAssetState = AssetState.remote,
  35. this.enabled = true,
  36. }) : super(key: key);
  37. @override
  38. Widget build(BuildContext context, WidgetRef ref) {
  39. var isDarkMode = Theme.of(context).brightness == Brightness.dark;
  40. var hasRemote = selectionAssetState == AssetState.remote;
  41. Widget renderActionButtons() {
  42. return Row(
  43. children: [
  44. ControlBoxButton(
  45. iconData: Platform.isAndroid
  46. ? Icons.share_rounded
  47. : Icons.ios_share_rounded,
  48. label: "control_bottom_app_bar_share".tr(),
  49. onPressed: enabled ? onShare : null,
  50. ),
  51. if (hasRemote)
  52. ControlBoxButton(
  53. iconData: Icons.archive,
  54. label: "control_bottom_app_bar_archive".tr(),
  55. onPressed: enabled ? onArchive : null,
  56. ),
  57. if (hasRemote)
  58. ControlBoxButton(
  59. iconData: Icons.favorite_border_rounded,
  60. label: "control_bottom_app_bar_favorite".tr(),
  61. onPressed: enabled ? onFavorite : null,
  62. ),
  63. ControlBoxButton(
  64. iconData: Icons.delete_outline_rounded,
  65. label: "control_bottom_app_bar_delete".tr(),
  66. onPressed: enabled
  67. ? () => showDialog(
  68. context: context,
  69. builder: (BuildContext context) {
  70. return DeleteDialog(
  71. onDelete: onDelete,
  72. );
  73. },
  74. )
  75. : null,
  76. ),
  77. if (!hasRemote)
  78. ControlBoxButton(
  79. iconData: Icons.backup_outlined,
  80. label: "Upload",
  81. onPressed: enabled
  82. ? () => showDialog(
  83. context: context,
  84. builder: (BuildContext context) {
  85. return UploadDialog(
  86. onUpload: onUpload,
  87. );
  88. },
  89. )
  90. : null,
  91. ),
  92. ],
  93. );
  94. }
  95. return DraggableScrollableSheet(
  96. initialChildSize: hasRemote ? 0.30 : 0.18,
  97. minChildSize: 0.18,
  98. maxChildSize: hasRemote ? 0.57 : 0.18,
  99. snap: true,
  100. builder: (
  101. BuildContext context,
  102. ScrollController scrollController,
  103. ) {
  104. return Card(
  105. color: isDarkMode ? Colors.grey[900] : Colors.grey[100],
  106. surfaceTintColor: Colors.transparent,
  107. elevation: 18.0,
  108. shape: const RoundedRectangleBorder(
  109. borderRadius: BorderRadius.only(
  110. topLeft: Radius.circular(12),
  111. topRight: Radius.circular(12),
  112. ),
  113. ),
  114. margin: const EdgeInsets.all(0),
  115. child: CustomScrollView(
  116. controller: scrollController,
  117. slivers: [
  118. SliverToBoxAdapter(
  119. child: Column(
  120. children: <Widget>[
  121. const SizedBox(height: 12),
  122. const CustomDraggingHandle(),
  123. const SizedBox(height: 12),
  124. renderActionButtons(),
  125. if (hasRemote)
  126. const Divider(
  127. indent: 16,
  128. endIndent: 16,
  129. thickness: 1,
  130. ),
  131. if (hasRemote)
  132. AddToAlbumTitleRow(
  133. onCreateNewAlbum: enabled ? onCreateNewAlbum : null,
  134. ),
  135. ],
  136. ),
  137. ),
  138. if (hasRemote)
  139. SliverPadding(
  140. padding: const EdgeInsets.symmetric(horizontal: 16),
  141. sliver: AddToAlbumSliverList(
  142. albums: albums,
  143. sharedAlbums: sharedAlbums,
  144. onAddToAlbum: onAddToAlbum,
  145. enabled: enabled,
  146. ),
  147. ),
  148. if (hasRemote)
  149. const SliverToBoxAdapter(
  150. child: SizedBox(height: 200),
  151. ),
  152. ],
  153. ),
  154. );
  155. },
  156. );
  157. }
  158. }
  159. class AddToAlbumTitleRow extends StatelessWidget {
  160. const AddToAlbumTitleRow({
  161. super.key,
  162. required this.onCreateNewAlbum,
  163. });
  164. final VoidCallback? onCreateNewAlbum;
  165. @override
  166. Widget build(BuildContext context) {
  167. return Padding(
  168. padding: const EdgeInsets.symmetric(horizontal: 16),
  169. child: Row(
  170. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  171. children: [
  172. const Text(
  173. "common_add_to_album",
  174. style: TextStyle(
  175. fontSize: 14,
  176. fontWeight: FontWeight.bold,
  177. ),
  178. ).tr(),
  179. TextButton.icon(
  180. onPressed: onCreateNewAlbum,
  181. icon: const Icon(Icons.add),
  182. label: Text(
  183. "common_create_new_album",
  184. style: TextStyle(
  185. color: Theme.of(context).primaryColor,
  186. fontWeight: FontWeight.bold,
  187. fontSize: 14,
  188. ),
  189. ).tr(),
  190. ),
  191. ],
  192. ),
  193. );
  194. }
  195. }