2022-08-03 07:04:34 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2023-02-05 05:25:11 +02:00
|
|
|
import 'package:collection/collection.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';
|
|
|
|
import 'package:immich_mobile/modules/album/providers/album.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/album/ui/album_thumbnail_card.dart';
|
|
|
|
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:54:31 +02:00
|
|
|
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
|
|
|
|
class LibraryPage extends HookConsumerWidget {
|
|
|
|
const LibraryPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final albums = ref.watch(albumProvider);
|
2023-02-11 22:23:32 +02:00
|
|
|
var isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
2023-03-19 21:54:31 +02:00
|
|
|
var settings = ref.watch(appSettingsServiceProvider);
|
2022-08-03 07:04:34 +02:00
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
ref.read(albumProvider.notifier).getAllAlbums();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
|
2023-02-05 05:25:11 +02:00
|
|
|
AppBar buildAppBar() {
|
|
|
|
return AppBar(
|
2022-08-03 07:04:34 +02:00
|
|
|
centerTitle: true,
|
|
|
|
automaticallyImplyLeading: false,
|
2023-02-05 05:25:11 +02:00
|
|
|
title: const Text(
|
2022-08-03 07:04:34 +02:00
|
|
|
'IMMICH',
|
|
|
|
style: TextStyle(
|
|
|
|
fontFamily: 'SnowburstOne',
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 22,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-04-17 07:02:07 +02:00
|
|
|
final selectedAlbumSortOrder =
|
|
|
|
useState(settings.getSetting(AppSettingsEnum.selectedAlbumSortOrder));
|
2023-02-05 05:25:11 +02:00
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
List<Album> sortedAlbums() {
|
2023-10-12 20:18:54 +02:00
|
|
|
// Created.
|
2023-02-05 05:25:11 +02:00
|
|
|
if (selectedAlbumSortOrder.value == 0) {
|
2023-03-04 00:38:30 +02:00
|
|
|
return albums
|
|
|
|
.where((a) => a.isRemote)
|
|
|
|
.sortedBy((album) => album.createdAt)
|
|
|
|
.reversed
|
|
|
|
.toList();
|
2023-02-05 05:25:11 +02:00
|
|
|
}
|
2023-10-12 20:18:54 +02:00
|
|
|
// Album title.
|
|
|
|
if (selectedAlbumSortOrder.value == 1) {
|
|
|
|
return albums.where((a) => a.isRemote).sortedBy((album) => album.name);
|
|
|
|
}
|
|
|
|
// Most recent photo, if unset (e.g. empty album, use modifiedAt / updatedAt).
|
|
|
|
if (selectedAlbumSortOrder.value == 2) {
|
|
|
|
return albums
|
|
|
|
.where((a) => a.isRemote)
|
|
|
|
.sorted(
|
|
|
|
(a, b) => a.lastModifiedAssetTimestamp != null &&
|
|
|
|
b.lastModifiedAssetTimestamp != null
|
|
|
|
? a.lastModifiedAssetTimestamp!
|
|
|
|
.compareTo(b.lastModifiedAssetTimestamp!)
|
|
|
|
: a.modifiedAt.compareTo(b.modifiedAt),
|
|
|
|
)
|
|
|
|
.reversed
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
// Last modified.
|
|
|
|
if (selectedAlbumSortOrder.value == 3) {
|
|
|
|
return albums
|
|
|
|
.where((a) => a.isRemote)
|
|
|
|
.sortedBy((album) => album.modifiedAt)
|
|
|
|
.reversed
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback: Album title.
|
2023-03-04 00:38:30 +02:00
|
|
|
return albums.where((a) => a.isRemote).sortedBy((album) => album.name);
|
2023-02-05 05:25:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildSortButton() {
|
|
|
|
final options = [
|
|
|
|
"library_page_sort_created".tr(),
|
2023-08-19 00:52:40 +02:00
|
|
|
"library_page_sort_title".tr(),
|
2023-10-12 20:18:54 +02:00
|
|
|
"library_page_sort_most_recent_photo".tr(),
|
|
|
|
"library_page_sort_last_modified".tr(),
|
2023-02-05 05:25:11 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return PopupMenuButton(
|
|
|
|
position: PopupMenuPosition.over,
|
|
|
|
itemBuilder: (BuildContext context) {
|
|
|
|
return options.mapIndexed<PopupMenuEntry<int>>((index, option) {
|
|
|
|
final selected = selectedAlbumSortOrder.value == index;
|
|
|
|
return PopupMenuItem(
|
|
|
|
value: index,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 12.0),
|
|
|
|
child: Icon(
|
|
|
|
Icons.check,
|
|
|
|
color: selected
|
|
|
|
? Theme.of(context).primaryColor
|
|
|
|
: Colors.transparent,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
option,
|
|
|
|
style: TextStyle(
|
|
|
|
color: selected ? Theme.of(context).primaryColor : null,
|
|
|
|
fontSize: 12.0,
|
|
|
|
),
|
2023-08-19 00:52:40 +02:00
|
|
|
),
|
2023-02-05 05:25:11 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList();
|
|
|
|
},
|
|
|
|
onSelected: (int value) {
|
|
|
|
selectedAlbumSortOrder.value = value;
|
2023-03-19 21:54:31 +02:00
|
|
|
settings.setSetting(AppSettingsEnum.selectedAlbumSortOrder, value);
|
2023-02-05 05:25:11 +02:00
|
|
|
},
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.swap_vert_rounded,
|
|
|
|
size: 18,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
options[selectedAlbumSortOrder.value],
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontSize: 12.0,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-26 16:40:19 +02:00
|
|
|
Widget buildCreateAlbumButton() {
|
2022-08-03 07:04:34 +02:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
AutoRouter.of(context).push(CreateAlbumRoute(isSharedAlbum: false));
|
|
|
|
},
|
2023-02-08 21:42:45 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 32),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
2023-02-11 22:23:32 +02:00
|
|
|
color: isDarkMode
|
|
|
|
? const Color.fromARGB(255, 53, 53, 53)
|
|
|
|
: const Color.fromARGB(255, 203, 203, 203),
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
color: isDarkMode ? Colors.grey[900] : Colors.grey[50],
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
|
|
|
child: Center(
|
|
|
|
child: Icon(
|
|
|
|
Icons.add_rounded,
|
|
|
|
size: 28,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
),
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 8.0,
|
|
|
|
bottom: 16,
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
child: const Text(
|
|
|
|
'library_page_new_album',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
).tr(),
|
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-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(
|
|
|
|
fontWeight: FontWeight.bold,
|
2023-04-17 07:02:07 +02:00
|
|
|
fontSize: 13.0,
|
|
|
|
color: isDarkMode ? Colors.white : Colors.grey[800],
|
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-02-11 22:23:32 +02:00
|
|
|
backgroundColor: isDarkMode ? Colors.grey[900] : Colors.grey[50],
|
2023-02-05 05:25:11 +02:00
|
|
|
side: BorderSide(
|
2023-02-11 22:23:32 +02:00
|
|
|
color: isDarkMode ? 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,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
2023-02-05 05:25:11 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-08 21:42:45 +02:00
|
|
|
final sorted = sortedAlbums();
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
final local = albums.where((a) => a.isLocal).toList();
|
|
|
|
|
2022-08-03 07:04:34 +02:00
|
|
|
return Scaffold(
|
2023-02-05 05:25:11 +02:00
|
|
|
appBar: buildAppBar(),
|
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, () {
|
2023-02-05 05:25:11 +02:00
|
|
|
AutoRouter.of(context).navigate(const FavoritesRoute());
|
|
|
|
}),
|
|
|
|
const SizedBox(width: 12.0),
|
|
|
|
buildLibraryNavButton(
|
2023-04-17 07:02:07 +02:00
|
|
|
"library_page_archive".tr(), Icons.archive_outlined, () {
|
|
|
|
AutoRouter.of(context).navigate(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: [
|
|
|
|
const Text(
|
|
|
|
'library_page_albums',
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
).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],
|
|
|
|
onTap: () => AutoRouter.of(context).push(
|
|
|
|
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: [
|
|
|
|
const Text(
|
|
|
|
'library_page_device_albums',
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
).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],
|
|
|
|
onTap: () => AutoRouter.of(context).push(
|
|
|
|
AlbumViewerRoute(
|
|
|
|
albumId: local[index].id,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-08-03 07:04:34 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|