2022-04-23 19:08:45 -07:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-07-07 11:40:54 -07:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-04-23 19:08:45 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/ui/draggable_scrollbar.dart';
|
|
|
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
2022-08-02 22:04:34 -07:00
|
|
|
import 'package:immich_mobile/modules/album/models/asset_selection_page_result.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/providers/asset_selection.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/providers/shared_album.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/services/album.service.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/album_action_outlined_button.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/album_viewer_appbar.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/album_viewer_editable_title.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/album_viewer_thumbnail.dart';
|
2022-04-23 19:08:45 -07:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_sliver_persistent_app_bar_delegate.dart';
|
|
|
|
import 'package:immich_mobile/shared/views/immich_loading_overlay.dart';
|
2022-07-13 05:23:48 -07:00
|
|
|
import 'package:openapi/api.dart';
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
class AlbumViewerPage extends HookConsumerWidget {
|
|
|
|
final String albumId;
|
|
|
|
|
|
|
|
const AlbumViewerPage({Key? key, required this.albumId}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-04-28 21:46:37 -07:00
|
|
|
FocusNode titleFocusNode = useFocusNode();
|
2022-06-21 22:23:35 -07:00
|
|
|
ScrollController scrollController = useScrollController();
|
2022-08-03 13:36:12 -07:00
|
|
|
var albumInfo = ref.watch(sharedAlbumDetailProvider(albumId));
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
final userId = ref.watch(authenticationProvider).userId;
|
|
|
|
|
|
|
|
/// Find out if the assets in album exist on the device
|
|
|
|
/// If they exist, add to selected asset state to show they are already selected.
|
2022-07-13 05:23:48 -07:00
|
|
|
void _onAddPhotosPressed(AlbumResponseDto albumInfo) async {
|
|
|
|
if (albumInfo.assets.isNotEmpty == true) {
|
2022-04-23 19:08:45 -07:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
2022-07-13 05:23:48 -07:00
|
|
|
.addNewAssets(albumInfo.assets.toList());
|
2022-04-23 19:08:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ref.watch(assetSelectionProvider.notifier).setIsAlbumExist(true);
|
|
|
|
|
2022-06-21 22:23:35 -07:00
|
|
|
AssetSelectionPageResult? returnPayload = await AutoRouter.of(context)
|
|
|
|
.push<AssetSelectionPageResult?>(const AssetSelectionRoute());
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
if (returnPayload != null) {
|
|
|
|
// Check if there is new assets add
|
|
|
|
if (returnPayload.selectedAdditionalAsset.isNotEmpty) {
|
|
|
|
ImmichLoadingOverlayController.appLoader.show();
|
|
|
|
|
2022-08-02 22:04:34 -07:00
|
|
|
var isSuccess =
|
|
|
|
await ref.watch(albumServiceProvider).addAdditionalAssetToAlbum(
|
|
|
|
returnPayload.selectedAdditionalAsset,
|
|
|
|
albumId,
|
|
|
|
);
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
if (isSuccess) {
|
|
|
|
ref.refresh(sharedAlbumDetailProvider(albumId));
|
|
|
|
}
|
|
|
|
|
|
|
|
ImmichLoadingOverlayController.appLoader.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
ref.watch(assetSelectionProvider.notifier).removeAll();
|
|
|
|
} else {
|
|
|
|
ref.watch(assetSelectionProvider.notifier).removeAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 05:23:48 -07:00
|
|
|
void _onAddUsersPressed(AlbumResponseDto albumInfo) async {
|
|
|
|
List<String>? sharedUserIds =
|
|
|
|
await AutoRouter.of(context).push<List<String>?>(
|
|
|
|
SelectAdditionalUserForSharingRoute(albumInfo: albumInfo),
|
|
|
|
);
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
if (sharedUserIds != null) {
|
|
|
|
ImmichLoadingOverlayController.appLoader.show();
|
|
|
|
|
2022-06-25 11:46:51 -07:00
|
|
|
var isSuccess = await ref
|
2022-08-02 22:04:34 -07:00
|
|
|
.watch(albumServiceProvider)
|
2022-06-21 22:23:35 -07:00
|
|
|
.addAdditionalUserToAlbum(sharedUserIds, albumId);
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
if (isSuccess) {
|
|
|
|
ref.refresh(sharedAlbumDetailProvider(albumId));
|
|
|
|
}
|
|
|
|
|
|
|
|
ImmichLoadingOverlayController.appLoader.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 05:23:48 -07:00
|
|
|
Widget _buildTitle(AlbumResponseDto albumInfo) {
|
2022-04-23 19:08:45 -07:00
|
|
|
return Padding(
|
2022-04-28 21:46:37 -07:00
|
|
|
padding: const EdgeInsets.only(left: 8, right: 8, top: 16),
|
|
|
|
child: userId == albumInfo.ownerId
|
|
|
|
? AlbumViewerEditableTitle(
|
|
|
|
albumInfo: albumInfo,
|
|
|
|
titleFocusNode: titleFocusNode,
|
|
|
|
)
|
|
|
|
: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 8.0),
|
2022-07-13 05:23:48 -07:00
|
|
|
child: Text(
|
|
|
|
albumInfo.albumName,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 24,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
2022-04-28 21:46:37 -07:00
|
|
|
),
|
2022-04-23 19:08:45 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-13 05:23:48 -07:00
|
|
|
Widget _buildAlbumDateRange(AlbumResponseDto albumInfo) {
|
2022-06-30 18:08:49 -07:00
|
|
|
String startDate = "";
|
|
|
|
DateTime parsedStartDate =
|
2022-07-13 05:23:48 -07:00
|
|
|
DateTime.parse(albumInfo.assets.first.createdAt);
|
2022-06-30 18:08:49 -07:00
|
|
|
DateTime parsedEndDate = DateTime.parse(
|
2022-07-13 05:23:48 -07:00
|
|
|
albumInfo.assets.last.createdAt,
|
|
|
|
); //Need default.
|
2022-06-30 18:08:49 -07:00
|
|
|
|
|
|
|
if (parsedStartDate.year == parsedEndDate.year) {
|
|
|
|
startDate = DateFormat('LLL d').format(parsedStartDate);
|
2022-04-23 19:08:45 -07:00
|
|
|
} else {
|
2022-06-30 18:08:49 -07:00
|
|
|
startDate = DateFormat('LLL d, y').format(parsedStartDate);
|
2022-04-23 19:08:45 -07:00
|
|
|
}
|
2022-06-30 18:08:49 -07:00
|
|
|
|
|
|
|
String endDate = DateFormat('LLL d, y').format(parsedEndDate);
|
|
|
|
|
|
|
|
return Padding(
|
2022-08-02 22:04:34 -07:00
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: 16.0,
|
|
|
|
top: 8.0,
|
|
|
|
bottom: albumInfo.shared ? 0.0 : 8.0,
|
|
|
|
),
|
2022-06-30 18:08:49 -07:00
|
|
|
child: Text(
|
|
|
|
"$startDate-$endDate",
|
|
|
|
style: const TextStyle(
|
2022-07-13 05:23:48 -07:00
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
2022-06-30 18:08:49 -07:00
|
|
|
),
|
|
|
|
);
|
2022-04-23 19:08:45 -07:00
|
|
|
}
|
|
|
|
|
2022-07-13 05:23:48 -07:00
|
|
|
Widget _buildHeader(AlbumResponseDto albumInfo) {
|
2022-04-23 19:08:45 -07:00
|
|
|
return SliverToBoxAdapter(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-04-28 21:46:37 -07:00
|
|
|
_buildTitle(albumInfo),
|
2022-07-13 05:23:48 -07:00
|
|
|
if (albumInfo.assets.isNotEmpty == true)
|
2022-06-30 18:08:49 -07:00
|
|
|
_buildAlbumDateRange(albumInfo),
|
2022-08-02 22:04:34 -07:00
|
|
|
if (albumInfo.shared)
|
|
|
|
SizedBox(
|
|
|
|
height: 60,
|
|
|
|
child: ListView.builder(
|
|
|
|
padding: const EdgeInsets.only(left: 16),
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
itemBuilder: ((context, index) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: CircleAvatar(
|
|
|
|
backgroundColor: Colors.grey[300],
|
|
|
|
radius: 18,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(2.0),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(50.0),
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/immich-logo-no-outline.png',
|
|
|
|
),
|
|
|
|
),
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
|
|
|
),
|
2022-08-02 22:04:34 -07:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
itemCount: albumInfo.sharedUsers.length,
|
|
|
|
),
|
|
|
|
)
|
2022-04-23 19:08:45 -07:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-13 05:23:48 -07:00
|
|
|
Widget _buildImageGrid(AlbumResponseDto albumInfo) {
|
|
|
|
if (albumInfo.assets.isNotEmpty) {
|
2022-04-23 19:08:45 -07:00
|
|
|
return SliverPadding(
|
|
|
|
padding: const EdgeInsets.only(top: 10.0),
|
|
|
|
sliver: SliverGrid(
|
|
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
|
|
crossAxisCount: 3,
|
|
|
|
crossAxisSpacing: 5.0,
|
|
|
|
mainAxisSpacing: 5,
|
|
|
|
),
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
(BuildContext context, int index) {
|
2022-08-03 13:36:12 -07:00
|
|
|
return AlbumViewerThumbnail(
|
|
|
|
asset: albumInfo.assets[index],
|
|
|
|
assetList: albumInfo.assets,
|
|
|
|
);
|
2022-04-23 19:08:45 -07:00
|
|
|
},
|
2022-08-10 20:48:25 -07:00
|
|
|
childCount: albumInfo.assetCount,
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return const SliverToBoxAdapter();
|
|
|
|
}
|
|
|
|
|
2022-07-13 05:23:48 -07:00
|
|
|
Widget _buildControlButton(AlbumResponseDto albumInfo) {
|
2022-04-23 19:08:45 -07:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16.0, top: 8, bottom: 8),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 40,
|
|
|
|
child: ListView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
children: [
|
|
|
|
AlbumActionOutlinedButton(
|
|
|
|
iconData: Icons.add_photo_alternate_outlined,
|
|
|
|
onPressed: () => _onAddPhotosPressed(albumInfo),
|
2022-07-07 11:40:54 -07:00
|
|
|
labelText: "share_add_photos".tr(),
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
2022-06-30 18:08:49 -07:00
|
|
|
if (userId == albumInfo.ownerId)
|
|
|
|
AlbumActionOutlinedButton(
|
|
|
|
iconData: Icons.person_add_alt_rounded,
|
|
|
|
onPressed: () => _onAddUsersPressed(albumInfo),
|
2022-07-07 11:40:54 -07:00
|
|
|
labelText: "album_viewer_page_share_add_users".tr(),
|
2022-06-30 18:08:49 -07:00
|
|
|
),
|
2022-04-23 19:08:45 -07:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-13 05:23:48 -07:00
|
|
|
Widget _buildBody(AlbumResponseDto albumInfo) {
|
2022-04-28 21:46:37 -07:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
titleFocusNode.unfocus();
|
|
|
|
},
|
2022-04-30 15:03:45 -07:00
|
|
|
child: DraggableScrollbar.semicircle(
|
2022-08-15 16:53:30 -07:00
|
|
|
backgroundColor: Theme.of(context).hintColor,
|
2022-06-21 22:23:35 -07:00
|
|
|
controller: scrollController,
|
2022-04-30 15:03:45 -07:00
|
|
|
heightScrollThumb: 48.0,
|
|
|
|
child: CustomScrollView(
|
2022-06-21 22:23:35 -07:00
|
|
|
controller: scrollController,
|
2022-04-30 15:03:45 -07:00
|
|
|
slivers: [
|
|
|
|
_buildHeader(albumInfo),
|
|
|
|
SliverPersistentHeader(
|
|
|
|
pinned: true,
|
|
|
|
delegate: ImmichSliverPersistentAppBarDelegate(
|
|
|
|
minHeight: 50,
|
|
|
|
maxHeight: 50,
|
|
|
|
child: Container(
|
2022-08-15 16:53:30 -07:00
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
2022-04-30 15:03:45 -07:00
|
|
|
child: _buildControlButton(albumInfo),
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
|
|
|
),
|
2022-04-30 15:03:45 -07:00
|
|
|
),
|
|
|
|
_buildImageGrid(albumInfo)
|
|
|
|
],
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
2022-04-30 15:03:45 -07:00
|
|
|
),
|
2022-04-28 21:46:37 -07:00
|
|
|
);
|
2022-04-23 19:08:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
2022-08-02 22:04:34 -07:00
|
|
|
appBar: albumInfo.when(
|
|
|
|
data: (AlbumResponseDto? data) {
|
|
|
|
if (data != null) {
|
|
|
|
return AlbumViewerAppbar(
|
|
|
|
albumInfo: data,
|
|
|
|
userId: userId,
|
|
|
|
albumId: albumId,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
error: (e, _) => null,
|
|
|
|
loading: () => null,
|
2022-07-13 05:23:48 -07:00
|
|
|
),
|
2022-06-21 22:23:35 -07:00
|
|
|
body: albumInfo.when(
|
2022-07-13 05:23:48 -07:00
|
|
|
data: (albumInfo) => albumInfo != null
|
|
|
|
? _buildBody(albumInfo)
|
|
|
|
: const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
2022-04-23 19:08:45 -07:00
|
|
|
error: (e, _) => Center(child: Text("Error loading album info $e")),
|
|
|
|
loading: () => const Center(
|
|
|
|
child: ImmichLoadingIndicator(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|