mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
Quick date picker: localization, fix datetime overflows
This commit is contained in:
parent
2c29697b55
commit
f538b5563a
3 changed files with 44 additions and 15 deletions
|
|
@ -1174,6 +1174,7 @@
|
|||
"import_path": "Import path",
|
||||
"in_albums": "In {count, plural, one {# album} other {# albums}}",
|
||||
"in_archive": "In archive",
|
||||
"in_year": "In {year}",
|
||||
"include_archived": "Include archived",
|
||||
"include_shared_albums": "Include shared albums",
|
||||
"include_shared_partner_assets": "Include shared partner assets",
|
||||
|
|
@ -1210,6 +1211,8 @@
|
|||
"language_setting_description": "Select your preferred language",
|
||||
"large_files": "Large Files",
|
||||
"last": "Last",
|
||||
"last_month": "Last month",
|
||||
"last_nth_month": "Last {months} months",
|
||||
"last_seen": "Last seen",
|
||||
"latest_version": "Latest Version",
|
||||
"latitude": "Latitude",
|
||||
|
|
@ -1516,6 +1519,8 @@
|
|||
"photos_count": "{count, plural, one {{count, number} Photo} other {{count, number} Photos}}",
|
||||
"photos_from_previous_years": "Photos from previous years",
|
||||
"pick_a_location": "Pick a location",
|
||||
"pick_date_range": "Select a date range",
|
||||
"pick_exact_date": "Enter a custom interval",
|
||||
"pin_code_changed_successfully": "Successfully changed PIN code",
|
||||
"pin_code_reset_successfully": "Successfully reset PIN code",
|
||||
"pin_code_setup_successfully": "Successfully setup a PIN code",
|
||||
|
|
|
|||
|
|
@ -285,15 +285,23 @@ class DriftSearchPage extends HookConsumerWidget {
|
|||
final firstDate = DateTime(1900);
|
||||
final lastDate = DateTime.now();
|
||||
|
||||
var dateRange = DateTimeRange(
|
||||
start: filter.value.date.takenAfter ?? lastDate,
|
||||
end: filter.value.date.takenBefore ?? lastDate,
|
||||
);
|
||||
|
||||
// datePicked() may increase the date, this will make the date picker fail an assertion
|
||||
// Fixup the end date to be at most now.
|
||||
if (dateRange.end.isAfter(lastDate)) {
|
||||
dateRange = DateTimeRange(start: dateRange.start, end: lastDate);
|
||||
}
|
||||
|
||||
final date = await showDateRangePicker(
|
||||
context: context,
|
||||
firstDate: firstDate,
|
||||
lastDate: lastDate,
|
||||
currentDate: DateTime.now(),
|
||||
initialDateRange: DateTimeRange(
|
||||
start: filter.value.date.takenAfter ?? lastDate,
|
||||
end: filter.value.date.takenBefore ?? lastDate,
|
||||
),
|
||||
initialDateRange: dateRange,
|
||||
helpText: 'search_filter_date_title'.t(context: context),
|
||||
cancelText: 'cancel'.t(context: context),
|
||||
confirmText: 'select'.t(context: context),
|
||||
|
|
@ -313,7 +321,7 @@ class DriftSearchPage extends HookConsumerWidget {
|
|||
showFilterBottomSheet(
|
||||
context: context,
|
||||
child: FilterBottomSheetScaffold(
|
||||
title: "Pick date range",
|
||||
title: "pick_date_range".tr(),
|
||||
expanded: true,
|
||||
onClear: () => datePicked(null),
|
||||
child: QuickDatePicker(
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
|
||||
|
|
@ -7,13 +8,28 @@ class QuickDatePicker extends HookWidget {
|
|||
final Function() onRequestPicker;
|
||||
final Function(DateTimeRange<DateTime> range) onSelect;
|
||||
|
||||
ListTile _monthListTile(String text, int monthsFromNow) {
|
||||
void _selectRange(DateTimeRange range) {
|
||||
// Ensure we don't go beyond today, eg when picking "in $current_year"
|
||||
final now = DateTime.now();
|
||||
if (range.end.isAfter(now)) {
|
||||
range = DateTimeRange(start: range.start, end: now);
|
||||
}
|
||||
|
||||
onSelect(range);
|
||||
}
|
||||
|
||||
ListTile _monthListTile(int monthsFromNow) {
|
||||
String label = monthsFromNow == 1
|
||||
? 'last_month'.tr()
|
||||
: 'last_nth_month'.tr(namedArgs: {"months": monthsFromNow.toString()});
|
||||
return ListTile(
|
||||
title: Text(text),
|
||||
title: Text(label),
|
||||
onTap: () {
|
||||
final now = DateTime.now();
|
||||
final from = DateTime(now.year, now.month - monthsFromNow, now.day);
|
||||
onSelect(DateTimeRange(start: from, end: now));
|
||||
// We use the first of the target month here to avoid issues with different month lengths
|
||||
// the negative overflow of months is handled by DateTime correctly
|
||||
final from = DateTime(now.year, now.month - monthsFromNow, 1);
|
||||
_selectRange(DateTimeRange(start: from, end: now));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -24,27 +40,27 @@ class QuickDatePicker extends HookWidget {
|
|||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
return ListTile(
|
||||
title: const Text("Exact date"),
|
||||
title: Text('pick_exact_date'.tr()),
|
||||
onTap: () {
|
||||
onRequestPicker();
|
||||
},
|
||||
);
|
||||
} else if (index == 1) {
|
||||
return _monthListTile("Last month", 1);
|
||||
return _monthListTile(1);
|
||||
} else if (index == 2) {
|
||||
return _monthListTile("Last 3 months", 3);
|
||||
return _monthListTile(3);
|
||||
} else if (index == 3) {
|
||||
return _monthListTile("Last 9 months", 9);
|
||||
return _monthListTile(9);
|
||||
} else {
|
||||
final now = DateTime.now();
|
||||
final years = index - 4;
|
||||
final year = now.year - years;
|
||||
return ListTile(
|
||||
title: Text("In $year"),
|
||||
title: Text("in_year".tr(namedArgs: {"year": year.toString()})),
|
||||
onTap: () {
|
||||
final from = DateTime(year, 1, 1);
|
||||
final to = DateTime(year, 12, 31, 23, 59, 59);
|
||||
onSelect(DateTimeRange(start: from, end: to));
|
||||
_selectRange(DateTimeRange(start: from, end: to));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue