2023-08-27 07:07:35 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-08-27 07:07:35 +02:00
|
|
|
import 'package:immich_mobile/modules/map/providers/map_state.provider.dart';
|
|
|
|
|
|
|
|
class MapSettingsDialog extends HookConsumerWidget {
|
|
|
|
const MapSettingsDialog({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final mapSettingsNotifier = ref.read(mapStateNotifier.notifier);
|
|
|
|
final mapSettings = ref.read(mapStateNotifier);
|
|
|
|
final isDarkMode = useState(mapSettings.isDarkTheme);
|
|
|
|
final showFavoriteOnly = useState(mapSettings.showFavoriteOnly);
|
2023-10-04 15:51:07 +02:00
|
|
|
final showIncludeArchived = useState(mapSettings.includeArchived);
|
2023-08-27 07:07:35 +02:00
|
|
|
final showRelativeDate = useState(mapSettings.relativeTime);
|
2023-11-09 18:19:53 +02:00
|
|
|
final ThemeData theme = context.themeData;
|
2023-08-27 07:07:35 +02:00
|
|
|
|
|
|
|
Widget buildMapThemeSetting() {
|
|
|
|
return SwitchListTile.adaptive(
|
|
|
|
value: isDarkMode.value,
|
|
|
|
onChanged: (value) {
|
|
|
|
isDarkMode.value = value;
|
|
|
|
},
|
|
|
|
activeColor: theme.primaryColor,
|
|
|
|
dense: true,
|
|
|
|
title: Text(
|
|
|
|
"map_settings_dark_mode".tr(),
|
|
|
|
style:
|
|
|
|
theme.textTheme.labelLarge?.copyWith(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildFavoriteOnlySetting() {
|
|
|
|
return SwitchListTile.adaptive(
|
|
|
|
value: showFavoriteOnly.value,
|
|
|
|
onChanged: (value) {
|
|
|
|
showFavoriteOnly.value = value;
|
|
|
|
},
|
|
|
|
activeColor: theme.primaryColor,
|
|
|
|
dense: true,
|
|
|
|
title: Text(
|
|
|
|
"map_settings_only_show_favorites".tr(),
|
|
|
|
style:
|
|
|
|
theme.textTheme.labelLarge?.copyWith(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-10-04 15:51:07 +02:00
|
|
|
Widget buildIncludeArchivedSetting() {
|
|
|
|
return SwitchListTile.adaptive(
|
|
|
|
value: showIncludeArchived.value,
|
|
|
|
onChanged: (value) {
|
|
|
|
showIncludeArchived.value = value;
|
|
|
|
},
|
|
|
|
activeColor: theme.primaryColor,
|
|
|
|
dense: true,
|
|
|
|
title: Text(
|
|
|
|
"map_settings_include_show_archived".tr(),
|
|
|
|
style:
|
|
|
|
theme.textTheme.labelLarge?.copyWith(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-27 07:07:35 +02:00
|
|
|
Widget buildDateRangeSetting() {
|
|
|
|
final now = DateTime.now();
|
|
|
|
return DropdownMenu(
|
|
|
|
enableSearch: false,
|
|
|
|
enableFilter: false,
|
|
|
|
initialSelection: showRelativeDate.value,
|
|
|
|
onSelected: (value) {
|
|
|
|
showRelativeDate.value = value!;
|
|
|
|
},
|
|
|
|
dropdownMenuEntries: [
|
2023-11-19 04:32:28 +02:00
|
|
|
DropdownMenuEntry(
|
|
|
|
value: 0,
|
|
|
|
label: "map_settings_date_range_option_all".tr(),
|
|
|
|
),
|
|
|
|
DropdownMenuEntry(
|
2023-08-27 07:07:35 +02:00
|
|
|
value: 1,
|
2023-11-19 04:32:28 +02:00
|
|
|
label: "map_settings_date_range_option_days".plural(1),
|
2023-08-27 07:07:35 +02:00
|
|
|
),
|
2023-11-19 04:32:28 +02:00
|
|
|
DropdownMenuEntry(
|
2023-08-27 07:07:35 +02:00
|
|
|
value: 7,
|
2023-11-19 04:32:28 +02:00
|
|
|
label: "map_settings_date_range_option_days".plural(7),
|
2023-08-27 07:07:35 +02:00
|
|
|
),
|
2023-11-19 04:32:28 +02:00
|
|
|
DropdownMenuEntry(
|
2023-08-27 07:07:35 +02:00
|
|
|
value: 30,
|
2023-11-19 04:32:28 +02:00
|
|
|
label: "map_settings_date_range_option_days".plural(30),
|
2023-08-27 07:07:35 +02:00
|
|
|
),
|
|
|
|
DropdownMenuEntry(
|
|
|
|
value: now
|
|
|
|
.difference(
|
|
|
|
DateTime(
|
|
|
|
now.year - 1,
|
|
|
|
now.month,
|
|
|
|
now.day,
|
|
|
|
now.hour,
|
|
|
|
now.minute,
|
|
|
|
now.second,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.inDays,
|
2023-11-19 04:32:28 +02:00
|
|
|
label: "map_settings_date_range_option_years".plural(1),
|
2023-08-27 07:07:35 +02:00
|
|
|
),
|
|
|
|
DropdownMenuEntry(
|
|
|
|
value: now
|
|
|
|
.difference(
|
|
|
|
DateTime(
|
|
|
|
now.year - 3,
|
|
|
|
now.month,
|
|
|
|
now.day,
|
|
|
|
now.hour,
|
|
|
|
now.minute,
|
|
|
|
now.second,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.inDays,
|
2023-11-19 04:32:28 +02:00
|
|
|
label: "map_settings_date_range_option_years".plural(3),
|
2023-08-27 07:07:35 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Widget> getDialogActions() {
|
|
|
|
return <Widget>[
|
|
|
|
TextButton(
|
2023-11-09 18:19:53 +02:00
|
|
|
onPressed: () => context.pop(),
|
2023-08-27 07:07:35 +02:00
|
|
|
style: TextButton.styleFrom(
|
|
|
|
backgroundColor:
|
|
|
|
mapSettings.isDarkTheme ? Colors.grey[100] : Colors.grey[700],
|
|
|
|
),
|
2023-11-20 16:58:03 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
child: Text(
|
|
|
|
"map_settings_dialog_cancel".tr(),
|
|
|
|
style: theme.textTheme.labelLarge?.copyWith(
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
color: mapSettings.isDarkTheme
|
|
|
|
? Colors.grey[900]
|
|
|
|
: Colors.grey[100],
|
|
|
|
),
|
2023-08-27 07:07:35 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
mapSettingsNotifier.switchTheme(isDarkMode.value);
|
|
|
|
mapSettingsNotifier.switchFavoriteOnly(showFavoriteOnly.value);
|
|
|
|
mapSettingsNotifier.setRelativeTime(showRelativeDate.value);
|
2023-10-04 15:51:07 +02:00
|
|
|
mapSettingsNotifier
|
|
|
|
.switchIncludeArchived(showIncludeArchived.value);
|
2023-11-09 18:19:53 +02:00
|
|
|
context.pop();
|
2023-08-27 07:07:35 +02:00
|
|
|
},
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
backgroundColor: theme.primaryColor,
|
|
|
|
),
|
2023-11-20 16:58:03 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
child: Text(
|
|
|
|
"map_settings_dialog_save".tr(),
|
|
|
|
style: theme.textTheme.labelLarge?.copyWith(
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
color: theme.primaryTextTheme.labelLarge?.color,
|
|
|
|
),
|
2023-08-27 07:07:35 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return AlertDialog(
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
|
|
|
title: Center(
|
|
|
|
child: Text(
|
|
|
|
"map_settings_dialog_title".tr(),
|
|
|
|
style: TextStyle(
|
|
|
|
color: theme.primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 18,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
content: SizedBox(
|
|
|
|
width: double.maxFinite,
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(
|
2023-11-09 18:19:53 +02:00
|
|
|
maxHeight: context.height * 0.6,
|
2023-08-27 07:07:35 +02:00
|
|
|
),
|
|
|
|
child: ListView(
|
|
|
|
shrinkWrap: true,
|
|
|
|
children: [
|
|
|
|
buildMapThemeSetting(),
|
|
|
|
buildFavoriteOnlySetting(),
|
2023-10-04 15:51:07 +02:00
|
|
|
buildIncludeArchivedSetting(),
|
2023-08-27 07:07:35 +02:00
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 20),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"map_settings_only_relative_range".tr(),
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
buildDateRangeSetting(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
].toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: getDialogActions(),
|
|
|
|
actionsAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|