refactor: rename customtimerange variables

This commit is contained in:
Yaros
2026-02-19 14:08:50 +01:00
parent b0f6d5cf38
commit 733100f6ec
5 changed files with 35 additions and 45 deletions
@@ -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) {
@@ -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
@@ -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<MapState> {
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<MapState> {
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,
),
@@ -21,7 +21,7 @@ class _DriftMapSettingsSheetState extends ConsumerState<DriftMapSettingsSheet> {
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<DriftMapSettingsSheet> {
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<DriftMapSettingsSheet> {
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)),
),
@@ -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));
}
},
),