2024-02-15 15:23:02 +03:30
|
|
|
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
|
2023-09-17 00:23:31 +03:30
|
|
|
import 'package:flutter/material.dart';
|
2023-12-22 14:16:24 +03:30
|
|
|
import 'package:hiddify/core/analytics/analytics_controller.dart';
|
2023-12-01 12:56:24 +03:30
|
|
|
import 'package:hiddify/core/localization/locale_extensions.dart';
|
|
|
|
|
import 'package:hiddify/core/localization/locale_preferences.dart';
|
|
|
|
|
import 'package:hiddify/core/localization/translations.dart';
|
|
|
|
|
import 'package:hiddify/core/model/region.dart';
|
|
|
|
|
import 'package:hiddify/core/preferences/general_preferences.dart';
|
2023-09-17 00:23:31 +03:30
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
|
|
|
|
|
|
class LocalePrefTile extends HookConsumerWidget {
|
|
|
|
|
const LocalePrefTile({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final t = ref.watch(translationsProvider);
|
|
|
|
|
|
2023-12-01 12:56:24 +03:30
|
|
|
final locale = ref.watch(localePreferencesProvider);
|
2023-09-17 00:23:31 +03:30
|
|
|
|
|
|
|
|
return ListTile(
|
|
|
|
|
title: Text(t.settings.general.locale),
|
2023-11-25 22:48:22 +03:30
|
|
|
subtitle: Text(locale.localeName),
|
2024-02-15 15:23:02 +03:30
|
|
|
leading: const Icon(FluentIcons.local_language_24_regular),
|
2023-09-17 00:23:31 +03:30
|
|
|
onTap: () async {
|
|
|
|
|
final selectedLocale = await showDialog<AppLocale>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return SimpleDialog(
|
|
|
|
|
title: Text(t.settings.general.locale),
|
|
|
|
|
children: AppLocale.values
|
|
|
|
|
.map(
|
|
|
|
|
(e) => RadioListTile(
|
2023-11-25 22:48:22 +03:30
|
|
|
title: Text(e.localeName),
|
2023-09-17 00:23:31 +03:30
|
|
|
value: e,
|
|
|
|
|
groupValue: locale,
|
2023-12-28 10:43:57 +03:30
|
|
|
onChanged: Navigator.of(context).maybePop,
|
2023-09-17 00:23:31 +03:30
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList(),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (selectedLocale != null) {
|
|
|
|
|
await ref
|
2023-12-01 12:56:24 +03:30
|
|
|
.read(localePreferencesProvider.notifier)
|
|
|
|
|
.changeLocale(selectedLocale);
|
2023-09-17 00:23:31 +03:30
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 14:55:46 +03:30
|
|
|
class RegionPrefTile extends HookConsumerWidget {
|
|
|
|
|
const RegionPrefTile({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final t = ref.watch(translationsProvider);
|
|
|
|
|
|
2024-03-02 22:53:14 +03:30
|
|
|
final region = ref.watch(Preferences.region);
|
2023-09-17 14:55:46 +03:30
|
|
|
|
|
|
|
|
return ListTile(
|
|
|
|
|
title: Text(t.settings.general.region),
|
|
|
|
|
subtitle: Text(region.present(t)),
|
2024-02-15 15:23:02 +03:30
|
|
|
leading: const Icon(FluentIcons.globe_location_24_regular),
|
2023-09-17 14:55:46 +03:30
|
|
|
onTap: () async {
|
|
|
|
|
final selectedRegion = await showDialog<Region>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return SimpleDialog(
|
|
|
|
|
title: Text(t.settings.general.region),
|
|
|
|
|
children: Region.values
|
|
|
|
|
.map(
|
|
|
|
|
(e) => RadioListTile(
|
|
|
|
|
title: Text(e.present(t)),
|
|
|
|
|
value: e,
|
|
|
|
|
groupValue: region,
|
2023-12-28 10:43:57 +03:30
|
|
|
onChanged: Navigator.of(context).maybePop,
|
2023-09-17 14:55:46 +03:30
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList(),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (selectedRegion != null) {
|
2024-03-02 22:53:14 +03:30
|
|
|
await ref.read(Preferences.region.notifier).update(selectedRegion);
|
2023-09-17 14:55:46 +03:30
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 00:23:31 +03:30
|
|
|
class EnableAnalyticsPrefTile extends HookConsumerWidget {
|
|
|
|
|
const EnableAnalyticsPrefTile({
|
|
|
|
|
super.key,
|
|
|
|
|
this.onChanged,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final ValueChanged<bool>? onChanged;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final t = ref.watch(translationsProvider);
|
|
|
|
|
|
2023-12-23 11:01:48 +03:30
|
|
|
final enabled = ref.watch(analyticsControllerProvider).requireValue;
|
2023-09-17 00:23:31 +03:30
|
|
|
|
|
|
|
|
return SwitchListTile(
|
|
|
|
|
title: Text(t.settings.general.enableAnalytics),
|
|
|
|
|
subtitle: Text(
|
|
|
|
|
t.settings.general.enableAnalyticsMsg,
|
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
|
),
|
2024-02-15 15:23:02 +03:30
|
|
|
secondary: const Icon(FluentIcons.bug_24_regular),
|
2023-12-23 11:01:48 +03:30
|
|
|
value: enabled,
|
2023-09-17 00:23:31 +03:30
|
|
|
onChanged: (value) async {
|
|
|
|
|
if (onChanged != null) {
|
|
|
|
|
return onChanged!(value);
|
|
|
|
|
}
|
2023-12-23 11:01:48 +03:30
|
|
|
if (enabled) {
|
2023-12-22 14:16:24 +03:30
|
|
|
await ref
|
|
|
|
|
.read(analyticsControllerProvider.notifier)
|
|
|
|
|
.disableAnalytics();
|
|
|
|
|
} else {
|
|
|
|
|
await ref
|
|
|
|
|
.read(analyticsControllerProvider.notifier)
|
|
|
|
|
.enableAnalytics();
|
|
|
|
|
}
|
2023-09-17 00:23:31 +03:30
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|