2026-07-30 12:39:24 -07:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
2023-11-09 17:10:56 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2026-04-17 20:01:44 +05:30
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-04-30 21:36:40 -05:00
|
|
|
import 'package:immich_mobile/models/map/map_state.model.dart';
|
2026-05-30 20:57:55 +05:30
|
|
|
import 'package:immich_mobile/providers/infrastructure/settings.provider.dart';
|
2024-09-23 21:30:23 +01:00
|
|
|
import 'package:immich_mobile/providers/server_info.provider.dart';
|
2023-08-27 05:07:35 +00:00
|
|
|
|
2026-04-17 20:01:44 +05:30
|
|
|
final mapStateNotifierProvider = NotifierProvider<MapStateNotifier, MapState>(MapStateNotifier.new);
|
2023-11-09 17:10:56 +01:00
|
|
|
|
2026-04-17 20:01:44 +05:30
|
|
|
class MapStateNotifier extends Notifier<MapState> {
|
2024-01-15 15:26:13 +00:00
|
|
|
@override
|
|
|
|
|
MapState build() {
|
2026-05-12 10:43:52 +07:00
|
|
|
final mapConfig = ref.read(appConfigProvider.select((config) => config.map));
|
2023-08-27 05:07:35 +00:00
|
|
|
|
2025-07-25 08:07:22 +05:30
|
|
|
final lightStyleUrl = ref.read(serverInfoProvider).serverConfig.mapLightStyleUrl;
|
|
|
|
|
final darkStyleUrl = ref.read(serverInfoProvider).serverConfig.mapDarkStyleUrl;
|
2024-09-23 21:30:23 +01:00
|
|
|
|
2024-01-15 15:26:13 +00:00
|
|
|
return MapState(
|
2026-05-12 10:43:52 +07:00
|
|
|
themeMode: mapConfig.themeMode,
|
|
|
|
|
showFavoriteOnly: mapConfig.favoritesOnly,
|
|
|
|
|
includeArchived: mapConfig.includeArchived,
|
|
|
|
|
withPartners: mapConfig.withPartners,
|
|
|
|
|
relativeTime: mapConfig.relativeDays,
|
2024-09-23 21:30:23 +01:00
|
|
|
lightStyleFetched: AsyncData(lightStyleUrl),
|
|
|
|
|
darkStyleFetched: AsyncData(darkStyleUrl),
|
2023-08-27 05:07:35 +00:00
|
|
|
);
|
2023-11-09 17:10:56 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-15 15:26:13 +00:00
|
|
|
void switchTheme(ThemeMode mode) {
|
2026-07-30 12:39:24 -07:00
|
|
|
unawaited(ref.read(settingsProvider).write(.mapThemeMode, mode));
|
2024-01-15 15:26:13 +00:00
|
|
|
state = state.copyWith(themeMode: mode);
|
2023-08-27 05:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void switchFavoriteOnly(bool isFavoriteOnly) {
|
2026-07-30 12:39:24 -07:00
|
|
|
unawaited(ref.read(settingsProvider).write(.mapShowFavoriteOnly, isFavoriteOnly));
|
2025-07-29 00:34:03 +05:30
|
|
|
state = state.copyWith(showFavoriteOnly: isFavoriteOnly, shouldRefetchMarkers: true);
|
2024-01-15 15:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setRefetchMarkers(bool shouldRefetch) {
|
|
|
|
|
state = state.copyWith(shouldRefetchMarkers: shouldRefetch);
|
2023-08-27 05:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-04 15:51:07 +02:00
|
|
|
void switchIncludeArchived(bool isIncludeArchived) {
|
2026-07-30 12:39:24 -07:00
|
|
|
unawaited(ref.read(settingsProvider).write(.mapIncludeArchived, isIncludeArchived));
|
2025-07-29 00:34:03 +05:30
|
|
|
state = state.copyWith(includeArchived: isIncludeArchived, shouldRefetchMarkers: true);
|
2023-10-04 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-06 16:04:40 +02:00
|
|
|
void switchWithPartners(bool isWithPartners) {
|
2026-07-30 12:39:24 -07:00
|
|
|
unawaited(ref.read(settingsProvider).write(.mapWithPartners, isWithPartners));
|
2025-07-29 00:34:03 +05:30
|
|
|
state = state.copyWith(withPartners: isWithPartners, shouldRefetchMarkers: true);
|
2024-04-06 16:04:40 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-27 05:07:35 +00:00
|
|
|
void setRelativeTime(int relativeTime) {
|
2026-07-30 12:39:24 -07:00
|
|
|
unawaited(ref.read(settingsProvider).write(.mapRelativeDate, relativeTime));
|
2025-07-29 00:34:03 +05:30
|
|
|
state = state.copyWith(relativeTime: relativeTime, shouldRefetchMarkers: true);
|
2023-11-09 17:10:56 +01:00
|
|
|
}
|
2023-08-27 05:07:35 +00:00
|
|
|
}
|