2024-01-05 07:20:55 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-08-08 15:11:56 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/album.provider.dart';
|
2023-12-07 20:14:09 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/album_sort_by_options.provider.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/ui/album_thumbnail_card.dart';
|
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2023-10-30 19:17:34 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_app_bar.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
|
2024-01-15 18:50:33 +02:00
|
|
|
@RoutePage()
|
2022-08-03 07:04:34 +02:00
|
|
|
class LibraryPage extends HookConsumerWidget {
|
2024-01-27 18:14:32 +02:00
|
|
|
const LibraryPage({super.key});
|
2022-08-03 07:04:34 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-10-30 19:17:34 +02:00
|
|
|
final trashEnabled =
|
|
|
|
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));
|
2022-08-03 07:04:34 +02:00
|
|
|
final albums = ref.watch(albumProvider);
|
2023-12-07 20:14:09 +02:00
|
|
|
final isDarkTheme = context.isDarkTheme;
|
|
|
|
final albumSortOption = ref.watch(albumSortByOptionsProvider);
|
|
|
|
final albumSortIsReverse = ref.watch(albumSortOrderProvider);
|
2022-08-03 07:04:34 +02:00
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
ref.read(albumProvider.notifier).getAllAlbums();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
|
2023-02-05 05:25:11 +02:00
|
|
|
Widget buildSortButton() {
|
|
|
|
return PopupMenuButton(
|
|
|
|
position: PopupMenuPosition.over,
|
|
|
|
itemBuilder: (BuildContext context) {
|
2023-12-07 20:14:09 +02:00
|
|
|
return AlbumSortMode.values
|
|
|
|
.map<PopupMenuEntry<AlbumSortMode>>((option) {
|
|
|
|
final selected = albumSortOption == option;
|
2023-02-05 05:25:11 +02:00
|
|
|
return PopupMenuItem(
|
2023-12-07 20:14:09 +02:00
|
|
|
value: option,
|
2023-02-05 05:25:11 +02:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 12.0),
|
|
|
|
child: Icon(
|
|
|
|
Icons.check,
|
2023-11-09 18:19:53 +02:00
|
|
|
color:
|
|
|
|
selected ? context.primaryColor : Colors.transparent,
|
2023-02-05 05:25:11 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
2023-12-07 20:14:09 +02:00
|
|
|
option.label.tr(),
|
2023-02-05 05:25:11 +02:00
|
|
|
style: TextStyle(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: selected ? context.primaryColor : null,
|
2023-12-07 20:14:09 +02:00
|
|
|
fontSize: 14.0,
|
2023-02-05 05:25:11 +02:00
|
|
|
),
|
2023-08-19 00:52:40 +02:00
|
|
|
),
|
2023-02-05 05:25:11 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList();
|
|
|
|
},
|
2023-12-07 20:14:09 +02:00
|
|
|
onSelected: (AlbumSortMode value) {
|
|
|
|
final selected = albumSortOption == value;
|
|
|
|
// Switch direction
|
|
|
|
if (selected) {
|
|
|
|
ref
|
|
|
|
.read(albumSortOrderProvider.notifier)
|
|
|
|
.changeSortDirection(!albumSortIsReverse);
|
|
|
|
} else {
|
|
|
|
ref.read(albumSortByOptionsProvider.notifier).changeSortMode(value);
|
|
|
|
}
|
2023-02-05 05:25:11 +02:00
|
|
|
},
|
|
|
|
child: Row(
|
|
|
|
children: [
|
2023-12-07 20:14:09 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 5),
|
|
|
|
child: Icon(
|
|
|
|
albumSortIsReverse
|
|
|
|
? Icons.arrow_downward_rounded
|
|
|
|
: Icons.arrow_upward_rounded,
|
|
|
|
size: 14,
|
|
|
|
color: context.primaryColor,
|
|
|
|
),
|
2023-02-05 05:25:11 +02:00
|
|
|
),
|
|
|
|
Text(
|
2023-12-07 20:14:09 +02:00
|
|
|
albumSortOption.label.tr(),
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.labelLarge?.copyWith(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-02-05 05:25:11 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-26 16:40:19 +02:00
|
|
|
Widget buildCreateAlbumButton() {
|
2023-12-04 21:26:17 +02:00
|
|
|
return LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
var cardSize = constraints.maxWidth;
|
|
|
|
|
|
|
|
return GestureDetector(
|
2023-12-07 20:14:09 +02:00
|
|
|
onTap: () =>
|
2024-01-05 07:20:55 +02:00
|
|
|
context.pushRoute(CreateAlbumRoute(isSharedAlbum: false)),
|
2023-12-04 21:26:17 +02:00
|
|
|
child: Padding(
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.only(bottom: 32), // Adjust padding to suit
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: cardSize,
|
|
|
|
height: cardSize,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: isDarkTheme
|
|
|
|
? const Color.fromARGB(255, 53, 53, 53)
|
|
|
|
: const Color.fromARGB(255, 203, 203, 203),
|
|
|
|
),
|
|
|
|
color: isDarkTheme ? Colors.grey[900] : Colors.grey[50],
|
2023-12-07 20:14:09 +02:00
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
2023-12-04 21:26:17 +02:00
|
|
|
),
|
|
|
|
child: Center(
|
|
|
|
child: Icon(
|
|
|
|
Icons.add_rounded,
|
|
|
|
size: 28,
|
|
|
|
color: context.primaryColor,
|
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
|
|
|
),
|
2023-12-04 21:26:17 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 8.0,
|
|
|
|
bottom: 16,
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
2023-12-04 21:26:17 +02:00
|
|
|
child: Text(
|
|
|
|
'library_page_new_album',
|
|
|
|
style: context.textTheme.labelLarge,
|
|
|
|
).tr(),
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
2023-12-04 21:26:17 +02:00
|
|
|
],
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
2023-12-04 21:26:17 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2022-08-03 07:04:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-05 05:25:11 +02:00
|
|
|
Widget buildLibraryNavButton(
|
|
|
|
String label,
|
|
|
|
IconData icon,
|
|
|
|
Function() onClick,
|
|
|
|
) {
|
|
|
|
return Expanded(
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
onPressed: onClick,
|
|
|
|
label: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
|
|
child: Text(
|
|
|
|
label,
|
|
|
|
style: TextStyle(
|
2023-11-20 16:58:03 +02:00
|
|
|
color: context.isDarkTheme
|
|
|
|
? Colors.white
|
|
|
|
: Colors.black.withAlpha(200),
|
2023-02-05 05:25:11 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
style: OutlinedButton.styleFrom(
|
2023-04-17 07:02:07 +02:00
|
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
2023-11-09 18:19:53 +02:00
|
|
|
backgroundColor: isDarkTheme ? Colors.grey[900] : Colors.grey[50],
|
2023-02-05 05:25:11 +02:00
|
|
|
side: BorderSide(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: isDarkTheme ? Colors.grey[800]! : Colors.grey[300]!,
|
2023-02-05 05:25:11 +02:00
|
|
|
),
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
icon: Icon(
|
|
|
|
icon,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-02-11 22:23:32 +02:00
|
|
|
),
|
2023-02-05 05:25:11 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-12-07 20:14:09 +02:00
|
|
|
final remote = albums.where((a) => a.isRemote).toList();
|
|
|
|
final sorted = albumSortOption.sortFn(remote, albumSortIsReverse);
|
2023-03-04 00:38:30 +02:00
|
|
|
final local = albums.where((a) => a.isLocal).toList();
|
|
|
|
|
2023-10-30 19:17:34 +02:00
|
|
|
Widget? shareTrashButton() {
|
|
|
|
return trashEnabled
|
|
|
|
? InkWell(
|
2024-01-05 07:20:55 +02:00
|
|
|
onTap: () => context.pushRoute(const TrashRoute()),
|
2023-12-07 20:14:09 +02:00
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
2024-03-12 17:12:11 +02:00
|
|
|
child: Icon(
|
2023-10-30 19:17:34 +02:00
|
|
|
Icons.delete_rounded,
|
|
|
|
size: 25,
|
2024-03-12 17:12:11 +02:00
|
|
|
semanticLabel: 'profile_drawer_trash'.tr(),
|
2023-10-30 19:17:34 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
: null;
|
|
|
|
}
|
|
|
|
|
2022-08-03 07:04:34 +02:00
|
|
|
return Scaffold(
|
2023-10-30 19:17:34 +02:00
|
|
|
appBar: ImmichAppBar(
|
|
|
|
action: shareTrashButton(),
|
|
|
|
),
|
2022-08-03 07:04:34 +02:00
|
|
|
body: CustomScrollView(
|
|
|
|
slivers: [
|
2022-08-08 15:11:56 +02:00
|
|
|
SliverToBoxAdapter(
|
2022-08-03 07:04:34 +02:00
|
|
|
child: Padding(
|
2023-02-05 05:25:11 +02:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 12.0,
|
|
|
|
right: 12.0,
|
|
|
|
top: 24.0,
|
|
|
|
bottom: 12.0,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: [
|
|
|
|
buildLibraryNavButton(
|
2023-05-08 21:01:39 +02:00
|
|
|
"library_page_favorites".tr(), Icons.favorite_border, () {
|
2024-01-05 07:20:55 +02:00
|
|
|
context.navigateTo(const FavoritesRoute());
|
2023-02-05 05:25:11 +02:00
|
|
|
}),
|
|
|
|
const SizedBox(width: 12.0),
|
|
|
|
buildLibraryNavButton(
|
2023-04-17 07:02:07 +02:00
|
|
|
"library_page_archive".tr(), Icons.archive_outlined, () {
|
2024-01-05 07:20:55 +02:00
|
|
|
context.navigateTo(const ArchiveRoute());
|
2023-02-05 05:25:11 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 12.0,
|
|
|
|
left: 12.0,
|
|
|
|
right: 12.0,
|
|
|
|
bottom: 20.0,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2023-11-20 16:58:03 +02:00
|
|
|
Text(
|
2023-02-05 05:25:11 +02:00
|
|
|
'library_page_albums',
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.bodyLarge?.copyWith(
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
2023-02-05 05:25:11 +02:00
|
|
|
).tr(),
|
|
|
|
buildSortButton(),
|
|
|
|
],
|
|
|
|
),
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
SliverPadding(
|
2023-02-08 21:42:45 +02:00
|
|
|
padding: const EdgeInsets.all(12.0),
|
|
|
|
sliver: SliverGrid(
|
|
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
maxCrossAxisExtent: 250,
|
|
|
|
mainAxisSpacing: 12,
|
|
|
|
crossAxisSpacing: 12,
|
|
|
|
childAspectRatio: .7,
|
|
|
|
),
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
childCount: sorted.length + 1,
|
|
|
|
(context, index) {
|
2023-02-11 22:23:32 +02:00
|
|
|
if (index == 0) {
|
2023-02-08 21:42:45 +02:00
|
|
|
return buildCreateAlbumButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
return AlbumThumbnailCard(
|
|
|
|
album: sorted[index - 1],
|
2024-01-05 07:20:55 +02:00
|
|
|
onTap: () => context.pushRoute(
|
2023-02-08 21:42:45 +02:00
|
|
|
AlbumViewerRoute(
|
|
|
|
albumId: sorted[index - 1].id,
|
|
|
|
),
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
);
|
|
|
|
},
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
2023-03-04 00:38:30 +02:00
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 12.0,
|
|
|
|
left: 12.0,
|
|
|
|
right: 12.0,
|
|
|
|
bottom: 20.0,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2023-11-20 16:58:03 +02:00
|
|
|
Text(
|
2023-03-04 00:38:30 +02:00
|
|
|
'library_page_device_albums',
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.bodyLarge?.copyWith(
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
2023-03-04 00:38:30 +02:00
|
|
|
).tr(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SliverPadding(
|
|
|
|
padding: const EdgeInsets.all(12.0),
|
|
|
|
sliver: SliverGrid(
|
|
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
maxCrossAxisExtent: 250,
|
|
|
|
mainAxisSpacing: 12,
|
|
|
|
crossAxisSpacing: 12,
|
|
|
|
childAspectRatio: .7,
|
|
|
|
),
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
childCount: local.length,
|
|
|
|
(context, index) => AlbumThumbnailCard(
|
|
|
|
album: local[index],
|
2024-01-05 07:20:55 +02:00
|
|
|
onTap: () => context.pushRoute(
|
2023-03-04 00:38:30 +02:00
|
|
|
AlbumViewerRoute(
|
|
|
|
albumId: local[index].id,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-08-03 07:04:34 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|