2022-04-24 04:08:45 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/shared_album.provider.dart';
|
2023-03-19 21:47:51 +02:00
|
|
|
import 'package:immich_mobile/modules/album/ui/album_thumbnail_card.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/ui/sharing_sliver_appbar.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2023-02-06 09:13:32 +02:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
2023-03-19 21:47:51 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart' as store;
|
2023-03-04 00:38:30 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_image.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
class SharingPage extends HookConsumerWidget {
|
|
|
|
const SharingPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-02-06 09:13:32 +02:00
|
|
|
final List<Album> sharedAlbums = ref.watch(sharedAlbumProvider);
|
2023-03-27 04:35:52 +02:00
|
|
|
final userId = store.Store.get(store.StoreKey.currentUser).id;
|
2023-03-19 21:47:51 +02:00
|
|
|
var isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
ref.read(sharedAlbumProvider.notifier).getAllSharedAlbums();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2023-03-19 21:47:51 +02:00
|
|
|
buildAlbumGrid() {
|
|
|
|
return SliverPadding(
|
|
|
|
padding: const EdgeInsets.all(18.0),
|
|
|
|
sliver: SliverGrid(
|
|
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
maxCrossAxisExtent: 250,
|
|
|
|
mainAxisSpacing: 12,
|
|
|
|
crossAxisSpacing: 12,
|
|
|
|
childAspectRatio: .7,
|
|
|
|
),
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
(context, index) {
|
|
|
|
return AlbumThumbnailCard(
|
|
|
|
album: sharedAlbums[index],
|
|
|
|
showOwner: true,
|
|
|
|
onTap: () {
|
|
|
|
AutoRouter.of(context)
|
|
|
|
.push(AlbumViewerRoute(albumId: sharedAlbums[index].id));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
childCount: sharedAlbums.length,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildAlbumList() {
|
2022-04-24 04:08:45 +02:00
|
|
|
return SliverList(
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
(BuildContext context, int index) {
|
2022-08-21 18:41:36 +02:00
|
|
|
final album = sharedAlbums[index];
|
2023-03-19 21:47:51 +02:00
|
|
|
final isOwner = album.ownerId == userId;
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
return ListTile(
|
2022-06-25 22:12:47 +02:00
|
|
|
contentPadding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
|
2022-04-24 04:08:45 +02:00
|
|
|
leading: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
2023-03-04 00:38:30 +02:00
|
|
|
child: ImmichImage(
|
|
|
|
album.thumbnail.value,
|
2022-04-24 04:08:45 +02:00
|
|
|
width: 60,
|
|
|
|
height: 60,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
title: Text(
|
2023-03-19 21:47:51 +02:00
|
|
|
album.name,
|
2022-04-24 04:08:45 +02:00
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
2022-08-16 01:53:30 +02:00
|
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
|
|
fontWeight: FontWeight.bold,
|
2023-03-19 21:47:51 +02:00
|
|
|
color: isDarkMode
|
|
|
|
? Theme.of(context).primaryColor
|
|
|
|
: Colors.black,
|
2022-08-16 01:53:30 +02:00
|
|
|
),
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
2023-03-19 21:47:51 +02:00
|
|
|
subtitle: isOwner
|
|
|
|
? const Text(
|
|
|
|
'Owned',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12.0,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: album.ownerName != null
|
|
|
|
? Text(
|
|
|
|
'Shared by ${album.ownerName!}',
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 12.0,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
2022-04-24 04:08:45 +02:00
|
|
|
onTap: () {
|
2022-06-25 22:12:47 +02:00
|
|
|
AutoRouter.of(context)
|
|
|
|
.push(AlbumViewerRoute(albumId: sharedAlbums[index].id));
|
2022-04-24 04:08:45 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
childCount: sharedAlbums.length,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildEmptyListIndication() {
|
2022-04-24 04:08:45 +02:00
|
|
|
return SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Card(
|
|
|
|
elevation: 0,
|
|
|
|
shape: RoundedRectangleBorder(
|
2023-02-11 22:23:32 +02:00
|
|
|
borderRadius: BorderRadius.circular(20),
|
2022-04-24 04:08:45 +02:00
|
|
|
side: const BorderSide(
|
2022-08-16 01:53:30 +02:00
|
|
|
color: Colors.grey,
|
2023-02-11 22:23:32 +02:00
|
|
|
width: 0.5,
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
// color: Colors.transparent,
|
2022-04-24 04:08:45 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(18.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-09-06 16:37:04 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 5.0, bottom: 5),
|
2022-04-24 04:08:45 +02:00
|
|
|
child: Icon(
|
2023-02-11 22:23:32 +02:00
|
|
|
Icons.insert_photo_rounded,
|
2022-04-24 04:08:45 +02:00
|
|
|
size: 50,
|
2022-09-06 16:37:04 +02:00
|
|
|
color: Theme.of(context).primaryColor,
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
'sharing_page_empty_list',
|
2023-02-11 22:23:32 +02:00
|
|
|
style: Theme.of(context).textTheme.displaySmall,
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
'sharing_page_description',
|
2022-08-16 01:53:30 +02:00
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
body: CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
const SharingSliverAppBar(),
|
2022-07-07 20:40:54 +02:00
|
|
|
SliverPadding(
|
2022-07-13 14:23:48 +02:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
2022-04-24 04:08:45 +02:00
|
|
|
sliver: SliverToBoxAdapter(
|
2022-07-13 14:23:48 +02:00
|
|
|
child: const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"sharing_page_album",
|
2022-04-24 04:08:45 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-04-24 04:08:45 +02:00
|
|
|
),
|
|
|
|
),
|
2023-03-19 21:47:51 +02:00
|
|
|
SliverLayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
if (sharedAlbums.isEmpty) {
|
|
|
|
return buildEmptyListIndication();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (constraints.crossAxisExtent < 600) {
|
|
|
|
return buildAlbumList();
|
|
|
|
} else {
|
|
|
|
return buildAlbumGrid();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-04-24 04:08:45 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|