2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-08 19:24:49 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/providers/home_page_state.provider.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:openapi/api.dart';
|
2022-02-08 19:24:49 +02:00
|
|
|
|
|
|
|
class DailyTitleText extends ConsumerWidget {
|
|
|
|
const DailyTitleText({
|
|
|
|
Key? key,
|
|
|
|
required this.isoDate,
|
|
|
|
required this.assetGroup,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String isoDate;
|
2022-07-13 14:23:48 +02:00
|
|
|
final List<AssetResponseDto> assetGroup;
|
2022-02-08 19:24:49 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
var currentYear = DateTime.now().year;
|
|
|
|
var groupYear = DateTime.parse(isoDate).year;
|
2022-07-13 14:23:48 +02:00
|
|
|
var formatDateTemplate = currentYear == groupYear
|
|
|
|
? "daily_title_text_date".tr()
|
|
|
|
: "daily_title_text_date_year".tr();
|
2022-09-22 22:58:17 +02:00
|
|
|
var dateText = DateFormat(formatDateTemplate)
|
|
|
|
.format(DateTime.parse(isoDate).toLocal());
|
2022-06-25 22:12:47 +02:00
|
|
|
var isMultiSelectEnable =
|
|
|
|
ref.watch(homePageStateProvider).isMultiSelectEnable;
|
2022-02-08 19:24:49 +02:00
|
|
|
var selectedDateGroup = ref.watch(homePageStateProvider).selectedDateGroup;
|
|
|
|
var selectedItems = ref.watch(homePageStateProvider).selectedItems;
|
|
|
|
|
2022-02-09 20:41:02 +02:00
|
|
|
void _handleTitleIconClick() {
|
|
|
|
if (isMultiSelectEnable &&
|
|
|
|
selectedDateGroup.contains(dateText) &&
|
|
|
|
selectedDateGroup.length == 1 &&
|
|
|
|
selectedItems.length <= assetGroup.length) {
|
|
|
|
// Multi select is active - click again on the icon while it is the only active group -> disable multi select
|
|
|
|
ref.watch(homePageStateProvider.notifier).disableMultiSelect();
|
|
|
|
} else if (isMultiSelectEnable &&
|
|
|
|
selectedDateGroup.contains(dateText) &&
|
|
|
|
selectedItems.length != assetGroup.length) {
|
|
|
|
// Multi select is active - click again on the icon while it is not the only active group -> remove that group from selected group/items
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.removeSelectedDateGroup(dateText);
|
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.removeMultipleSelectedItem(assetGroup);
|
|
|
|
} else if (isMultiSelectEnable &&
|
|
|
|
selectedDateGroup.contains(dateText) &&
|
|
|
|
selectedDateGroup.length > 1) {
|
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.removeSelectedDateGroup(dateText);
|
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.removeMultipleSelectedItem(assetGroup);
|
2022-02-09 20:41:02 +02:00
|
|
|
} else if (isMultiSelectEnable && !selectedDateGroup.contains(dateText)) {
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.addSelectedDateGroup(dateText);
|
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.addMultipleSelectedItems(assetGroup);
|
2022-02-09 20:41:02 +02:00
|
|
|
} else {
|
2022-06-25 22:12:47 +02:00
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.enableMultiSelect(assetGroup.toSet());
|
|
|
|
ref
|
|
|
|
.watch(homePageStateProvider.notifier)
|
|
|
|
.addSelectedDateGroup(dateText);
|
2022-02-09 20:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 19:24:49 +02:00
|
|
|
return SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
2022-06-25 22:12:47 +02:00
|
|
|
padding: const EdgeInsets.only(
|
2022-07-13 14:23:48 +02:00
|
|
|
top: 29.0,
|
|
|
|
bottom: 29.0,
|
|
|
|
left: 12.0,
|
|
|
|
right: 12.0,
|
|
|
|
),
|
2022-02-08 19:24:49 +02:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
dateText,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
GestureDetector(
|
2022-02-09 20:41:02 +02:00
|
|
|
onTap: _handleTitleIconClick,
|
2022-02-08 19:24:49 +02:00
|
|
|
child: isMultiSelectEnable && selectedDateGroup.contains(dateText)
|
2022-02-09 20:41:02 +02:00
|
|
|
? Icon(
|
|
|
|
Icons.check_circle_rounded,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
)
|
|
|
|
: const Icon(
|
|
|
|
Icons.check_circle_outline_rounded,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
2022-02-08 19:24:49 +02:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|