#1192 fixed path filter
This commit is contained in:
parent
652215fc13
commit
748f8b9270
2 changed files with 15 additions and 8 deletions
|
@ -9,22 +9,24 @@ class PathFilter extends CollectionFilter {
|
||||||
static const type = 'path';
|
static const type = 'path';
|
||||||
|
|
||||||
// including trailing separator
|
// including trailing separator
|
||||||
final String path;
|
late final String path;
|
||||||
|
|
||||||
// without trailing separator
|
// without trailing separator
|
||||||
final String _rootAlbum;
|
late final String _rootAlbum;
|
||||||
|
|
||||||
late final EntryFilter _test;
|
late final EntryFilter _test;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [path, reversed];
|
List<Object?> get props => [path, reversed];
|
||||||
|
|
||||||
PathFilter(this.path, {super.reversed = false}) : _rootAlbum = path.substring(0, path.length - 1) {
|
PathFilter(String path, {super.reversed = false}) {
|
||||||
|
this.path = path.endsWith(pContext.separator) ? path : '$path${pContext.separator}';
|
||||||
|
_rootAlbum = this.path.substring(0, this.path.length - 1);
|
||||||
_test = (entry) {
|
_test = (entry) {
|
||||||
final dir = entry.directory;
|
final dir = entry.directory;
|
||||||
if (dir == null) return false;
|
if (dir == null) return false;
|
||||||
// avoid string building in most cases
|
// avoid string building in most cases
|
||||||
return dir.startsWith(_rootAlbum) && '$dir${pContext.separator}'.startsWith(path);
|
return dir.startsWith(_rootAlbum) && '$dir${pContext.separator}'.startsWith(this.path);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,9 +93,14 @@ void main() {
|
||||||
final subImage = FakeMediaStoreService.newImage(subAlbum, 'image1');
|
final subImage = FakeMediaStoreService.newImage(subAlbum, 'image1');
|
||||||
final siblingImage = FakeMediaStoreService.newImage(siblingAlbum, 'image1');
|
final siblingImage = FakeMediaStoreService.newImage(siblingAlbum, 'image1');
|
||||||
|
|
||||||
final path = PathFilter('$rootAlbum/');
|
final untrailedPath = PathFilter(rootAlbum);
|
||||||
expect(path.test(rootImage), true);
|
expect(untrailedPath.test(rootImage), true);
|
||||||
expect(path.test(subImage), true);
|
expect(untrailedPath.test(subImage), true);
|
||||||
expect(path.test(siblingImage), false);
|
expect(untrailedPath.test(siblingImage), false);
|
||||||
|
|
||||||
|
final trailedPath = PathFilter('$rootAlbum/');
|
||||||
|
expect(trailedPath.test(rootImage), true);
|
||||||
|
expect(trailedPath.test(subImage), true);
|
||||||
|
expect(trailedPath.test(siblingImage), false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue