2022-04-23 19:08:45 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/sharing/providers/asset_selection.provider.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
|
|
|
|
|
|
|
class MonthGroupTitle extends HookConsumerWidget {
|
|
|
|
final String month;
|
|
|
|
final List<ImmichAsset> assetGroup;
|
|
|
|
|
2022-06-25 13:12:47 -07:00
|
|
|
const MonthGroupTitle(
|
|
|
|
{Key? key, required this.month, required this.assetGroup})
|
|
|
|
: super(key: key);
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final selectedDateGroup = ref.watch(assetSelectionProvider).selectedMonths;
|
2022-06-25 13:12:47 -07:00
|
|
|
final selectedAssets =
|
|
|
|
ref.watch(assetSelectionProvider).selectedNewAssetsForAlbum;
|
2022-04-23 19:08:45 -07:00
|
|
|
final isAlbumExist = ref.watch(assetSelectionProvider).isAlbumExist;
|
|
|
|
|
|
|
|
_handleTitleIconClick() {
|
|
|
|
HapticFeedback.heavyImpact();
|
|
|
|
|
|
|
|
if (isAlbumExist) {
|
|
|
|
if (selectedDateGroup.contains(month)) {
|
2022-06-25 13:12:47 -07:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.removeAssetsInMonth(month, []);
|
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.removeSelectedAdditionalAssets(assetGroup);
|
2022-04-23 19:08:45 -07:00
|
|
|
} else {
|
2022-06-25 13:12:47 -07:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.addAllAssetsInMonth(month, []);
|
2022-04-23 19:08:45 -07:00
|
|
|
|
|
|
|
// Deep clone assetGroup
|
|
|
|
var assetGroupWithNewItems = [...assetGroup];
|
|
|
|
|
|
|
|
for (var selectedAsset in selectedAssets) {
|
|
|
|
assetGroupWithNewItems.removeWhere((a) => a.id == selectedAsset.id);
|
|
|
|
}
|
|
|
|
|
2022-06-25 13:12:47 -07:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.addAdditionalAssets(assetGroupWithNewItems);
|
2022-04-23 19:08:45 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (selectedDateGroup.contains(month)) {
|
2022-06-25 13:12:47 -07:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.removeAssetsInMonth(month, assetGroup);
|
2022-04-23 19:08:45 -07:00
|
|
|
} else {
|
2022-06-25 13:12:47 -07:00
|
|
|
ref
|
|
|
|
.watch(assetSelectionProvider.notifier)
|
|
|
|
.addAllAssetsInMonth(month, assetGroup);
|
2022-04-23 19:08:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_getSimplifiedMonth() {
|
|
|
|
var monthAndYear = month.split(',');
|
|
|
|
var yearText = monthAndYear[1].trim();
|
|
|
|
var monthText = monthAndYear[0].trim();
|
|
|
|
var currentYear = DateTime.now().year.toString();
|
|
|
|
|
|
|
|
if (yearText == currentYear) {
|
|
|
|
return monthText;
|
|
|
|
} else {
|
|
|
|
return month;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
2022-06-25 13:12:47 -07:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 29.0, bottom: 29.0, left: 14.0, right: 8.0),
|
2022-04-23 19:08:45 -07:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
GestureDetector(
|
|
|
|
onTap: _handleTitleIconClick,
|
|
|
|
child: selectedDateGroup.contains(month)
|
|
|
|
? Icon(
|
|
|
|
Icons.check_circle_rounded,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
)
|
|
|
|
: const Icon(
|
|
|
|
Icons.circle_outlined,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
|
|
child: Text(
|
|
|
|
_getSimplifiedMonth(),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 24,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|