2024-01-05 00:20:55 -05:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-02-10 21:40:11 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2022-04-02 12:31:53 -05:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-05-02 15:59:14 -05:00
|
|
|
import 'package:immich_mobile/providers/activity_statistics.provider.dart';
|
|
|
|
import 'package:immich_mobile/providers/album/current_album.provider.dart';
|
2024-04-30 21:36:40 -05:00
|
|
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
2024-05-02 15:59:14 -05:00
|
|
|
import 'package:immich_mobile/providers/asset.provider.dart';
|
2022-02-10 21:40:11 -05:00
|
|
|
|
2023-02-03 11:26:05 -05:00
|
|
|
class TopControlAppBar extends HookConsumerWidget {
|
2022-07-13 07:23:48 -05:00
|
|
|
const TopControlAppBar({
|
2024-01-27 11:14:32 -05:00
|
|
|
super.key,
|
2022-07-13 07:23:48 -05:00
|
|
|
required this.asset,
|
|
|
|
required this.onMoreInfoPressed,
|
|
|
|
required this.onDownloadPressed,
|
2023-01-27 00:16:28 -05:00
|
|
|
required this.onAddToAlbumPressed,
|
2024-04-26 01:01:03 -05:00
|
|
|
required this.onRestorePressed,
|
2022-11-19 00:12:54 -05:00
|
|
|
required this.onToggleMotionVideo,
|
|
|
|
required this.isPlayingMotionVideo,
|
2023-02-04 22:25:11 -05:00
|
|
|
required this.onFavorite,
|
2023-08-05 21:40:50 -05:00
|
|
|
required this.onUploadPressed,
|
2023-10-28 14:48:30 -05:00
|
|
|
required this.isOwner,
|
2023-11-06 10:46:26 -05:00
|
|
|
required this.onActivitiesPressed,
|
2023-12-07 10:38:22 -05:00
|
|
|
required this.isPartner,
|
2024-01-27 11:14:32 -05:00
|
|
|
});
|
2022-02-10 21:40:11 -05:00
|
|
|
|
2022-11-08 12:00:24 -05:00
|
|
|
final Asset asset;
|
2022-02-10 21:40:11 -05:00
|
|
|
final Function onMoreInfoPressed;
|
2023-08-05 21:40:50 -05:00
|
|
|
final VoidCallback? onUploadPressed;
|
2022-11-08 12:00:24 -05:00
|
|
|
final VoidCallback? onDownloadPressed;
|
2022-11-19 00:12:54 -05:00
|
|
|
final VoidCallback onToggleMotionVideo;
|
2023-01-27 00:16:28 -05:00
|
|
|
final VoidCallback onAddToAlbumPressed;
|
2024-04-26 01:01:03 -05:00
|
|
|
final VoidCallback onRestorePressed;
|
2023-11-06 10:46:26 -05:00
|
|
|
final VoidCallback onActivitiesPressed;
|
2023-10-11 21:10:59 -05:00
|
|
|
final Function(Asset) onFavorite;
|
2022-11-19 00:12:54 -05:00
|
|
|
final bool isPlayingMotionVideo;
|
2023-10-28 14:48:30 -05:00
|
|
|
final bool isOwner;
|
2023-12-07 10:38:22 -05:00
|
|
|
final bool isPartner;
|
2022-04-02 12:31:53 -05:00
|
|
|
|
2022-02-10 21:40:11 -05:00
|
|
|
@override
|
2022-04-02 12:31:53 -05:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-04-18 11:23:56 -05:00
|
|
|
const double iconSize = 22.0;
|
2023-10-11 21:10:59 -05:00
|
|
|
final a = ref.watch(assetWatcher(asset)).value ?? asset;
|
2023-12-07 10:38:22 -05:00
|
|
|
final album = ref.watch(currentAlbumProvider);
|
2024-01-15 19:25:59 -05:00
|
|
|
final comments = album != null &&
|
|
|
|
album.remoteId != null &&
|
|
|
|
asset.remoteId != null
|
2024-01-05 00:20:55 -05:00
|
|
|
? ref.watch(activityStatisticsProvider(album.remoteId!, asset.remoteId))
|
2023-11-06 10:46:26 -05:00
|
|
|
: 0;
|
2022-02-10 21:40:11 -05:00
|
|
|
|
2023-10-11 21:10:59 -05:00
|
|
|
Widget buildFavoriteButton(a) {
|
2023-04-17 00:02:07 -05:00
|
|
|
return IconButton(
|
2023-10-11 21:10:59 -05:00
|
|
|
onPressed: () => onFavorite(a),
|
2023-04-17 00:02:07 -05:00
|
|
|
icon: Icon(
|
2023-10-11 21:10:59 -05:00
|
|
|
a.isFavorite ? Icons.favorite : Icons.favorite_border,
|
2023-04-17 00:02:07 -05:00
|
|
|
color: Colors.grey[200],
|
|
|
|
),
|
|
|
|
);
|
2023-02-04 22:25:11 -05:00
|
|
|
}
|
|
|
|
|
2023-08-05 21:40:50 -05:00
|
|
|
Widget buildLivePhotoButton() {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
onToggleMotionVideo();
|
|
|
|
},
|
|
|
|
icon: isPlayingMotionVideo
|
|
|
|
? Icon(
|
|
|
|
Icons.motion_photos_pause_outlined,
|
|
|
|
color: Colors.grey[200],
|
|
|
|
)
|
|
|
|
: Icon(
|
|
|
|
Icons.play_circle_outline_rounded,
|
|
|
|
color: Colors.grey[200],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildMoreInfoButton() {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
onMoreInfoPressed();
|
|
|
|
},
|
|
|
|
icon: Icon(
|
|
|
|
Icons.info_outline_rounded,
|
|
|
|
color: Colors.grey[200],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildDownloadButton() {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: onDownloadPressed,
|
|
|
|
icon: Icon(
|
|
|
|
Icons.cloud_download_outlined,
|
|
|
|
color: Colors.grey[200],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-26 01:01:03 -05:00
|
|
|
Widget buildAddToAlbumButton() {
|
2023-08-05 21:40:50 -05:00
|
|
|
return IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
onAddToAlbumPressed();
|
|
|
|
},
|
|
|
|
icon: Icon(
|
|
|
|
Icons.add,
|
|
|
|
color: Colors.grey[200],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-26 01:01:03 -05:00
|
|
|
Widget buildRestoreButton() {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
onRestorePressed();
|
|
|
|
},
|
|
|
|
icon: Icon(
|
|
|
|
Icons.history_rounded,
|
|
|
|
color: Colors.grey[200],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-06 10:46:26 -05:00
|
|
|
Widget buildActivitiesButton() {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
onActivitiesPressed();
|
|
|
|
},
|
|
|
|
icon: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.mode_comment_outlined,
|
|
|
|
color: Colors.grey[200],
|
|
|
|
),
|
|
|
|
if (comments != 0)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 5),
|
|
|
|
child: Text(
|
|
|
|
comments.toString(),
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.grey[200],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-05 21:40:50 -05:00
|
|
|
Widget buildUploadButton() {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: onUploadPressed,
|
|
|
|
icon: Icon(
|
|
|
|
Icons.backup_outlined,
|
|
|
|
color: Colors.grey[200],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildBackButton() {
|
|
|
|
return IconButton(
|
2022-02-10 21:40:11 -05:00
|
|
|
onPressed: () {
|
2024-01-05 00:20:55 -05:00
|
|
|
context.popRoute();
|
2022-02-10 21:40:11 -05:00
|
|
|
},
|
2022-09-06 09:37:04 -05:00
|
|
|
icon: Icon(
|
2022-02-10 21:40:11 -05:00
|
|
|
Icons.arrow_back_ios_new_rounded,
|
|
|
|
size: 20.0,
|
2022-09-06 09:37:04 -05:00
|
|
|
color: Colors.grey[200],
|
2022-02-10 21:40:11 -05:00
|
|
|
),
|
2023-08-05 21:40:50 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return AppBar(
|
|
|
|
foregroundColor: Colors.grey[100],
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
leading: buildBackButton(),
|
2023-02-10 17:11:09 -05:00
|
|
|
actionsIconTheme: const IconThemeData(
|
|
|
|
size: iconSize,
|
|
|
|
),
|
2022-02-10 21:40:11 -05:00
|
|
|
actions: [
|
2023-10-28 14:48:30 -05:00
|
|
|
if (asset.isRemote && isOwner) buildFavoriteButton(a),
|
2023-08-05 21:40:50 -05:00
|
|
|
if (asset.livePhotoVideoId != null) buildLivePhotoButton(),
|
|
|
|
if (asset.isLocal && !asset.isRemote) buildUploadButton(),
|
2024-01-05 22:02:16 -05:00
|
|
|
if (asset.isRemote && !asset.isLocal && !asset.isOffline && isOwner)
|
|
|
|
buildDownloadButton(),
|
2024-04-26 01:01:03 -05:00
|
|
|
if (asset.isRemote && (isOwner || isPartner) && !asset.isTrashed)
|
|
|
|
buildAddToAlbumButton(),
|
|
|
|
if (asset.isTrashed) buildRestoreButton(),
|
2023-12-07 10:38:22 -05:00
|
|
|
if (album != null && album.shared) buildActivitiesButton(),
|
2023-08-18 17:52:40 -05:00
|
|
|
buildMoreInfoButton(),
|
2022-02-10 21:40:11 -05:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|