top_control_app_bar.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:hooks_riverpod/hooks_riverpod.dart';
  4. import 'package:immich_mobile/modules/activities/providers/activity.provider.dart';
  5. import 'package:immich_mobile/shared/models/asset.dart';
  6. import 'package:immich_mobile/shared/providers/asset.provider.dart';
  7. class TopControlAppBar extends HookConsumerWidget {
  8. const TopControlAppBar({
  9. Key? key,
  10. required this.asset,
  11. required this.onMoreInfoPressed,
  12. required this.onDownloadPressed,
  13. required this.onAddToAlbumPressed,
  14. required this.onToggleMotionVideo,
  15. required this.isPlayingMotionVideo,
  16. required this.onFavorite,
  17. required this.onUploadPressed,
  18. required this.isOwner,
  19. required this.shareAlbumId,
  20. required this.onActivitiesPressed,
  21. }) : super(key: key);
  22. final Asset asset;
  23. final Function onMoreInfoPressed;
  24. final VoidCallback? onUploadPressed;
  25. final VoidCallback? onDownloadPressed;
  26. final VoidCallback onToggleMotionVideo;
  27. final VoidCallback onAddToAlbumPressed;
  28. final VoidCallback onActivitiesPressed;
  29. final Function(Asset) onFavorite;
  30. final bool isPlayingMotionVideo;
  31. final bool isOwner;
  32. final String? shareAlbumId;
  33. @override
  34. Widget build(BuildContext context, WidgetRef ref) {
  35. const double iconSize = 22.0;
  36. final a = ref.watch(assetWatcher(asset)).value ?? asset;
  37. final comments = shareAlbumId != null
  38. ? ref.watch(
  39. activityStatisticsStateProvider(
  40. (albumId: shareAlbumId!, assetId: asset.remoteId),
  41. ),
  42. )
  43. : 0;
  44. Widget buildFavoriteButton(a) {
  45. return IconButton(
  46. onPressed: () => onFavorite(a),
  47. icon: Icon(
  48. a.isFavorite ? Icons.favorite : Icons.favorite_border,
  49. color: Colors.grey[200],
  50. ),
  51. );
  52. }
  53. Widget buildLivePhotoButton() {
  54. return IconButton(
  55. onPressed: () {
  56. onToggleMotionVideo();
  57. },
  58. icon: isPlayingMotionVideo
  59. ? Icon(
  60. Icons.motion_photos_pause_outlined,
  61. color: Colors.grey[200],
  62. )
  63. : Icon(
  64. Icons.play_circle_outline_rounded,
  65. color: Colors.grey[200],
  66. ),
  67. );
  68. }
  69. Widget buildMoreInfoButton() {
  70. return IconButton(
  71. onPressed: () {
  72. onMoreInfoPressed();
  73. },
  74. icon: Icon(
  75. Icons.info_outline_rounded,
  76. color: Colors.grey[200],
  77. ),
  78. );
  79. }
  80. Widget buildDownloadButton() {
  81. return IconButton(
  82. onPressed: onDownloadPressed,
  83. icon: Icon(
  84. Icons.cloud_download_outlined,
  85. color: Colors.grey[200],
  86. ),
  87. );
  88. }
  89. Widget buildAddToAlbumButtom() {
  90. return IconButton(
  91. onPressed: () {
  92. onAddToAlbumPressed();
  93. },
  94. icon: Icon(
  95. Icons.add,
  96. color: Colors.grey[200],
  97. ),
  98. );
  99. }
  100. Widget buildActivitiesButton() {
  101. return IconButton(
  102. onPressed: () {
  103. onActivitiesPressed();
  104. },
  105. icon: Row(
  106. crossAxisAlignment: CrossAxisAlignment.center,
  107. children: [
  108. Icon(
  109. Icons.mode_comment_outlined,
  110. color: Colors.grey[200],
  111. ),
  112. if (comments != 0)
  113. Padding(
  114. padding: const EdgeInsets.only(left: 5),
  115. child: Text(
  116. comments.toString(),
  117. style: TextStyle(
  118. fontWeight: FontWeight.bold,
  119. color: Colors.grey[200],
  120. ),
  121. ),
  122. ),
  123. ],
  124. ),
  125. );
  126. }
  127. Widget buildUploadButton() {
  128. return IconButton(
  129. onPressed: onUploadPressed,
  130. icon: Icon(
  131. Icons.backup_outlined,
  132. color: Colors.grey[200],
  133. ),
  134. );
  135. }
  136. Widget buildBackButton() {
  137. return IconButton(
  138. onPressed: () {
  139. AutoRouter.of(context).pop();
  140. },
  141. icon: Icon(
  142. Icons.arrow_back_ios_new_rounded,
  143. size: 20.0,
  144. color: Colors.grey[200],
  145. ),
  146. );
  147. }
  148. return AppBar(
  149. foregroundColor: Colors.grey[100],
  150. backgroundColor: Colors.transparent,
  151. leading: buildBackButton(),
  152. actionsIconTheme: const IconThemeData(
  153. size: iconSize,
  154. ),
  155. actions: [
  156. if (asset.isRemote && isOwner) buildFavoriteButton(a),
  157. if (asset.livePhotoVideoId != null) buildLivePhotoButton(),
  158. if (asset.isLocal && !asset.isRemote) buildUploadButton(),
  159. if (asset.isRemote && !asset.isLocal && isOwner) buildDownloadButton(),
  160. if (asset.isRemote && isOwner) buildAddToAlbumButtom(),
  161. if (shareAlbumId != null) buildActivitiesButton(),
  162. buildMoreInfoButton(),
  163. ],
  164. );
  165. }
  166. }