[mob][photos] Create FilterTypeNames enum and enforce that a new entry is added here any time a new class extends HierarchicalSearchFilter

This commit is contained in:
ashilkn
2024-10-26 18:40:57 +05:30
parent 1c3bdb6d69
commit 2c4c25feb3
8 changed files with 26 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ class AlbumFilter extends HierarchicalSearchFilter {
required this.collectionID,
required this.albumName,
required this.occurrence,
super.filterTypeName = "albumFilter",
super.matchedUploadedIDs,
});

View File

@@ -10,6 +10,7 @@ class ContactsFilter extends HierarchicalSearchFilter {
ContactsFilter({
required this.user,
required this.occurrence,
super.filterTypeName = "contactsFilter",
super.matchedUploadedIDs,
});

View File

@@ -15,6 +15,7 @@ class FaceFilter extends HierarchicalSearchFilter {
required this.faceName,
required this.faceFile,
required this.occurrence,
super.filterTypeName = "faceFilter",
super.matchedUploadedIDs,
}) : assert(
personId != null || clusterId != null,

View File

@@ -27,6 +27,7 @@ class FileTypeFilter extends HierarchicalSearchFilter {
required this.fileType,
required this.typeName,
required this.occurrence,
super.filterTypeName = "fileTypeFilter",
super.matchedUploadedIDs,
});

View File

@@ -4,17 +4,34 @@ import "package:photos/models/file/file.dart";
int kMostRelevantFilter = 10000;
int kLeastRelevantFilter = -1;
enum FilterTypeNames {
albumFilter,
contactsFilter,
faceFilter,
fileTypeFilter,
locationFilter,
magicFilter,
topLevelGenericFilter,
}
abstract class HierarchicalSearchFilter {
//These matches should be from list of all files in db and not just all files
//in gallery since this is used as cache for faster filtering when
//adding/removing applied filters. An exception where results can be all files
//in gallery is when the filter is the initial filter (top level) of the
//gallery.
final String filterTypeName;
final Set<int> matchedUploadedIDs;
bool isApplied = false;
HierarchicalSearchFilter({matchedUploadedIDs})
: matchedUploadedIDs = matchedUploadedIDs ?? {};
HierarchicalSearchFilter({required this.filterTypeName, matchedUploadedIDs})
: matchedUploadedIDs = matchedUploadedIDs ?? {},
assert(
FilterTypeNames.values
.map((e) => e.toString().split(".").last)
.contains(filterTypeName),
"filterTypeName = $filterTypeName is not a valid filter type in FilterTypeNames enum. Please add it to the enum if it's missing or else, cross check spelling ",
);
String name();
IconData? icon();

View File

@@ -11,6 +11,7 @@ class LocationFilter extends HierarchicalSearchFilter {
LocationFilter({
required this.locationTag,
required this.occurrence,
super.filterTypeName = "locationFilter",
super.matchedUploadedIDs,
});

View File

@@ -9,6 +9,7 @@ class MagicFilter extends HierarchicalSearchFilter {
MagicFilter({
required this.filterName,
required this.occurrence,
super.filterTypeName = "magicFilter",
super.matchedUploadedIDs,
});

View File

@@ -19,6 +19,7 @@ class TopLevelGenericFilter extends HierarchicalSearchFilter {
required this.occurrence,
required this.filterResultType,
required super.matchedUploadedIDs,
super.filterTypeName = "topLevelGenericFilter",
this.filterIcon,
});