diff --git a/mobile/lib/infrastructure/repositories/map.repository.dart b/mobile/lib/infrastructure/repositories/map.repository.dart index fbac8de02c..43a8e3d1bc 100644 --- a/mobile/lib/infrastructure/repositories/map.repository.dart +++ b/mobile/lib/infrastructure/repositories/map.repository.dart @@ -27,12 +27,15 @@ class DriftMapRepository extends DriftDatabaseRepository { condition = condition & _db.remoteAssetEntity.isFavorite.equals(true); } - if (options.customTimeRange.isValid) { - if (options.customTimeRange.from != null) { - condition = condition & _db.remoteAssetEntity.createdAt.isBiggerOrEqualValue(options.customTimeRange.from!); + final from = options.customTimeRange.from; + final to = options.customTimeRange.to; + + if (from != null || to != null) { + if (from != null) { + condition = condition & _db.remoteAssetEntity.createdAt.isBiggerOrEqualValue(from); } - if (options.customTimeRange.to != null) { - condition = condition & _db.remoteAssetEntity.createdAt.isSmallerOrEqualValue(options.customTimeRange.to!); + if (to != null) { + condition = condition & _db.remoteAssetEntity.createdAt.isSmallerOrEqualValue(to); } } else if (options.relativeDays > 0) { final fromDate = DateTime.now().subtract(Duration(days: options.relativeDays)); diff --git a/mobile/lib/infrastructure/repositories/timeline.repository.dart b/mobile/lib/infrastructure/repositories/timeline.repository.dart index b0fcc503c3..f620413bd2 100644 --- a/mobile/lib/infrastructure/repositories/timeline.repository.dart +++ b/mobile/lib/infrastructure/repositories/timeline.repository.dart @@ -22,7 +22,7 @@ class TimelineMapOptions { final bool includeArchived; final bool withPartners; final int relativeDays; - final CustomTimeRange customTimeRange; + final TimeRange customTimeRange; const TimelineMapOptions({ required this.bounds, @@ -30,7 +30,7 @@ class TimelineMapOptions { this.includeArchived = false, this.withPartners = false, this.relativeDays = 0, - this.customTimeRange = const CustomTimeRange(), + this.customTimeRange = const TimeRange(), }); } @@ -531,13 +531,16 @@ class DriftTimelineRepository extends DriftDatabaseRepository { query.where(_db.remoteAssetEntity.isFavorite.equals(true)); } - if (options.customTimeRange.isValid) { + final from = options.customTimeRange.from; + final to = options.customTimeRange.to; + + if (from != null || to != null) { // Use custom from/to filters - if (options.customTimeRange.from != null) { - query.where(_db.remoteAssetEntity.createdAt.isBiggerOrEqualValue(options.customTimeRange.from!)); + if (from != null) { + query.where(_db.remoteAssetEntity.createdAt.isBiggerOrEqualValue(from)); } - if (options.customTimeRange.to != null) { - query.where(_db.remoteAssetEntity.createdAt.isSmallerOrEqualValue(options.customTimeRange.to!)); + if (to != null) { + query.where(_db.remoteAssetEntity.createdAt.isSmallerOrEqualValue(to)); } } else if (options.relativeDays > 0) { // Use relative days @@ -582,13 +585,16 @@ class DriftTimelineRepository extends DriftDatabaseRepository { query.where(_db.remoteAssetEntity.isFavorite.equals(true)); } - if (options.customTimeRange.isValid) { + final from = options.customTimeRange.from; + final to = options.customTimeRange.to; + + if (from != null || to != null) { // Use custom from/to filters - if (options.customTimeRange.from != null) { - query.where(_db.remoteAssetEntity.createdAt.isBiggerOrEqualValue(options.customTimeRange.from!)); + if (from != null) { + query.where(_db.remoteAssetEntity.createdAt.isBiggerOrEqualValue(from)); } - if (options.customTimeRange.to != null) { - query.where(_db.remoteAssetEntity.createdAt.isSmallerOrEqualValue(options.customTimeRange.to!)); + if (to != null) { + query.where(_db.remoteAssetEntity.createdAt.isSmallerOrEqualValue(to)); } } else if (options.relativeDays > 0) { // Use relative days diff --git a/mobile/lib/presentation/widgets/map/map.state.dart b/mobile/lib/presentation/widgets/map/map.state.dart index 3b5103fcb3..565658a3ad 100644 --- a/mobile/lib/presentation/widgets/map/map.state.dart +++ b/mobile/lib/presentation/widgets/map/map.state.dart @@ -9,20 +9,18 @@ import 'package:immich_mobile/providers/map/map_state.provider.dart'; import 'package:immich_mobile/services/app_settings.service.dart'; import 'package:maplibre_gl/maplibre_gl.dart'; -class CustomTimeRange { +class TimeRange { final DateTime? from; final DateTime? to; - const CustomTimeRange({this.from, this.to}); + const TimeRange({this.from, this.to}); - bool get isValid => from != null || to != null; - - CustomTimeRange copyWith({DateTime? from, DateTime? to}) { - return CustomTimeRange(from: from ?? this.from, to: to ?? this.to); + TimeRange copyWith({DateTime? from, DateTime? to}) { + return TimeRange(from: from ?? this.from, to: to ?? this.to); } - CustomTimeRange clearFrom() => CustomTimeRange(to: to); - CustomTimeRange clearTo() => CustomTimeRange(from: from); + TimeRange clearFrom() => TimeRange(to: to); + TimeRange clearTo() => TimeRange(from: from); } class MapState { @@ -32,7 +30,7 @@ class MapState { final bool includeArchived; final bool withPartners; final int relativeDays; - final CustomTimeRange customTimeRange; + final TimeRange customTimeRange; const MapState({ this.themeMode = ThemeMode.system, @@ -41,7 +39,7 @@ class MapState { this.includeArchived = false, this.withPartners = false, this.relativeDays = 0, - this.customTimeRange = const CustomTimeRange(), + this.customTimeRange = const TimeRange(), }); @override @@ -59,7 +57,7 @@ class MapState { bool? includeArchived, bool? withPartners, int? relativeDays, - CustomTimeRange? customTimeRange, + TimeRange? customTimeRange, }) { return MapState( bounds: bounds ?? this.bounds, @@ -125,7 +123,7 @@ class MapStateNotifier extends Notifier { EventStream.shared.emit(const MapMarkerReloadEvent()); } - void setCustomTimeRange(CustomTimeRange range) { + void setCustomTimeRange(TimeRange range) { ref .read(appSettingsServiceProvider) .setSetting(AppSettingsEnum.mapCustomFrom, range.from == null ? "" : range.from!.toIso8601String()); @@ -148,7 +146,7 @@ class MapStateNotifier extends Notifier { withPartners: appSettingsService.getSetting(AppSettingsEnum.mapwithPartners), relativeDays: appSettingsService.getSetting(AppSettingsEnum.mapRelativeDate), bounds: LatLngBounds(northeast: const LatLng(0, 0), southwest: const LatLng(0, 0)), - customTimeRange: CustomTimeRange( + customTimeRange: TimeRange( from: customFrom.isNotEmpty ? DateTime.parse(customFrom) : null, to: customTo.isNotEmpty ? DateTime.parse(customTo) : null, ), diff --git a/mobile/lib/presentation/widgets/map/map_settings_sheet.dart b/mobile/lib/presentation/widgets/map/map_settings_sheet.dart index e14349993f..d467730a8a 100644 --- a/mobile/lib/presentation/widgets/map/map_settings_sheet.dart +++ b/mobile/lib/presentation/widgets/map/map_settings_sheet.dart @@ -21,7 +21,8 @@ class _DriftMapSettingsSheetState extends ConsumerState { void initState() { super.initState(); final mapState = ref.read(mapStateProvider); - useCustomRange = mapState.customTimeRange.isValid; + final timeRange = mapState.customTimeRange; + useCustomRange = timeRange.from != null || timeRange.to != null; } @override @@ -75,7 +76,7 @@ class _DriftMapSettingsSheetState extends ConsumerState { onPressed: () => setState(() { useCustomRange = false; ref.read(mapStateProvider.notifier).setRelativeTime(0); - ref.read(mapStateProvider.notifier).setCustomTimeRange(const CustomTimeRange()); + ref.read(mapStateProvider.notifier).setCustomTimeRange(const TimeRange()); }), child: Text("remove_custom_date_range".t(context: context)), ), @@ -91,7 +92,7 @@ class _DriftMapSettingsSheetState extends ConsumerState { onPressed: () => setState(() { useCustomRange = true; ref.read(mapStateProvider.notifier).setRelativeTime(0); - ref.read(mapStateProvider.notifier).setCustomTimeRange(const CustomTimeRange()); + ref.read(mapStateProvider.notifier).setCustomTimeRange(const TimeRange()); }), child: Text("use_custom_date_range".t(context: context)), ), diff --git a/mobile/lib/widgets/map/map_settings/map_custom_time_range.dart b/mobile/lib/widgets/map/map_settings/map_custom_time_range.dart index 1f41e13ce8..00a952a63b 100644 --- a/mobile/lib/widgets/map/map_settings/map_custom_time_range.dart +++ b/mobile/lib/widgets/map/map_settings/map_custom_time_range.dart @@ -6,8 +6,8 @@ import 'package:intl/intl.dart'; class MapCustomTimeRange extends StatelessWidget { const MapCustomTimeRange({super.key, required this.customTimeRange, required this.onChanged}); - final CustomTimeRange customTimeRange; - final Function(CustomTimeRange) onChanged; + final TimeRange customTimeRange; + final Function(TimeRange) onChanged; @override Widget build(BuildContext context) {