feat: add region and terms to intro

This commit is contained in:
problematicconsumer
2023-09-17 14:55:46 +03:30
parent e6eab038ce
commit bb2e1a2625
8 changed files with 123 additions and 4 deletions

View File

@@ -10,6 +10,7 @@
"sortBy": "Sort by" "sortBy": "Sort by"
}, },
"intro": { "intro": {
"termsAndPolicyCaution(rich)": "by continuing you agree with ${tap(@:about.termsAndConditions)}",
"start": "Start" "start": "Start"
}, },
"home": { "home": {
@@ -104,10 +105,17 @@
}, },
"settings": { "settings": {
"pageTitle": "Settings", "pageTitle": "Settings",
"requiresRestartMsg": "for this to take effect restart the app", "requiresRestartMsg": "For this to take effect restart the app",
"general": { "general": {
"sectionTitle": "General", "sectionTitle": "General",
"locale": "Language", "locale": "Language",
"region": "Region",
"regionMsg": "Helps set default options to bypass domestic addresses",
"regions": {
"ir": "Iran (ir)",
"cn": "China (cn)",
"other": "Other"
},
"themeMode": "Theme Mode", "themeMode": "Theme Mode",
"themeModes": { "themeModes": {
"system": "Follow system theme", "system": "Follow system theme",
@@ -182,7 +190,9 @@
"version": "Version", "version": "Version",
"sourceCode": "Source Code", "sourceCode": "Source Code",
"telegramChannel": "Telegram Channel", "telegramChannel": "Telegram Channel",
"checkForUpdate": "Check for update" "checkForUpdate": "Check for update",
"privacyPolicy": "Privacy policy",
"termsAndConditions": "Terms and conditions"
}, },
"appUpdate": { "appUpdate": {
"dialogTitle": "Update Available", "dialogTitle": "Update Available",

View File

@@ -10,6 +10,7 @@
"sortBy": "مرتب‌سازی براساس" "sortBy": "مرتب‌سازی براساس"
}, },
"intro": { "intro": {
"termsAndPolicyCaution(rich)": "در صورت ادامه با ${tap(@:about.termsAndConditions)} موافقت میکنید",
"start": "شروع" "start": "شروع"
}, },
"home": { "home": {
@@ -108,6 +109,13 @@
"general": { "general": {
"sectionTitle": "اصلی", "sectionTitle": "اصلی",
"locale": "زبان", "locale": "زبان",
"region": "منطقه",
"regionMsg": "به انتخاب تنظیمات پیش‌فرض برای دورزدن آدرس‌های داخلی کمک میکند",
"regions": {
"ir": "ایران (ir)",
"cn": "چین (cn)",
"other": "سایر"
},
"themeMode": "تم مود", "themeMode": "تم مود",
"themeModes": { "themeModes": {
"system": "پیروی از تم دستگاه", "system": "پیروی از تم دستگاه",
@@ -182,7 +190,9 @@
"version": "ورژن", "version": "ورژن",
"sourceCode": "سورس کد", "sourceCode": "سورس کد",
"telegramChannel": "کانال تلگرام", "telegramChannel": "کانال تلگرام",
"checkForUpdate": "بررسی آپدیت جدید" "checkForUpdate": "بررسی آپدیت جدید",
"privacyPolicy": "سیاست حفظ حریم خصوصی",
"termsAndConditions": "شرایط و ضوابط استفاده"
}, },
"appUpdate": { "appUpdate": {
"dialogTitle": "نسخه جدید موجود است", "dialogTitle": "نسخه جدید موجود است",

View File

@@ -24,6 +24,25 @@ class IntroCompleted extends _$IntroCompleted {
} }
} }
@Riverpod(keepAlive: true)
class RegionNotifier extends _$RegionNotifier {
late final _pref = Pref(
ref.watch(sharedPreferencesProvider),
"region",
Region.other,
mapFrom: Region.values.byName,
mapTo: (value) => value.name,
);
@override
Region build() => _pref.getValue();
Future<void> update(Region value) {
state = value;
return _pref.update(value);
}
}
@Riverpod(keepAlive: true) @Riverpod(keepAlive: true)
class SilentStartNotifier extends _$SilentStartNotifier { class SilentStartNotifier extends _$SilentStartNotifier {
late final _pref = late final _pref =

View File

@@ -13,7 +13,7 @@ class LocaleNotifier extends _$LocaleNotifier {
late final _pref = Pref( late final _pref = Pref(
ref.watch(sharedPreferencesProvider), ref.watch(sharedPreferencesProvider),
"locale", "locale",
AppLocale.en, AppLocaleUtils.findDeviceLocale(),
mapFrom: AppLocale.values.byName, mapFrom: AppLocale.values.byName,
mapTo: (value) => value.name, mapTo: (value) => value.name,
); );

View File

@@ -10,6 +10,8 @@ abstract class Constants {
static const githubLatestReleaseUrl = static const githubLatestReleaseUrl =
"https://github.com/hiddify/hiddify-next/releases/latest"; "https://github.com/hiddify/hiddify-next/releases/latest";
static const telegramChannelUrl = "https://t.me/hiddify"; static const telegramChannelUrl = "https://t.me/hiddify";
static const privacyPolicyUrl = "https://hiddify.com/en/privacy-policy/";
static const termsAndConditionsUrl = "https://hiddify.com/terms/";
} }
abstract class Defaults { abstract class Defaults {

View File

@@ -22,3 +22,15 @@ enum PerAppProxyMode {
), ),
}; };
} }
enum Region {
ir,
cn,
other;
String present(TranslationsEn t) => switch (this) {
ir => t.settings.general.regions.ir,
cn => t.settings.general.regions.cn,
other => t.settings.general.regions.other,
};
}

View File

@@ -3,6 +3,7 @@ import 'package:flutter_localized_locales/flutter_localized_locales.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:hiddify/core/core_providers.dart'; import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/core/prefs/prefs.dart'; import 'package:hiddify/core/prefs/prefs.dart';
import 'package:hiddify/domain/singbox/singbox.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
class LocalePrefTile extends HookConsumerWidget { class LocalePrefTile extends HookConsumerWidget {
@@ -54,6 +55,48 @@ class LocalePrefTile extends HookConsumerWidget {
} }
} }
class RegionPrefTile extends HookConsumerWidget {
const RegionPrefTile({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
final region = ref.watch(regionNotifierProvider);
return ListTile(
title: Text(t.settings.general.region),
subtitle: Text(region.present(t)),
leading: const Icon(Icons.my_location),
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,
onChanged: (e) => context.pop(e),
),
)
.toList(),
);
},
);
if (selectedRegion != null) {
await ref
.read(regionNotifierProvider.notifier)
.update(selectedRegion);
}
},
);
}
}
class EnableAnalyticsPrefTile extends HookConsumerWidget { class EnableAnalyticsPrefTile extends HookConsumerWidget {
const EnableAnalyticsPrefTile({ const EnableAnalyticsPrefTile({
super.key, super.key,

View File

@@ -1,7 +1,9 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
import 'package:hiddify/core/core_providers.dart'; import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/core/prefs/prefs.dart'; import 'package:hiddify/core/prefs/prefs.dart';
import 'package:hiddify/domain/constants.dart';
import 'package:hiddify/features/common/common.dart'; import 'package:hiddify/features/common/common.dart';
import 'package:hiddify/gen/assets.gen.dart'; import 'package:hiddify/gen/assets.gen.dart';
import 'package:hiddify/utils/utils.dart'; import 'package:hiddify/utils/utils.dart';
@@ -37,7 +39,28 @@ class IntroPage extends HookConsumerWidget with PresLogger {
children: [ children: [
const LocalePrefTile(), const LocalePrefTile(),
const SliverGap(8), const SliverGap(8),
const RegionPrefTile(),
const SliverGap(8),
const EnableAnalyticsPrefTile(), const EnableAnalyticsPrefTile(),
const SliverGap(8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text.rich(
t.intro.termsAndPolicyCaution(
tap: (text) => TextSpan(
text: text,
style: const TextStyle(color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () async {
await UriUtils.tryLaunch(
Uri.parse(Constants.termsAndConditionsUrl),
);
},
),
),
style: Theme.of(context).textTheme.bodySmall,
),
),
Padding( Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 16, horizontal: 16,