2024-01-05 07:20:55 +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-05-06 14:22:23 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-16 01:53:30 +02:00
|
|
|
import 'package:immich_mobile/constants/immich_colors.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/backup/ui/album_info_card.dart';
|
2023-03-01 05:10:53 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/ui/album_info_list_tile.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
|
|
|
|
|
|
|
class BackupAlbumSelectionPage extends HookConsumerWidget {
|
|
|
|
const BackupAlbumSelectionPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-11-30 18:58:07 +02:00
|
|
|
// final availableAlbums = ref.watch(backupProvider).availableAlbums;
|
2022-05-06 14:22:23 +02:00
|
|
|
final selectedBackupAlbums = ref.watch(backupProvider).selectedBackupAlbums;
|
|
|
|
final excludedBackupAlbums = ref.watch(backupProvider).excludedBackupAlbums;
|
2023-11-09 18:19:53 +02:00
|
|
|
final isDarkTheme = context.isDarkTheme;
|
2023-12-13 05:06:04 +02:00
|
|
|
final albums = ref.watch(backupProvider).availableAlbums;
|
2022-05-06 14:22:23 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
2023-02-21 05:43:39 +02:00
|
|
|
ref.watch(backupProvider.notifier).getBackupInfo();
|
2022-07-13 14:23:48 +02:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-05-06 14:22:23 +02:00
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildAlbumSelectionList() {
|
2023-02-21 05:43:39 +02:00
|
|
|
if (albums.isEmpty) {
|
2023-03-01 05:10:53 +02:00
|
|
|
return const SliverToBoxAdapter(
|
|
|
|
child: Center(
|
|
|
|
child: ImmichLoadingIndicator(),
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-03-01 05:10:53 +02:00
|
|
|
return SliverPadding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 12.0),
|
|
|
|
sliver: SliverList(
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
((context, index) {
|
|
|
|
var thumbnailData = albums[index].thumbnailData;
|
|
|
|
return AlbumInfoListTile(
|
|
|
|
imageData: thumbnailData,
|
|
|
|
albumInfo: albums[index],
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
childCount: albums.length,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildAlbumSelectionGrid() {
|
|
|
|
if (albums.isEmpty) {
|
|
|
|
return const SliverToBoxAdapter(
|
|
|
|
child: Center(
|
|
|
|
child: ImmichLoadingIndicator(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SliverPadding(
|
|
|
|
padding: const EdgeInsets.all(12.0),
|
|
|
|
sliver: SliverGrid.builder(
|
|
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
maxCrossAxisExtent: 300,
|
|
|
|
mainAxisSpacing: 12,
|
|
|
|
crossAxisSpacing: 12,
|
|
|
|
),
|
2023-02-21 05:43:39 +02:00
|
|
|
itemCount: albums.length,
|
2022-05-06 14:22:23 +02:00
|
|
|
itemBuilder: ((context, index) {
|
2023-02-21 05:43:39 +02:00
|
|
|
var thumbnailData = albums[index].thumbnailData;
|
2023-03-01 05:10:53 +02:00
|
|
|
return AlbumInfoCard(
|
|
|
|
imageData: thumbnailData,
|
|
|
|
albumInfo: albums[index],
|
2022-05-06 14:22:23 +02:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildSelectedAlbumNameChip() {
|
2022-05-06 14:22:23 +02:00
|
|
|
return selectedBackupAlbums.map((album) {
|
2023-11-14 22:30:27 +02:00
|
|
|
void removeSelection() =>
|
|
|
|
ref.read(backupProvider.notifier).removeAlbumForBackup(album);
|
2022-05-06 14:22:23 +02:00
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: removeSelection,
|
|
|
|
child: Chip(
|
|
|
|
label: Text(
|
|
|
|
album.name,
|
2022-08-16 01:53:30 +02:00
|
|
|
style: TextStyle(
|
2023-11-20 16:58:03 +02:00
|
|
|
fontSize: 12,
|
2022-11-30 18:58:07 +02:00
|
|
|
color: isDarkTheme ? Colors.black : Colors.white,
|
2022-07-13 14:23:48 +02:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
2023-11-09 18:19:53 +02:00
|
|
|
backgroundColor: context.primaryColor,
|
2022-08-16 01:53:30 +02:00
|
|
|
deleteIconColor: isDarkTheme ? Colors.black : Colors.white,
|
2022-05-06 14:22:23 +02:00
|
|
|
deleteIcon: const Icon(
|
|
|
|
Icons.cancel_rounded,
|
|
|
|
size: 15,
|
|
|
|
),
|
|
|
|
onDeleted: removeSelection,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toSet();
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildExcludedAlbumNameChip() {
|
2022-05-06 14:22:23 +02:00
|
|
|
return excludedBackupAlbums.map((album) {
|
|
|
|
void removeSelection() {
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(backupProvider.notifier)
|
|
|
|
.removeExcludedAlbumForBackup(album);
|
2022-05-06 14:22:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: removeSelection,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: Chip(
|
|
|
|
label: Text(
|
|
|
|
album.name,
|
2022-08-16 01:53:30 +02:00
|
|
|
style: TextStyle(
|
2023-11-20 16:58:03 +02:00
|
|
|
fontSize: 12,
|
2022-08-16 01:53:30 +02:00
|
|
|
color: isDarkTheme ? Colors.black : immichBackgroundColor,
|
2022-07-13 14:23:48 +02:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
backgroundColor: Colors.red[300],
|
2022-08-16 01:53:30 +02:00
|
|
|
deleteIconColor:
|
|
|
|
isDarkTheme ? Colors.black : immichBackgroundColor,
|
2022-05-06 14:22:23 +02:00
|
|
|
deleteIcon: const Icon(
|
|
|
|
Icons.cancel_rounded,
|
|
|
|
size: 15,
|
|
|
|
),
|
|
|
|
onDeleted: removeSelection,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toSet();
|
|
|
|
}
|
|
|
|
|
2023-12-13 05:06:04 +02:00
|
|
|
// buildSearchBar() {
|
|
|
|
// return Padding(
|
|
|
|
// padding: const EdgeInsets.only(left: 16.0, right: 16, bottom: 8.0),
|
|
|
|
// child: TextFormField(
|
|
|
|
// onChanged: (searchValue) {
|
|
|
|
// // if (searchValue.isEmpty) {
|
|
|
|
// // albums = availableAlbums;
|
|
|
|
// // } else {
|
|
|
|
// // albums.value = availableAlbums
|
|
|
|
// // .where(
|
|
|
|
// // (album) => album.name
|
|
|
|
// // .toLowerCase()
|
|
|
|
// // .contains(searchValue.toLowerCase()),
|
|
|
|
// // )
|
|
|
|
// // .toList();
|
|
|
|
// // }
|
|
|
|
// },
|
|
|
|
// decoration: InputDecoration(
|
|
|
|
// contentPadding: const EdgeInsets.symmetric(
|
|
|
|
// horizontal: 8.0,
|
|
|
|
// vertical: 8.0,
|
|
|
|
// ),
|
|
|
|
// hintText: "Search",
|
|
|
|
// hintStyle: TextStyle(
|
|
|
|
// color: isDarkTheme ? Colors.white : Colors.grey,
|
|
|
|
// fontSize: 14.0,
|
|
|
|
// ),
|
|
|
|
// prefixIcon: const Icon(
|
|
|
|
// Icons.search,
|
|
|
|
// color: Colors.grey,
|
|
|
|
// ),
|
|
|
|
// border: OutlineInputBorder(
|
|
|
|
// borderRadius: BorderRadius.circular(10),
|
|
|
|
// borderSide: BorderSide.none,
|
|
|
|
// ),
|
|
|
|
// filled: true,
|
|
|
|
// fillColor: isDarkTheme ? Colors.white30 : Colors.grey[200],
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// }
|
2022-11-30 18:58:07 +02:00
|
|
|
|
2022-05-06 14:22:23 +02:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: IconButton(
|
2024-01-05 07:20:55 +02:00
|
|
|
onPressed: () => context.popRoute(),
|
2022-05-06 14:22:23 +02:00
|
|
|
icon: const Icon(Icons.arrow_back_ios_rounded),
|
|
|
|
),
|
|
|
|
title: const Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"backup_album_selection_page_select_albums",
|
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
elevation: 0,
|
|
|
|
),
|
2023-03-01 05:10:53 +02:00
|
|
|
body: CustomScrollView(
|
2022-05-06 14:22:23 +02:00
|
|
|
physics: const ClampingScrollPhysics(),
|
2023-03-01 05:10:53 +02:00
|
|
|
slivers: [
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2022-06-25 22:12:47 +02:00
|
|
|
children: [
|
2023-03-01 05:10:53 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 8.0,
|
|
|
|
horizontal: 16.0,
|
|
|
|
),
|
2023-11-20 16:58:03 +02:00
|
|
|
child: Text(
|
2023-03-01 05:10:53 +02:00
|
|
|
"backup_album_selection_page_selection_info",
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.titleSmall,
|
2023-03-01 05:10:53 +02:00
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
// Selected Album Chips
|
2022-05-06 14:22:23 +02:00
|
|
|
|
2023-03-01 05:10:53 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
child: Wrap(
|
|
|
|
children: [
|
|
|
|
...buildSelectedAlbumNameChip(),
|
2023-08-19 00:52:40 +02:00
|
|
|
...buildExcludedAlbumNameChip(),
|
2023-03-01 05:10:53 +02:00
|
|
|
],
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
2023-03-01 05:10:53 +02:00
|
|
|
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
"backup_album_selection_page_albums_device".tr(
|
|
|
|
args: [
|
|
|
|
ref
|
|
|
|
.watch(backupProvider)
|
|
|
|
.availableAlbums
|
|
|
|
.length
|
2023-08-19 00:52:40 +02:00
|
|
|
.toString(),
|
2023-03-01 05:10:53 +02:00
|
|
|
],
|
|
|
|
),
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.titleSmall,
|
2023-03-01 05:10:53 +02:00
|
|
|
),
|
|
|
|
subtitle: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
child: Text(
|
|
|
|
"backup_album_selection_page_albums_tap",
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.labelLarge?.copyWith(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2022-07-13 14:23:48 +02:00
|
|
|
),
|
2023-03-01 05:10:53 +02:00
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
trailing: IconButton(
|
|
|
|
splashRadius: 16,
|
|
|
|
icon: Icon(
|
|
|
|
Icons.info,
|
|
|
|
size: 20,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-03-01 05:10:53 +02:00
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
// show the dialog
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
elevation: 5,
|
|
|
|
title: Text(
|
|
|
|
'backup_album_selection_page_selection_info',
|
2022-06-25 22:12:47 +02:00
|
|
|
style: TextStyle(
|
2023-03-01 05:10:53 +02:00
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.bold,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2022-07-13 14:23:48 +02:00
|
|
|
),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2023-03-01 05:10:53 +02:00
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: ListBody(
|
|
|
|
children: [
|
|
|
|
const Text(
|
|
|
|
'backup_album_selection_page_assets_scatter',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
2023-12-13 05:06:04 +02:00
|
|
|
// buildSearchBar(),
|
2023-03-01 05:10:53 +02:00
|
|
|
],
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
),
|
2023-03-01 05:10:53 +02:00
|
|
|
SliverLayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
if (constraints.crossAxisExtent > 600) {
|
|
|
|
return buildAlbumSelectionGrid();
|
|
|
|
} else {
|
|
|
|
return buildAlbumSelectionList();
|
|
|
|
}
|
|
|
|
},
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|