From 6e30282051754057cabdc226a98caeec45598464 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 22 Aug 2022 09:44:38 +0530 Subject: [PATCH] cache years and its durations --- lib/data/years.dart | 23 +++++++++++++++++++++++ lib/ui/viewer/search/search_widget.dart | 10 +++++----- 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 lib/data/years.dart diff --git a/lib/data/years.dart b/lib/data/years.dart new file mode 100644 index 000000000..9e9c6894c --- /dev/null +++ b/lib/data/years.dart @@ -0,0 +1,23 @@ +import 'package:photos/utils/date_time_util.dart'; + +class YearsData { + final List yearsData = []; + YearsData._privateConstructor() { + for (int year = 1970; year <= currentYear; year++) { + yearsData.add( + YearData(year.toString(), year, [ + DateTime(year).microsecondsSinceEpoch, + DateTime(year + 1).microsecondsSinceEpoch, + ]), + ); + } + } + static final YearsData instance = YearsData._privateConstructor(); +} + +class YearData { + final String yearInString; + final int yearInInt; + final List duration; + YearData(this.yearInString, this.yearInInt, this.duration); +} diff --git a/lib/ui/viewer/search/search_widget.dart b/lib/ui/viewer/search/search_widget.dart index e1848c942..222eb7c67 100644 --- a/lib/ui/viewer/search/search_widget.dart +++ b/lib/ui/viewer/search/search_widget.dart @@ -171,11 +171,11 @@ class _SearchWidgetState extends State { Completer completer, List allResults, ) async { - final queryAsIntForYear = int.tryParse(query); - if (_isYearValid(queryAsIntForYear)) { + final queryAsInt = int.tryParse(query); + if (_isYearValid(queryAsInt)) { final yearResult = - await _searchService.getYearSearchResults(queryAsIntForYear); - allResults.add(yearResult); //only one year will be returned + await _searchService.getYearSearchResults(queryAsInt, query); + allResults.add(yearResult); } final holidayResults = await _searchService.getHolidaySearchResults(query); @@ -196,6 +196,6 @@ class _SearchWidgetState extends State { } bool _isYearValid(int year) { - return year != null && year >= 1970 && year <= currentYear; + return year != null && year <= currentYear; } }