From 79507be8de0f53e5a22408fa05f6946f07331f11 Mon Sep 17 00:00:00 2001 From: kidozh <11661760+kidozh@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:22:56 +0000 Subject: [PATCH] update version --- lib/page/AddDiscuzPage.dart | 7 ++-- lib/page/ConfigurePictureBedPage.dart | 18 ++++++--- lib/page/SettingPage.dart | 25 +++++++------ lib/page/TestFlightBannerPage.dart | 26 ++++++------- lib/utility/AppPlatformIcons.dart | 2 +- lib/utility/NetworkUtils.dart | 53 +++++++++++++++++++++++++-- lib/utility/PushServiceUtils.dart | 2 +- pubspec.yaml | 2 + 8 files changed, 97 insertions(+), 38 deletions(-) diff --git a/lib/page/AddDiscuzPage.dart b/lib/page/AddDiscuzPage.dart index eae5ea91..e271d5c6 100644 --- a/lib/page/AddDiscuzPage.dart +++ b/lib/page/AddDiscuzPage.dart @@ -11,6 +11,7 @@ import 'package:discuz_flutter/database/AppDatabase.dart'; import 'package:discuz_flutter/entity/Discuz.dart'; import 'package:discuz_flutter/generated/l10n.dart'; import 'package:discuz_flutter/provider/DiscuzAndUserNotifier.dart'; +import 'package:discuz_flutter/utility/NetworkUtils.dart'; import 'package:discuz_flutter/utility/UserPreferencesUtils.dart'; import 'package:discuz_flutter/utility/VibrationUtils.dart'; import 'package:discuz_flutter/widget/ErrorCard.dart'; @@ -81,7 +82,7 @@ class _AddDiscuzFormFieldState }); } catch (e) {} - final dio = Dio(); + final dio = await NetworkUtils.getDioWithTempCookieJar(); final client = UtilityServiceApiClient(dio, baseUrl: 'https://discuzhub.kidozh.com'); client.getAllSuggestedDiscuzList().then((string) { @@ -127,11 +128,11 @@ class _AddDiscuzFormFieldState Navigator.pop(context); } - void _checkApiAvailable() { + void _checkApiAvailable() async{ String discuzUrl = _urlController.text; log("Recv url " + discuzUrl); // check the availability - final dio = Dio(); + final dio = await NetworkUtils.getDioWithTempCookieJar(); final client = MobileApiClient(dio, baseUrl: discuzUrl); setState(() { _isLoading = true; diff --git a/lib/page/ConfigurePictureBedPage.dart b/lib/page/ConfigurePictureBedPage.dart index 4157b83e..6efa4b00 100644 --- a/lib/page/ConfigurePictureBedPage.dart +++ b/lib/page/ConfigurePictureBedPage.dart @@ -113,7 +113,9 @@ class ConfigurePictureBedState extends State { Center( child: Text( S.of(context).pictureBedTermsTitle(pictureBedName), - style: Theme.of(context).textTheme.headlineSmall, + style: Theme.of(context).textTheme.headlineMedium?..copyWith( + fontWeight: FontWeight.bold + ), ), ), SizedBox( @@ -146,13 +148,17 @@ class ConfigurePictureBedState extends State { SizedBox( height: 16, ), - Padding( - padding: EdgeInsets.symmetric(vertical: 8, horizontal: 0), - child: PlatformElevatedButton( - child: Text(S.of(context).pictureBedAgreeToService), - onPressed: onPressed, + SizedBox( + width: double.infinity, + child: Padding( + padding: EdgeInsets.symmetric(vertical: 16, horizontal: 0), + child: PlatformElevatedButton( + child: Text(S.of(context).pictureBedAgreeToService), + onPressed: onPressed, + ), ), ) + ], ), ), diff --git a/lib/page/SettingPage.dart b/lib/page/SettingPage.dart index e023cfad..88fe3965 100644 --- a/lib/page/SettingPage.dart +++ b/lib/page/SettingPage.dart @@ -23,6 +23,8 @@ import 'package:url_launcher/url_launcher.dart'; import '../utility/AppPlatformIcons.dart'; import '../utility/PostTextFieldUtils.dart'; import 'ChooseThemeColorPage.dart'; +import 'ConfigurePictureBedPage.dart'; +import 'SetPushNotificationPage.dart'; class SettingPage extends StatefulWidget { @override @@ -120,6 +122,17 @@ class _SettingPageState extends State { }); }, initialValue: recordHistory, ), + SettingsTile.navigation( + title: Text(S.of(context).pictureBedTitle), + leading: Icon(AppPlatformIcons(context).pictureBedOutlined), + onPressed: (_) { + VibrationUtils.vibrateWithClickIfPossible(); + Navigator.of(context).push(platformPageRoute( + builder: (_) => ConfigurePictureBedPage(), + context: context, + )); + }, + ), // SettingsTile.navigation( // title: Text(S.of(context).pushNotification), // leading: Icon(AppPlatformIcons(context).pushServiceOutlined), @@ -301,17 +314,7 @@ class _SettingPageState extends State { ) ), - // SettingsTile.navigation( - // title: Text(S.of(context).pictureBedTitle), - // leading: Icon(AppPlatformIcons(context).pictureBedOutlined), - // onPressed: (_) { - // VibrationUtils.vibrateWithClickIfPossible(); - // Navigator.of(context).push(platformPageRoute( - // builder: (_) => ConfigurePictureBedPage(), - // context: context, - // )); - // }, - // ), + ], ), SettingsSection( diff --git a/lib/page/TestFlightBannerPage.dart b/lib/page/TestFlightBannerPage.dart index 39f0e229..85e1b71d 100644 --- a/lib/page/TestFlightBannerPage.dart +++ b/lib/page/TestFlightBannerPage.dart @@ -192,19 +192,19 @@ class TestFlightBannerContentState extends State{ URLUtils.launchURL("https://discuzhub.kidozh.com/zh/term_of_use/"); }, ), - Divider(), - ListTile( - leading: CircleAvatar( - backgroundColor: Colors.purple, - child: Icon(Icons.menu_open,color: Colors.white,), - ), - title: Text(S.of(context).openSoftwareTitle), - subtitle: Text(S.of(context).openSoftwareSubtitle), - onTap: (){ - VibrationUtils.vibrateWithClickIfPossible(); - URLUtils.launchURL("https://github.com/kidozh/discuz_flutter"); - }, - ), + //Divider(), + // ListTile( + // leading: CircleAvatar( + // backgroundColor: Colors.purple, + // child: Icon(Icons.menu_open,color: Colors.white,), + // ), + // title: Text(S.of(context).openSoftwareTitle), + // subtitle: Text(S.of(context).openSoftwareSubtitle), + // onTap: (){ + // VibrationUtils.vibrateWithClickIfPossible(); + // URLUtils.launchURL("https://github.com/kidozh/discuz_flutter"); + // }, + // ), SizedBox(height: 24,), Row( mainAxisSize: MainAxisSize.max, diff --git a/lib/utility/AppPlatformIcons.dart b/lib/utility/AppPlatformIcons.dart index 669f616f..94d0b8ff 100644 --- a/lib/utility/AppPlatformIcons.dart +++ b/lib/utility/AppPlatformIcons.dart @@ -103,7 +103,7 @@ class AppPlatformIcons{ IconData get hapticFeedbackOutlined => isMaterial(context)? Icons.vibration_outlined : CupertinoIcons.dial; - IconData get pictureBedOutlined => isMaterial(context)? Icons.photo_album_outlined : CupertinoIcons.square_stack; + IconData get pictureBedOutlined => isMaterial(context)? Icons.photo_album_outlined : CupertinoIcons.archivebox; IconData get chevronSolid => isMaterial(context)? Icons.arrow_forward : CupertinoIcons.chevron_forward; diff --git a/lib/utility/NetworkUtils.dart b/lib/utility/NetworkUtils.dart index 6388d06e..ee989e6f 100644 --- a/lib/utility/NetworkUtils.dart +++ b/lib/utility/NetworkUtils.dart @@ -6,9 +6,12 @@ import 'package:dio/dio.dart'; import 'package:discuz_flutter/entity/User.dart'; import 'package:path_provider/path_provider.dart'; import 'package:dio_cookie_manager/dio_cookie_manager.dart'; +import 'package:random_user_agents/random_user_agents.dart'; +import 'package:ua_client_hints/ua_client_hints.dart'; class NetworkUtils{ + static final ua = RandomUserAgents.random(); static Future getPersistentCookieJarByUser(User user) async{ Directory appDocDir = await getApplicationDocumentsDirectory(); @@ -34,18 +37,62 @@ class NetworkUtils{ } static Future getDioWithTempCookieJar() async{ - var dio = Dio(); + String userAgent = ua; + final header = await userAgentClientHintsHeader(); + var dio = Dio( + BaseOptions( + headers: { + 'User-Agent': userAgent, + //'Accept-Language': 'en-US,en;q=0.9' + } + ) + ); + print("Running on UA ${ua} ${header}"); + PersistCookieJar cookieJar = await getTemporaryCookieJar(); dio.interceptors.add(CookieManager(cookieJar)); + // dio.interceptors.add(InterceptorsWrapper( + // onRequest: (options, handler) async{ + // options.headers.addAll(await userAgentClientHintsHeader()); + // //return options; + // }, + // )); return dio; } static Future getDioWithPersistCookieJar(User? user) async{ if(user == null){ - return Dio(); + String userAgent = ua; + var dio = Dio( + BaseOptions( + headers: { + 'User-Agent': userAgent + } + ) + ); + // dio.interceptors.add(InterceptorsWrapper( + // onRequest: (options, handler) async{ + // options.headers.addAll(await userAgentClientHintsHeader()); + // //return options; + // }, + // )); + return dio; } else{ - var dio = Dio(); + String userAgent = ua; + var dio = Dio( + BaseOptions( + headers: { + 'User-Agent': userAgent + } + ) + ); + // dio.interceptors.add(InterceptorsWrapper( + // onRequest: (options, handler) async{ + // options.headers.addAll(await userAgentClientHintsHeader()); + // //return options; + // }, + // )); PersistCookieJar cookieJar = await getPersistentCookieJarByUser(user); dio.interceptors.add(CookieManager(cookieJar)); return dio; diff --git a/lib/utility/PushServiceUtils.dart b/lib/utility/PushServiceUtils.dart index b917ed1a..f47edf49 100644 --- a/lib/utility/PushServiceUtils.dart +++ b/lib/utility/PushServiceUtils.dart @@ -419,7 +419,7 @@ class PushServiceUtils{ requestAlertPermission: false, requestBadgePermission: false, requestSoundPermission: false, - onDidReceiveLocalNotification: PushServiceUtils.onDidReceiveLocalNotification + //onDidReceiveLocalNotification: PushServiceUtils.onDidReceiveLocalNotification ); final InitializationSettings initializationSettings = InitializationSettings( android: initializationSettingsAndroid, diff --git a/pubspec.yaml b/pubspec.yaml index 4bc4aedb..a28b03db 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -103,6 +103,8 @@ dependencies: firebase_core: ^3.2.0 html: ^0.15.4 ios_utsname_ext: ^2.3.0 + ua_client_hints: ^1.4.0 + random_user_agents: ^1.0.6 dev_dependencies: flutter_test: sdk: flutter