From 733100f6ec6939eff982a5aab228e6e02e96d5af Mon Sep 17 00:00:00 2001 From: Yaros Date: Thu, 19 Feb 2026 14:08:50 +0100 Subject: [PATCH] refactor: rename customtimerange variables --- .../repositories/map.repository.dart | 4 +-- .../repositories/timeline.repository.dart | 12 ++++---- .../presentation/widgets/map/map.state.dart | 24 +++++---------- .../widgets/map/map_settings_sheet.dart | 10 +++---- .../map_settings/map_custom_time_range.dart | 30 +++++++++---------- 5 files changed, 35 insertions(+), 45 deletions(-) diff --git a/mobile/lib/infrastructure/repositories/map.repository.dart b/mobile/lib/infrastructure/repositories/map.repository.dart index 43a8e3d1bc..a7652d0678 100644 --- a/mobile/lib/infrastructure/repositories/map.repository.dart +++ b/mobile/lib/infrastructure/repositories/map.repository.dart @@ -27,8 +27,8 @@ class DriftMapRepository extends DriftDatabaseRepository { condition = condition & _db.remoteAssetEntity.isFavorite.equals(true); } - final from = options.customTimeRange.from; - final to = options.customTimeRange.to; + final from = options.timeRange.from; + final to = options.timeRange.to; if (from != null || to != null) { if (from != null) { diff --git a/mobile/lib/infrastructure/repositories/timeline.repository.dart b/mobile/lib/infrastructure/repositories/timeline.repository.dart index f620413bd2..70b4701eb0 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 TimeRange customTimeRange; + final TimeRange timeRange; const TimelineMapOptions({ required this.bounds, @@ -30,7 +30,7 @@ class TimelineMapOptions { this.includeArchived = false, this.withPartners = false, this.relativeDays = 0, - this.customTimeRange = const TimeRange(), + this.timeRange = const TimeRange(), }); } @@ -531,8 +531,8 @@ class DriftTimelineRepository extends DriftDatabaseRepository { query.where(_db.remoteAssetEntity.isFavorite.equals(true)); } - final from = options.customTimeRange.from; - final to = options.customTimeRange.to; + final from = options.timeRange.from; + final to = options.timeRange.to; if (from != null || to != null) { // Use custom from/to filters @@ -585,8 +585,8 @@ class DriftTimelineRepository extends DriftDatabaseRepository { query.where(_db.remoteAssetEntity.isFavorite.equals(true)); } - final from = options.customTimeRange.from; - final to = options.customTimeRange.to; + final from = options.timeRange.from; + final to = options.timeRange.to; if (from != null || to != null) { // Use custom from/to filters diff --git a/mobile/lib/presentation/widgets/map/map.state.dart b/mobile/lib/presentation/widgets/map/map.state.dart index 565658a3ad..e198e2f2c5 100644 --- a/mobile/lib/presentation/widgets/map/map.state.dart +++ b/mobile/lib/presentation/widgets/map/map.state.dart @@ -30,7 +30,7 @@ class MapState { final bool includeArchived; final bool withPartners; final int relativeDays; - final TimeRange customTimeRange; + final TimeRange timeRange; const MapState({ this.themeMode = ThemeMode.system, @@ -39,7 +39,7 @@ class MapState { this.includeArchived = false, this.withPartners = false, this.relativeDays = 0, - this.customTimeRange = const TimeRange(), + this.timeRange = const TimeRange(), }); @override @@ -57,7 +57,7 @@ class MapState { bool? includeArchived, bool? withPartners, int? relativeDays, - TimeRange? customTimeRange, + TimeRange? timeRange, }) { return MapState( bounds: bounds ?? this.bounds, @@ -66,7 +66,7 @@ class MapState { includeArchived: includeArchived ?? this.includeArchived, withPartners: withPartners ?? this.withPartners, relativeDays: relativeDays ?? this.relativeDays, - customTimeRange: customTimeRange ?? this.customTimeRange, + timeRange: timeRange ?? this.timeRange, ); } @@ -75,8 +75,7 @@ class MapState { onlyFavorites: onlyFavorites, includeArchived: includeArchived, withPartners: withPartners, - relativeDays: relativeDays, - customTimeRange: customTimeRange, + timeRange: timeRange, ); } @@ -117,20 +116,14 @@ class MapStateNotifier extends Notifier { EventStream.shared.emit(const MapMarkerReloadEvent()); } - void setRelativeTime(int relativeDays) { - ref.read(appSettingsServiceProvider).setSetting(AppSettingsEnum.mapRelativeDate, relativeDays); - state = state.copyWith(relativeDays: relativeDays); - EventStream.shared.emit(const MapMarkerReloadEvent()); - } - - void setCustomTimeRange(TimeRange range) { + void setTimeRange(TimeRange range) { ref .read(appSettingsServiceProvider) .setSetting(AppSettingsEnum.mapCustomFrom, range.from == null ? "" : range.from!.toIso8601String()); ref .read(appSettingsServiceProvider) .setSetting(AppSettingsEnum.mapCustomTo, range.to == null ? "" : range.to!.toIso8601String()); - state = state.copyWith(customTimeRange: range); + state = state.copyWith(timeRange: range); EventStream.shared.emit(const MapMarkerReloadEvent()); } @@ -144,9 +137,8 @@ class MapStateNotifier extends Notifier { onlyFavorites: appSettingsService.getSetting(AppSettingsEnum.mapShowFavoriteOnly), includeArchived: appSettingsService.getSetting(AppSettingsEnum.mapIncludeArchived), withPartners: appSettingsService.getSetting(AppSettingsEnum.mapwithPartners), - relativeDays: appSettingsService.getSetting(AppSettingsEnum.mapRelativeDate), bounds: LatLngBounds(northeast: const LatLng(0, 0), southwest: const LatLng(0, 0)), - customTimeRange: TimeRange( + timeRange: 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 d467730a8a..0d0ff8f39d 100644 --- a/mobile/lib/presentation/widgets/map/map_settings_sheet.dart +++ b/mobile/lib/presentation/widgets/map/map_settings_sheet.dart @@ -21,7 +21,7 @@ class _DriftMapSettingsSheetState extends ConsumerState { void initState() { super.initState(); final mapState = ref.read(mapStateProvider); - final timeRange = mapState.customTimeRange; + final timeRange = mapState.timeRange; useCustomRange = timeRange.from != null || timeRange.to != null; } @@ -64,10 +64,10 @@ class _DriftMapSettingsSheetState extends ConsumerState { onChanged: (withPartners) => ref.read(mapStateProvider.notifier).switchWithPartners(withPartners), ), if (useCustomRange) ...[ - MapCustomTimeRange( - customTimeRange: mapState.customTimeRange, + MapTimeRange( + timeRange: mapState.timeRange, onChanged: (range) { - ref.read(mapStateProvider.notifier).setCustomTimeRange(range); + ref.read(mapStateProvider.notifier).setTimeRange(range); }, ), Align( @@ -76,7 +76,7 @@ class _DriftMapSettingsSheetState extends ConsumerState { onPressed: () => setState(() { useCustomRange = false; ref.read(mapStateProvider.notifier).setRelativeTime(0); - ref.read(mapStateProvider.notifier).setCustomTimeRange(const TimeRange()); + ref.read(mapStateProvider.notifier).setTimeRange(const TimeRange()); }), child: Text("remove_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 00a952a63b..60e7f57951 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 @@ -3,10 +3,10 @@ import 'package:immich_mobile/extensions/translate_extensions.dart'; import 'package:immich_mobile/presentation/widgets/map/map.state.dart'; import 'package:intl/intl.dart'; -class MapCustomTimeRange extends StatelessWidget { - const MapCustomTimeRange({super.key, required this.customTimeRange, required this.onChanged}); +class MapTimeRange extends StatelessWidget { + const MapTimeRange({super.key, required this.timeRange, required this.onChanged}); - final TimeRange customTimeRange; + final TimeRange timeRange; final Function(TimeRange) onChanged; @override @@ -17,44 +17,42 @@ class MapCustomTimeRange extends StatelessWidget { ListTile( title: Text("date_after".t(context: context)), subtitle: Text( - customTimeRange.from != null - ? DateFormat.yMMMd().add_jm().format(customTimeRange.from!) + timeRange.from != null + ? DateFormat.yMMMd().add_jm().format(timeRange.from!) : "not_set".t(context: context), ), - trailing: customTimeRange.from != null - ? IconButton(icon: const Icon(Icons.close), onPressed: () => onChanged(customTimeRange.clearFrom())) + trailing: timeRange.from != null + ? IconButton(icon: const Icon(Icons.close), onPressed: () => onChanged(timeRange.clearFrom())) : null, onTap: () async { final picked = await showDatePicker( context: context, - initialDate: customTimeRange.from ?? DateTime.now(), + initialDate: timeRange.from ?? DateTime.now(), firstDate: DateTime(1970), lastDate: DateTime.now(), ); if (picked != null) { - onChanged(customTimeRange.copyWith(from: picked)); + onChanged(timeRange.copyWith(from: picked)); } }, ), ListTile( title: Text("date_before".t(context: context)), subtitle: Text( - customTimeRange.to != null - ? DateFormat.yMMMd().add_jm().format(customTimeRange.to!) - : "not_set".t(context: context), + timeRange.to != null ? DateFormat.yMMMd().add_jm().format(timeRange.to!) : "not_set".t(context: context), ), - trailing: customTimeRange.to != null - ? IconButton(icon: const Icon(Icons.close), onPressed: () => onChanged(customTimeRange.clearTo())) + trailing: timeRange.to != null + ? IconButton(icon: const Icon(Icons.close), onPressed: () => onChanged(timeRange.clearTo())) : null, onTap: () async { final picked = await showDatePicker( context: context, - initialDate: customTimeRange.to ?? DateTime.now(), + initialDate: timeRange.to ?? DateTime.now(), firstDate: DateTime(1970), lastDate: DateTime.now(), ); if (picked != null) { - onChanged(customTimeRange.copyWith(to: picked)); + onChanged(timeRange.copyWith(to: picked)); } }, ),