2022-05-06 14:22:23 +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:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/backup/ui/album_info_card.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
|
|
|
|
|
|
|
class BackupAlbumSelectionPage extends HookConsumerWidget {
|
|
|
|
const BackupAlbumSelectionPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final availableAlbums = ref.watch(backupProvider).availableAlbums;
|
|
|
|
final selectedBackupAlbums = ref.watch(backupProvider).selectedBackupAlbums;
|
|
|
|
final excludedBackupAlbums = ref.watch(backupProvider).excludedBackupAlbums;
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
ref.read(backupProvider.notifier).getBackupInfo();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-05-06 14:22:23 +02:00
|
|
|
|
|
|
|
_buildAlbumSelectionList() {
|
|
|
|
if (availableAlbums.isEmpty) {
|
|
|
|
return const Center(
|
|
|
|
child: ImmichLoadingIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
height: 265,
|
|
|
|
child: ListView.builder(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
itemCount: availableAlbums.length,
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
itemBuilder: ((context, index) {
|
|
|
|
var thumbnailData = availableAlbums[index].thumbnailData;
|
|
|
|
return Padding(
|
2022-06-25 22:12:47 +02:00
|
|
|
padding: index == 0
|
|
|
|
? const EdgeInsets.only(left: 16.00)
|
|
|
|
: const EdgeInsets.all(0),
|
|
|
|
child: AlbumInfoCard(
|
2022-07-13 14:23:48 +02:00
|
|
|
imageData: thumbnailData,
|
|
|
|
albumInfo: availableAlbums[index].albumEntity,
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_buildSelectedAlbumNameChip() {
|
|
|
|
return selectedBackupAlbums.map((album) {
|
|
|
|
void removeSelection() {
|
|
|
|
if (ref.watch(backupProvider).selectedBackupAlbums.length == 1) {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
2022-07-07 20:40:54 +02:00
|
|
|
msg: "backup_err_only_album".tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
toastType: ToastType.error,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref.watch(backupProvider.notifier).removeAlbumForBackup(album);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: removeSelection,
|
|
|
|
child: Chip(
|
|
|
|
visualDensity: VisualDensity.compact,
|
2022-06-25 22:12:47 +02:00
|
|
|
shape: RoundedRectangleBorder(
|
2022-07-13 14:23:48 +02:00
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
label: Text(
|
|
|
|
album.name,
|
2022-06-25 22:12:47 +02:00
|
|
|
style: const TextStyle(
|
2022-07-13 14:23:48 +02:00
|
|
|
fontSize: 10,
|
|
|
|
color: Colors.white,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
|
|
deleteIconColor: Colors.white,
|
|
|
|
deleteIcon: const Icon(
|
|
|
|
Icons.cancel_rounded,
|
|
|
|
size: 15,
|
|
|
|
),
|
|
|
|
onDeleted: removeSelection,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
_buildExcludedAlbumNameChip() {
|
|
|
|
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(
|
|
|
|
visualDensity: VisualDensity.compact,
|
2022-06-25 22:12:47 +02:00
|
|
|
shape: RoundedRectangleBorder(
|
2022-07-13 14:23:48 +02:00
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
label: Text(
|
|
|
|
album.name,
|
2022-06-25 22:12:47 +02:00
|
|
|
style: const TextStyle(
|
2022-07-13 14:23:48 +02:00
|
|
|
fontSize: 10,
|
|
|
|
color: Colors.white,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
backgroundColor: Colors.red[300],
|
|
|
|
deleteIconColor: Colors.white,
|
|
|
|
deleteIcon: const Icon(
|
|
|
|
Icons.cancel_rounded,
|
|
|
|
size: 15,
|
|
|
|
),
|
|
|
|
onDeleted: removeSelection,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: IconButton(
|
|
|
|
onPressed: () => AutoRouter.of(context).pop(),
|
|
|
|
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",
|
2022-05-06 14:22:23 +02:00
|
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
elevation: 0,
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
physics: const ClampingScrollPhysics(),
|
|
|
|
children: [
|
2022-07-07 20:40:54 +02:00
|
|
|
Padding(
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
|
|
|
|
child: const Text(
|
|
|
|
"backup_album_selection_page_selection_info",
|
2022-05-06 14:22:23 +02:00
|
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
// Selected Album Chips
|
|
|
|
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
child: Wrap(
|
2022-06-25 22:12:47 +02:00
|
|
|
children: [
|
|
|
|
..._buildSelectedAlbumNameChip(),
|
|
|
|
..._buildExcludedAlbumNameChip()
|
|
|
|
],
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
|
|
|
|
child: Card(
|
|
|
|
margin: const EdgeInsets.all(0),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(5), // if you need this
|
|
|
|
side: const BorderSide(
|
|
|
|
color: Color.fromARGB(255, 235, 235, 235),
|
|
|
|
width: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
elevation: 0,
|
|
|
|
borderOnForeground: false,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
visualDensity: VisualDensity.compact,
|
|
|
|
title: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"backup_album_selection_page_total_assets",
|
2022-06-25 22:12:47 +02:00
|
|
|
style: TextStyle(
|
2022-07-13 14:23:48 +02:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14,
|
|
|
|
color: Colors.grey[700],
|
|
|
|
),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
trailing: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
ref
|
|
|
|
.watch(backupProvider)
|
|
|
|
.allUniqueAssets
|
|
|
|
.length
|
|
|
|
.toString(),
|
2022-05-06 14:22:23 +02:00
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"backup_album_selection_page_albums_device"
|
|
|
|
.tr(args: [availableAlbums.length.toString()]),
|
2022-05-06 14:22:23 +02:00
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
|
|
|
|
),
|
|
|
|
subtitle: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
child: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"backup_album_selection_page_albums_tap",
|
2022-05-06 14:22:23 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
trailing: IconButton(
|
|
|
|
splashRadius: 16,
|
|
|
|
icon: Icon(
|
|
|
|
Icons.info,
|
|
|
|
size: 20,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
// show the dialog
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
2022-06-25 22:12:47 +02:00
|
|
|
shape: RoundedRectangleBorder(
|
2022-07-13 14:23:48 +02:00
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
elevation: 5,
|
|
|
|
title: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
'backup_album_selection_page_selection_info',
|
2022-05-06 14:22:23 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: ListBody(
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
'backup_album_selection_page_assets_scatter',
|
2022-06-25 22:12:47 +02:00
|
|
|
style: TextStyle(
|
2022-07-13 14:23:48 +02:00
|
|
|
fontSize: 14,
|
|
|
|
color: Colors.grey[700],
|
|
|
|
),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 16.0),
|
|
|
|
child: _buildAlbumSelectionList(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|