#1549 week day filters
This commit is contained in:
parent
91cfe01af3
commit
4b87717cd2
7 changed files with 76 additions and 1 deletions
|
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
## <a id="unreleased"></a>[Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Search: week day filters
|
||||
|
||||
### Changed
|
||||
|
||||
- revert to Skia rendering engine
|
||||
|
|
|
@ -21,6 +21,7 @@ import 'package:aves/model/filters/set_and.dart';
|
|||
import 'package:aves/model/filters/set_or.dart';
|
||||
import 'package:aves/model/filters/trash.dart';
|
||||
import 'package:aves/model/filters/type.dart';
|
||||
import 'package:aves/model/filters/weekday.dart';
|
||||
import 'package:aves/theme/colors.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
@ -36,11 +37,13 @@ abstract class CollectionFilter extends Equatable implements Comparable<Collecti
|
|||
SetAndFilter.type,
|
||||
SetOrFilter.type,
|
||||
MimeFilter.type,
|
||||
AlbumGroupFilter.type,
|
||||
DynamicAlbumFilter.type,
|
||||
StoredAlbumFilter.type,
|
||||
TypeFilter.type,
|
||||
RecentlyAddedFilter.type,
|
||||
DateFilter.type,
|
||||
WeekDayFilter.type,
|
||||
LocationFilter.type,
|
||||
CoordinateFilter.type,
|
||||
FavouriteFilter.type,
|
||||
|
@ -98,6 +101,8 @@ abstract class CollectionFilter extends Equatable implements Comparable<Collecti
|
|||
return TypeFilter.fromMap(jsonMap);
|
||||
case TrashFilter.type:
|
||||
return TrashFilter.fromMap(jsonMap);
|
||||
case WeekDayFilter.type:
|
||||
return WeekDayFilter.fromMap(jsonMap);
|
||||
}
|
||||
debugPrint('failed to deserialize filter from JSON map=$jsonMap');
|
||||
return null;
|
||||
|
|
57
lib/model/filters/weekday.dart
Normal file
57
lib/model/filters/weekday.dart
Normal file
|
@ -0,0 +1,57 @@
|
|||
import 'package:aves/model/filters/filters.dart';
|
||||
import 'package:aves/theme/icons.dart';
|
||||
import 'package:aves/widgets/common/extensions/build_context.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class WeekDayFilter extends CollectionFilter {
|
||||
static const type = 'weekday';
|
||||
|
||||
late final int weekday;
|
||||
late final EntryFilter _test;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [weekday, reversed];
|
||||
|
||||
WeekDayFilter(this.weekday, {super.reversed = false}) {
|
||||
_test = (entry) => entry.bestDate?.weekday == weekday;
|
||||
}
|
||||
|
||||
factory WeekDayFilter.fromMap(Map<String, dynamic> json) {
|
||||
return WeekDayFilter(
|
||||
json['weekday'] as int,
|
||||
reversed: json['reversed'] ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() => {
|
||||
'type': type,
|
||||
'weekday': weekday,
|
||||
'reversed': reversed,
|
||||
};
|
||||
|
||||
@override
|
||||
EntryFilter get positiveTest => _test;
|
||||
|
||||
@override
|
||||
bool get exclusiveProp => true;
|
||||
|
||||
@override
|
||||
String get universalLabel => weekday.toString();
|
||||
|
||||
@override
|
||||
String getLabel(BuildContext context) {
|
||||
final dateSymbols = DateFormat(null, context.locale).dateSymbols;
|
||||
return dateSymbols.STANDALONEWEEKDAYS[weekday % 7];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget? iconBuilder(BuildContext context, double size, {bool allowGenericIcon = true}) => Icon(AIcons.dateWeekday, size: size);
|
||||
|
||||
@override
|
||||
String get category => type;
|
||||
|
||||
@override
|
||||
String get key => '$type-$reversed-$weekday';
|
||||
}
|
|
@ -72,6 +72,7 @@ class AIcons {
|
|||
static const dateByMonth = Symbols.calendar_month;
|
||||
static const dateRecent = Symbols.today;
|
||||
static const dateUndated = Symbols.event_busy;
|
||||
static const dateWeekday = Symbols.today;
|
||||
static const geoBounds = Symbols.public;
|
||||
static const location = Symbols.place;
|
||||
static const locationUnlocated = Symbols.location_off;
|
||||
|
|
|
@ -15,6 +15,7 @@ import 'package:aves/model/filters/rating.dart';
|
|||
import 'package:aves/model/filters/recent.dart';
|
||||
import 'package:aves/model/filters/set_and.dart';
|
||||
import 'package:aves/model/filters/type.dart';
|
||||
import 'package:aves/model/filters/weekday.dart';
|
||||
import 'package:aves/model/grouping/common.dart';
|
||||
import 'package:aves/model/settings/settings.dart';
|
||||
import 'package:aves/model/source/album.dart';
|
||||
|
@ -67,6 +68,7 @@ class CollectionSearchDelegate extends AvesSearchDelegate with FeedbackMixin, Va
|
|||
];
|
||||
|
||||
static final _monthFilters = List.generate(12, (i) => DateFilter(DateLevel.m, DateTime(1, i + 1)));
|
||||
static final _weekdayFilters = List.generate(7, (i) => WeekDayFilter(i + 1));
|
||||
|
||||
CollectionSearchDelegate({
|
||||
required super.searchFieldLabel,
|
||||
|
@ -200,6 +202,7 @@ class CollectionSearchDelegate extends AvesSearchDelegate with FeedbackMixin, Va
|
|||
DateFilter.onThisDay,
|
||||
RecentlyAddedFilter.instance,
|
||||
..._monthFilters,
|
||||
..._weekdayFilters,
|
||||
].where((f) => containQuery(f.getLabel(context))).toList();
|
||||
return _buildFilterRow(
|
||||
context: context,
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:aves/model/filters/favourite.dart';
|
|||
import 'package:aves/model/filters/mime.dart';
|
||||
import 'package:aves/model/filters/rating.dart';
|
||||
import 'package:aves/model/filters/type.dart';
|
||||
import 'package:aves/model/filters/weekday.dart';
|
||||
import 'package:aves/model/settings/settings.dart';
|
||||
import 'package:aves/model/source/collection_lens.dart';
|
||||
import 'package:aves/ref/mime_types.dart';
|
||||
|
@ -130,7 +131,7 @@ class _BasicSectionState extends State<BasicSection> {
|
|||
if (entry.isImage && entry.is360) TypeFilter.panorama,
|
||||
if (entry.isPureVideo && entry.is360) TypeFilter.sphericalVideo,
|
||||
if (entry.isPureVideo && !entry.is360) MimeFilter.video,
|
||||
if (dateTime != null) DateFilter(DateLevel.ymd, dateTime.date),
|
||||
if (dateTime != null) ...[DateFilter(DateLevel.ymd, dateTime.date), WeekDayFilter(dateTime.weekday)],
|
||||
if (album != null) StoredAlbumFilter(album, collection?.source.getStoredAlbumDisplayName(context, album)),
|
||||
if (entry.rating != 0) RatingFilter(entry.rating),
|
||||
...tags.map(TagFilter.new),
|
||||
|
|
|
@ -18,6 +18,7 @@ import 'package:aves/model/filters/recent.dart';
|
|||
import 'package:aves/model/filters/set_and.dart';
|
||||
import 'package:aves/model/filters/set_or.dart';
|
||||
import 'package:aves/model/filters/type.dart';
|
||||
import 'package:aves/model/filters/weekday.dart';
|
||||
import 'package:aves/model/grouping/common.dart';
|
||||
import 'package:aves/services/common/services.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
@ -80,6 +81,9 @@ void main() {
|
|||
final type = TypeFilter.sphericalVideo;
|
||||
expect(type, jsonRoundTrip(type));
|
||||
|
||||
final weekday = WeekDayFilter(5);
|
||||
expect(weekday, jsonRoundTrip(weekday));
|
||||
|
||||
// covered
|
||||
|
||||
final album = StoredAlbumFilter('path/to/album', 'album');
|
||||
|
|
Loading…
Reference in a new issue