2023-11-09 17:10:56 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2024-04-30 21:36:40 -05:00
|
|
|
import 'package:immich_mobile/models/map/map_state.model.dart';
|
2024-05-02 15:59:14 -05:00
|
|
|
import 'package:immich_mobile/providers/app_settings.provider.dart';
|
2024-09-23 21:30:23 +01:00
|
|
|
import 'package:immich_mobile/providers/server_info.provider.dart';
|
2024-05-02 15:59:14 -05:00
|
|
|
import 'package:immich_mobile/services/app_settings.service.dart';
|
2024-01-15 15:26:13 +00:00
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
2023-08-27 05:07:35 +00:00
|
|
|
|
2024-01-15 15:26:13 +00:00
|
|
|
part 'map_state.provider.g.dart';
|
2023-11-09 17:10:56 +01:00
|
|
|
|
2024-01-15 15:26:13 +00:00
|
|
|
@Riverpod(keepAlive: true)
|
|
|
|
|
class MapStateNotifier extends _$MapStateNotifier {
|
|
|
|
|
@override
|
|
|
|
|
MapState build() {
|
|
|
|
|
final appSettingsProvider = ref.read(appSettingsServiceProvider);
|
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(
|
2025-07-25 08:07:22 +05:30
|
|
|
themeMode: ThemeMode.values[appSettingsProvider.getSetting<int>(AppSettingsEnum.mapThemeMode)],
|
|
|
|
|
showFavoriteOnly: appSettingsProvider.getSetting<bool>(AppSettingsEnum.mapShowFavoriteOnly),
|
|
|
|
|
includeArchived: appSettingsProvider.getSetting<bool>(AppSettingsEnum.mapIncludeArchived),
|
|
|
|
|
withPartners: appSettingsProvider.getSetting<bool>(AppSettingsEnum.mapwithPartners),
|
|
|
|
|
relativeTime: appSettingsProvider.getSetting<int>(AppSettingsEnum.mapRelativeDate),
|
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) {
|
2025-07-29 00:34:03 +05:30
|
|
|
ref.read(appSettingsServiceProvider).setSetting(AppSettingsEnum.mapThemeMode, mode.index);
|
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) {
|
2025-07-29 00:34:03 +05:30
|
|
|
ref.read(appSettingsServiceProvider).setSetting(AppSettingsEnum.mapShowFavoriteOnly, isFavoriteOnly);
|
|
|
|
|
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) {
|
2025-07-29 00:34:03 +05:30
|
|
|
ref.read(appSettingsServiceProvider).setSetting(AppSettingsEnum.mapIncludeArchived, isIncludeArchived);
|
|
|
|
|
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) {
|
2025-07-29 00:34:03 +05:30
|
|
|
ref.read(appSettingsServiceProvider).setSetting(AppSettingsEnum.mapwithPartners, isWithPartners);
|
|
|
|
|
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) {
|
2025-07-29 00:34:03 +05:30
|
|
|
ref.read(appSettingsServiceProvider).setSetting(AppSettingsEnum.mapRelativeDate, relativeTime);
|
|
|
|
|
state = state.copyWith(relativeTime: relativeTime, shouldRefetchMarkers: true);
|
2023-11-09 17:10:56 +01:00
|
|
|
}
|
2023-08-27 05:07:35 +00:00
|
|
|
}
|