2022-05-06 05:22:23 -07:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.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/routing/router.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
|
|
|
import 'package:photo_manager/photo_manager.dart';
|
|
|
|
|
|
|
|
class AlbumInfoCard extends HookConsumerWidget {
|
|
|
|
final Uint8List? imageData;
|
|
|
|
final AssetPathEntity albumInfo;
|
|
|
|
|
2022-06-25 13:12:47 -07:00
|
|
|
const AlbumInfoCard({Key? key, this.imageData, required this.albumInfo})
|
|
|
|
: super(key: key);
|
2022-05-06 05:22:23 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-25 13:12:47 -07:00
|
|
|
final bool isSelected =
|
|
|
|
ref.watch(backupProvider).selectedBackupAlbums.contains(albumInfo);
|
|
|
|
final bool isExcluded =
|
|
|
|
ref.watch(backupProvider).excludedBackupAlbums.contains(albumInfo);
|
2022-05-06 05:22:23 -07:00
|
|
|
|
2022-06-25 13:12:47 -07:00
|
|
|
ColorFilter selectedFilter = ColorFilter.mode(
|
|
|
|
Theme.of(context).primaryColor.withAlpha(100), BlendMode.darken);
|
|
|
|
ColorFilter excludedFilter =
|
|
|
|
ColorFilter.mode(Colors.red.withAlpha(75), BlendMode.darken);
|
|
|
|
ColorFilter unselectedFilter =
|
|
|
|
const ColorFilter.mode(Colors.black, BlendMode.color);
|
2022-05-06 05:22:23 -07:00
|
|
|
|
|
|
|
_buildSelectedTextBox() {
|
|
|
|
if (isSelected) {
|
|
|
|
return Chip(
|
|
|
|
visualDensity: VisualDensity.compact,
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
|
|
|
|
label: const Text(
|
|
|
|
"INCLUDED",
|
2022-06-25 13:12:47 -07:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 10, color: Colors.white, fontWeight: FontWeight.bold),
|
2022-05-06 05:22:23 -07:00
|
|
|
),
|
|
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
|
|
);
|
|
|
|
} else if (isExcluded) {
|
|
|
|
return Chip(
|
|
|
|
visualDensity: VisualDensity.compact,
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
|
|
|
|
label: const Text(
|
|
|
|
"EXCLUDED",
|
2022-06-25 13:12:47 -07:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 10, color: Colors.white, fontWeight: FontWeight.bold),
|
2022-05-06 05:22:23 -07:00
|
|
|
),
|
|
|
|
backgroundColor: Colors.red[300],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-30 18:08:49 -07:00
|
|
|
return const SizedBox();
|
2022-05-06 05:22:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_buildImageFilter() {
|
|
|
|
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,
|
|
|
|
msg: "Cannot remove the only album",
|
|
|
|
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-06-25 13:12:47 -07:00
|
|
|
ref
|
|
|
|
.watch(backupProvider.notifier)
|
|
|
|
.removeExcludedAlbumForBackup(albumInfo);
|
2022-05-06 05:22:23 -07:00
|
|
|
} else {
|
|
|
|
if (ref.watch(backupProvider).selectedBackupAlbums.length == 1 &&
|
2022-06-25 13:12:47 -07:00
|
|
|
ref
|
|
|
|
.watch(backupProvider)
|
|
|
|
.selectedBackupAlbums
|
|
|
|
.contains(albumInfo)) {
|
2022-05-06 05:22:23 -07:00
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
msg: "Cannot exclude the only album",
|
|
|
|
toastType: ToastType.error,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-25 13:12:47 -07:00
|
|
|
ref
|
|
|
|
.watch(backupProvider.notifier)
|
|
|
|
.addExcludedAlbumForBackup(albumInfo);
|
2022-05-06 05:22:23 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Card(
|
|
|
|
margin: const EdgeInsets.all(1),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(12), // if you need this
|
|
|
|
side: const BorderSide(
|
|
|
|
color: Color(0xFFC9C9C9),
|
|
|
|
width: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
elevation: 0,
|
|
|
|
borderOnForeground: false,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 200,
|
|
|
|
height: 200,
|
|
|
|
decoration: BoxDecoration(
|
2022-06-25 13:12:47 -07:00
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(12),
|
|
|
|
topRight: Radius.circular(12)),
|
2022-05-06 05:22:23 -07:00
|
|
|
image: DecorationImage(
|
|
|
|
colorFilter: _buildImageFilter(),
|
|
|
|
image: imageData != null
|
|
|
|
? MemoryImage(imageData!)
|
2022-06-25 13:12:47 -07:00
|
|
|
: const AssetImage(
|
|
|
|
'assets/immich-logo-no-outline.png')
|
|
|
|
as ImageProvider,
|
2022-05-06 05:22:23 -07:00
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: null,
|
|
|
|
),
|
2022-06-30 18:08:49 -07:00
|
|
|
Positioned(
|
|
|
|
bottom: 10,
|
|
|
|
left: 25,
|
|
|
|
child: _buildSelectedTextBox(),
|
|
|
|
)
|
2022-05-06 05:22:23 -07: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-06-25 13:12:47 -07:00
|
|
|
fontSize: 14,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold),
|
2022-05-06 05:22:23 -07:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 2.0),
|
|
|
|
child: Text(
|
2022-06-30 18:08:49 -07:00
|
|
|
'${albumInfo.assetCount} ${(albumInfo.isAll ? " (ALL)" : "")}',
|
2022-06-25 13:12:47 -07:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12, color: Colors.grey[600]),
|
2022-05-06 05:22:23 -07:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2022-06-25 13:12:47 -07:00
|
|
|
AutoRouter.of(context)
|
|
|
|
.push(AlbumPreviewRoute(album: albumInfo));
|
2022-05-06 05:22:23 -07:00
|
|
|
},
|
|
|
|
icon: Icon(
|
|
|
|
Icons.image_outlined,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
splashRadius: 25,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|