refactor: rename timerange & remove isvalid

This commit is contained in:
Yaros
2026-02-19 13:23:40 +01:00
parent 39d2e14d3a
commit b0f6d5cf38
5 changed files with 43 additions and 35 deletions
@@ -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));
@@ -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
@@ -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<MapState> {
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<MapState> {
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,
),
@@ -21,7 +21,8 @@ class _DriftMapSettingsSheetState extends ConsumerState<DriftMapSettingsSheet> {
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<DriftMapSettingsSheet> {
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<DriftMapSettingsSheet> {
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)),
),
@@ -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) {