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/services.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-18 16:41:59 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/models/available_album.model.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
|
|
|
|
|
|
|
class AlbumInfoCard extends HookConsumerWidget {
|
|
|
|
final Uint8List? imageData;
|
2022-08-18 16:41:59 +02:00
|
|
|
final AvailableAlbum albumInfo;
|
2022-05-06 14:22:23 +02:00
|
|
|
|
2022-06-25 22:12:47 +02:00
|
|
|
const AlbumInfoCard({Key? key, this.imageData, required this.albumInfo})
|
|
|
|
: super(key: key);
|
2022-05-06 14:22:23 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-25 22:12:47 +02:00
|
|
|
final bool isSelected =
|
|
|
|
ref.watch(backupProvider).selectedBackupAlbums.contains(albumInfo);
|
|
|
|
final bool isExcluded =
|
|
|
|
ref.watch(backupProvider).excludedBackupAlbums.contains(albumInfo);
|
2022-08-16 01:53:30 +02:00
|
|
|
final isDarkTheme = Theme.of(context).brightness == Brightness.dark;
|
2022-05-06 14:22:23 +02:00
|
|
|
|
2022-06-25 22:12:47 +02:00
|
|
|
ColorFilter selectedFilter = ColorFilter.mode(
|
2022-07-13 14:23:48 +02:00
|
|
|
Theme.of(context).primaryColor.withAlpha(100),
|
|
|
|
BlendMode.darken,
|
|
|
|
);
|
2022-06-25 22:12:47 +02:00
|
|
|
ColorFilter excludedFilter =
|
|
|
|
ColorFilter.mode(Colors.red.withAlpha(75), BlendMode.darken);
|
|
|
|
ColorFilter unselectedFilter =
|
|
|
|
const ColorFilter.mode(Colors.black, BlendMode.color);
|
2022-05-06 14:22:23 +02:00
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildSelectedTextBox() {
|
2022-05-06 14:22:23 +02:00
|
|
|
if (isSelected) {
|
|
|
|
return Chip(
|
|
|
|
visualDensity: VisualDensity.compact,
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
|
2022-08-16 01:53:30 +02:00
|
|
|
label: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"album_info_card_backup_album_included",
|
2022-06-25 22:12:47 +02:00
|
|
|
style: TextStyle(
|
2022-07-13 14:23:48 +02:00
|
|
|
fontSize: 10,
|
2022-08-16 01:53:30 +02:00
|
|
|
color: isDarkTheme ? Colors.black : Colors.white,
|
2022-07-13 14:23:48 +02:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
|
|
);
|
|
|
|
} else if (isExcluded) {
|
|
|
|
return Chip(
|
|
|
|
visualDensity: VisualDensity.compact,
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
|
2022-08-16 01:53:30 +02:00
|
|
|
label: Text(
|
2022-07-07 20:40:54 +02:00
|
|
|
"album_info_card_backup_album_excluded",
|
2022-06-25 22:12:47 +02:00
|
|
|
style: TextStyle(
|
2022-07-13 14:23:48 +02:00
|
|
|
fontSize: 10,
|
2022-08-16 01:53:30 +02:00
|
|
|
color: isDarkTheme ? Colors.black : Colors.white,
|
2022-07-13 14:23:48 +02:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-07-07 20:40:54 +02:00
|
|
|
).tr(),
|
2022-05-06 14:22:23 +02:00
|
|
|
backgroundColor: Colors.red[300],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-01 03:08:49 +02:00
|
|
|
return const SizedBox();
|
2022-05-06 14:22:23 +02:00
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildImageFilter() {
|
2022-05-06 14:22:23 +02:00
|
|
|
if (isSelected) {
|
|
|
|
return selectedFilter;
|
|
|
|
} else if (isExcluded) {
|
|
|
|
return excludedFilter;
|
|
|
|
} else {
|
|
|
|
return unselectedFilter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
HapticFeedback.selectionClick();
|
|
|
|
|
|
|
|
if (isSelected) {
|
|
|
|
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(albumInfo);
|
|
|
|
} else {
|
|
|
|
ref.watch(backupProvider.notifier).addAlbumForBackup(albumInfo);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onDoubleTap: () {
|
|
|
|
HapticFeedback.selectionClick();
|
|
|
|
|
|
|
|
if (isExcluded) {
|
2022-08-01 04:56:41 +02:00
|
|
|
// Remove from exclude album list
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(backupProvider.notifier)
|
|
|
|
.removeExcludedAlbumForBackup(albumInfo);
|
2022-05-06 14:22:23 +02:00
|
|
|
} else {
|
2022-08-01 04:56:41 +02:00
|
|
|
// Add to exclude album list
|
2022-05-06 14:22:23 +02:00
|
|
|
if (ref.watch(backupProvider).selectedBackupAlbums.length == 1 &&
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(backupProvider)
|
|
|
|
.selectedBackupAlbums
|
|
|
|
.contains(albumInfo)) {
|
2022-05-06 14:22:23 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-08-18 23:27:08 +02:00
|
|
|
if (albumInfo.id == 'isAll' || albumInfo.name == 'Recents') {
|
2022-08-01 04:56:41 +02:00
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: 'Cannot exclude album contains all assets',
|
|
|
|
toastType: ToastType.error,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(backupProvider.notifier)
|
|
|
|
.addExcludedAlbumForBackup(albumInfo);
|
2022-05-06 14:22:23 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Card(
|
|
|
|
margin: const EdgeInsets.all(1),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(12), // if you need this
|
2022-08-16 01:53:30 +02:00
|
|
|
side: BorderSide(
|
|
|
|
color: isDarkTheme
|
|
|
|
? const Color.fromARGB(255, 37, 35, 35)
|
|
|
|
: const Color(0xFFC9C9C9),
|
2022-05-06 14:22:23 +02:00
|
|
|
width: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
elevation: 0,
|
|
|
|
borderOnForeground: false,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 200,
|
|
|
|
height: 200,
|
|
|
|
decoration: BoxDecoration(
|
2022-06-25 22:12:47 +02:00
|
|
|
borderRadius: const BorderRadius.only(
|
2022-07-13 14:23:48 +02:00
|
|
|
topLeft: Radius.circular(12),
|
|
|
|
topRight: Radius.circular(12),
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
image: DecorationImage(
|
2022-11-21 14:13:14 +02:00
|
|
|
colorFilter: buildImageFilter(),
|
2022-05-06 14:22:23 +02:00
|
|
|
image: imageData != null
|
|
|
|
? MemoryImage(imageData!)
|
2022-06-25 22:12:47 +02:00
|
|
|
: const AssetImage(
|
2022-07-13 14:23:48 +02:00
|
|
|
'assets/immich-logo-no-outline.png',
|
|
|
|
) as ImageProvider,
|
2022-05-06 14:22:23 +02:00
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: null,
|
|
|
|
),
|
2022-07-01 03:08:49 +02:00
|
|
|
Positioned(
|
|
|
|
bottom: 10,
|
|
|
|
left: 25,
|
2022-11-21 14:13:14 +02:00
|
|
|
child: buildSelectedTextBox(),
|
2022-07-01 03:08:49 +02:00
|
|
|
)
|
2022-05-06 14:22:23 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: 140,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 25.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
albumInfo.name,
|
|
|
|
style: TextStyle(
|
2022-07-13 14:23:48 +02:00
|
|
|
fontSize: 14,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 2.0),
|
2022-09-16 23:46:23 +02:00
|
|
|
child: FutureBuilder(
|
|
|
|
builder: ((context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return Text(
|
|
|
|
snapshot.data.toString() +
|
|
|
|
(albumInfo.isAll
|
|
|
|
? " (${'backup_all'.tr()})"
|
|
|
|
: ""),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return const Text("0");
|
|
|
|
}),
|
|
|
|
future: albumInfo.assetCount,
|
2022-05-06 14:22:23 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2022-08-16 01:53:30 +02:00
|
|
|
AutoRouter.of(context).push(
|
2022-08-18 16:41:59 +02:00
|
|
|
AlbumPreviewRoute(album: albumInfo.albumEntity),
|
2022-08-16 01:53:30 +02:00
|
|
|
);
|
2022-05-06 14:22:23 +02:00
|
|
|
},
|
|
|
|
icon: Icon(
|
|
|
|
Icons.image_outlined,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
splashRadius: 25,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|