more refactoring
This commit is contained in:
parent
742b8a76bc
commit
bffc967e21
8 changed files with 51 additions and 146 deletions
|
@ -1,4 +1,10 @@
|
|||
import 'package:photos/models/search/holiday_search_result.dart';
|
||||
class HolidayData {
|
||||
final String name;
|
||||
final int month;
|
||||
final int day;
|
||||
|
||||
const HolidayData(this.name, {required this.month, required this.day});
|
||||
}
|
||||
|
||||
const List<HolidayData> allHolidays = [
|
||||
HolidayData('New Year', month: 1, day: 1),
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import 'package:photos/models/search/month_search_result.dart';
|
||||
|
||||
List<MonthData> allMonths = [
|
||||
MonthData('January', 1),
|
||||
MonthData('February', 2),
|
||||
|
@ -14,3 +12,10 @@ List<MonthData> allMonths = [
|
|||
MonthData('November', 11),
|
||||
MonthData('December', 12),
|
||||
];
|
||||
|
||||
class MonthData {
|
||||
final String name;
|
||||
final int monthNumber;
|
||||
|
||||
MonthData(this.name, this.monthNumber);
|
||||
}
|
||||
|
|
|
@ -1,29 +1,30 @@
|
|||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/search/search_result.dart';
|
||||
|
||||
class LocationSearchResult extends SearchResult {
|
||||
final String location;
|
||||
final List<File> files;
|
||||
class GenericSearchResult extends SearchResult {
|
||||
final String _name;
|
||||
final List<File> _files;
|
||||
final ResultType _type;
|
||||
|
||||
LocationSearchResult(this.location, this.files);
|
||||
GenericSearchResult(this._type, this._name, this._files);
|
||||
|
||||
@override
|
||||
String name() {
|
||||
return location;
|
||||
return _name;
|
||||
}
|
||||
|
||||
@override
|
||||
ResultType type() {
|
||||
return ResultType.location;
|
||||
return _type;
|
||||
}
|
||||
|
||||
@override
|
||||
File previewThumbnail() {
|
||||
return files.first;
|
||||
return _files.first;
|
||||
}
|
||||
|
||||
@override
|
||||
List<File> resultFiles() {
|
||||
return files;
|
||||
return _files;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/search/search_result.dart';
|
||||
|
||||
class HolidaySearchResult extends SearchResult {
|
||||
final String holidayName;
|
||||
final List<File> files;
|
||||
|
||||
HolidaySearchResult(this.holidayName, this.files);
|
||||
|
||||
@override
|
||||
String name() {
|
||||
return holidayName;
|
||||
}
|
||||
|
||||
@override
|
||||
ResultType type() {
|
||||
return ResultType.event;
|
||||
}
|
||||
|
||||
@override
|
||||
File previewThumbnail() {
|
||||
return files.first;
|
||||
}
|
||||
|
||||
@override
|
||||
List<File> resultFiles() {
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
class HolidayData {
|
||||
final String name;
|
||||
final int month;
|
||||
final int day;
|
||||
|
||||
const HolidayData(this.name, {required this.month, required this.day});
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/search/search_result.dart';
|
||||
|
||||
class MonthSearchResult extends SearchResult {
|
||||
final String month;
|
||||
final List<File> files;
|
||||
|
||||
MonthSearchResult(this.month, this.files);
|
||||
|
||||
@override
|
||||
String name() {
|
||||
return month;
|
||||
}
|
||||
|
||||
@override
|
||||
ResultType type() {
|
||||
return ResultType.month;
|
||||
}
|
||||
|
||||
@override
|
||||
File previewThumbnail() {
|
||||
return files.first;
|
||||
}
|
||||
|
||||
@override
|
||||
List<File> resultFiles() {
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
class MonthData {
|
||||
final String name;
|
||||
final int monthNumber;
|
||||
|
||||
MonthData(this.name, this.monthNumber);
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/search/search_result.dart';
|
||||
|
||||
class YearSearchResult extends SearchResult {
|
||||
final String year;
|
||||
final List<File> files;
|
||||
|
||||
YearSearchResult(this.year, this.files);
|
||||
|
||||
@override
|
||||
String name() {
|
||||
return year;
|
||||
}
|
||||
|
||||
@override
|
||||
ResultType type() {
|
||||
return ResultType.year;
|
||||
}
|
||||
|
||||
@override
|
||||
File previewThumbnail() {
|
||||
return files.first;
|
||||
}
|
||||
|
||||
@override
|
||||
List<File> resultFiles() {
|
||||
return files;
|
||||
}
|
||||
}
|
|
@ -15,11 +15,9 @@ import 'package:photos/models/collection_items.dart';
|
|||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/location.dart';
|
||||
import 'package:photos/models/search/album_search_result.dart';
|
||||
import 'package:photos/models/search/holiday_search_result.dart';
|
||||
import 'package:photos/models/search/generic_search_result.dart';
|
||||
import 'package:photos/models/search/location_api_response.dart';
|
||||
import 'package:photos/models/search/location_search_result.dart';
|
||||
import 'package:photos/models/search/month_search_result.dart';
|
||||
import 'package:photos/models/search/year_search_result.dart';
|
||||
import 'package:photos/models/search/search_result.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/utils/date_time_util.dart';
|
||||
|
||||
|
@ -78,10 +76,10 @@ class SearchService {
|
|||
_cachedFilesFuture = null;
|
||||
}
|
||||
|
||||
Future<List<LocationSearchResult>> getLocationSearchResults(
|
||||
Future<List<GenericSearchResult>> getLocationSearchResults(
|
||||
String query,
|
||||
) async {
|
||||
final List<LocationSearchResult> locationSearchResults = [];
|
||||
final List<GenericSearchResult> searchResults = [];
|
||||
try {
|
||||
final List<File> allFiles = await _getAllFiles();
|
||||
|
||||
|
@ -109,15 +107,16 @@ class SearchService {
|
|||
(first, second) => second.creationTime.compareTo(first.creationTime),
|
||||
);
|
||||
if (filesInLocation.isNotEmpty) {
|
||||
locationSearchResults.add(
|
||||
LocationSearchResult(locationData.place, filesInLocation),
|
||||
searchResults.add(
|
||||
GenericSearchResult(
|
||||
ResultType.location, locationData.place, filesInLocation),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
_logger.severe(e);
|
||||
}
|
||||
return locationSearchResults;
|
||||
return searchResults;
|
||||
}
|
||||
|
||||
// getFilteredCollectionsWithThumbnail removes deleted or archived or
|
||||
|
@ -150,16 +149,17 @@ class SearchService {
|
|||
return collectionSearchResults;
|
||||
}
|
||||
|
||||
Future<List<YearSearchResult>> getYearSearchResults(
|
||||
Future<List<GenericSearchResult>> getYearSearchResults(
|
||||
String yearFromQuery,
|
||||
) async {
|
||||
final List<YearSearchResult> yearSearchResults = [];
|
||||
final List<GenericSearchResult> searchResults = [];
|
||||
for (var yearData in YearsData.instance.yearsData) {
|
||||
if (yearData.year.startsWith(yearFromQuery)) {
|
||||
final List<File> filesInYear = await _getFilesInYear(yearData.duration);
|
||||
if (filesInYear.isNotEmpty) {
|
||||
yearSearchResults.add(
|
||||
YearSearchResult(
|
||||
searchResults.add(
|
||||
GenericSearchResult(
|
||||
ResultType.year,
|
||||
yearData.year,
|
||||
filesInYear,
|
||||
),
|
||||
|
@ -167,13 +167,13 @@ class SearchService {
|
|||
}
|
||||
}
|
||||
}
|
||||
return yearSearchResults;
|
||||
return searchResults;
|
||||
}
|
||||
|
||||
Future<List<HolidaySearchResult>> getHolidaySearchResults(
|
||||
Future<List<GenericSearchResult>> getHolidaySearchResults(
|
||||
String query,
|
||||
) async {
|
||||
final List<HolidaySearchResult> holidaySearchResults = [];
|
||||
final List<GenericSearchResult> searchResults = [];
|
||||
|
||||
final nonCaseSensitiveRegexForQuery = RegExp(query, caseSensitive: false);
|
||||
|
||||
|
@ -185,18 +185,18 @@ class SearchService {
|
|||
null,
|
||||
order: 'DESC',
|
||||
);
|
||||
if (matchedFiles.isNotEmpty) {
|
||||
holidaySearchResults.add(
|
||||
HolidaySearchResult(holiday.name, matchedFiles),
|
||||
if (matchedFiles.\\isNotEmpty) {
|
||||
searchResults.add(
|
||||
GenericSearchResult(ResultType.event, holiday.name, matchedFiles),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return holidaySearchResults;
|
||||
return searchResults;
|
||||
}
|
||||
|
||||
Future<List<MonthSearchResult>> getMonthSearchResults(String query) async {
|
||||
final List<MonthSearchResult> monthSearchResults = [];
|
||||
Future<List<GenericSearchResult>> getMonthSearchResults(String query) async {
|
||||
final List<GenericSearchResult> searchResults = [];
|
||||
final nonCaseSensitiveRegexForQuery = RegExp(query, caseSensitive: false);
|
||||
|
||||
for (var month in allMonths) {
|
||||
|
@ -208,8 +208,9 @@ class SearchService {
|
|||
order: 'DESC',
|
||||
);
|
||||
if (matchedFiles.isNotEmpty) {
|
||||
monthSearchResults.add(
|
||||
MonthSearchResult(
|
||||
searchResults.add(
|
||||
GenericSearchResult(
|
||||
ResultType.month,
|
||||
month.name,
|
||||
matchedFiles,
|
||||
),
|
||||
|
@ -218,7 +219,7 @@ class SearchService {
|
|||
}
|
||||
}
|
||||
|
||||
return monthSearchResults;
|
||||
return searchResults;
|
||||
}
|
||||
|
||||
Future<List<File>> _getFilesInYear(List<int> durationOfYear) async {
|
||||
|
|
|
@ -6,11 +6,8 @@ import 'package:photos/db/files_db.dart';
|
|||
import 'package:photos/ente_theme_data.dart';
|
||||
import 'package:photos/models/search/album_search_result.dart';
|
||||
import 'package:photos/models/search/file_search_result.dart';
|
||||
import 'package:photos/models/search/holiday_search_result.dart';
|
||||
import 'package:photos/models/search/location_search_result.dart';
|
||||
import 'package:photos/models/search/month_search_result.dart';
|
||||
import 'package:photos/models/search/generic_search_result.dart';
|
||||
import 'package:photos/models/search/search_result.dart';
|
||||
import 'package:photos/models/search/year_search_result.dart';
|
||||
import 'package:photos/ui/viewer/gallery/collection_page.dart';
|
||||
import 'package:photos/ui/viewer/search/result/file_result_widget.dart';
|
||||
import 'package:photos/ui/viewer/search/result/search_result_widget.dart';
|
||||
|
@ -78,10 +75,7 @@ class SearchSuggestionsWidget extends StatelessWidget {
|
|||
);
|
||||
} else if (result is FileSearchResult) {
|
||||
return FileSearchResultWidget(result);
|
||||
} else if (result is YearSearchResult ||
|
||||
result is MonthSearchResult ||
|
||||
result is LocationSearchResult ||
|
||||
result is HolidaySearchResult) {
|
||||
} else if (result is GenericSearchResult) {
|
||||
return SearchResultWidget(result);
|
||||
} else {
|
||||
Logger('SearchSuggestionsWidget')
|
||||
|
|
Loading…
Reference in a new issue