diff --git a/lib/app.dart b/lib/app.dart index 0f300ec8..4861fd65 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -4,6 +4,7 @@ import 'package:clock_app/navigation/screens/nav_scaffold.dart'; import 'package:clock_app/navigation/types/routes.dart'; import 'package:clock_app/notifications/types/notifications_controller.dart'; import 'package:clock_app/settings/data/settings_schema.dart'; +import 'package:clock_app/settings/screens/settings_group_screen.dart'; import 'package:clock_app/settings/screens/vendor_list_screen.dart'; import 'package:clock_app/settings/types/setting_group.dart'; import 'package:clock_app/theme/types/color_scheme.dart'; @@ -27,6 +28,7 @@ class OnBoardingPageState extends State { final introKey = GlobalKey(); void _onIntroEnd(context) { + GetStorage().write('onboarded', true); Navigator.of(context).pushReplacement( MaterialPageRoute(builder: (_) => const NavScaffold()), ); @@ -70,7 +72,11 @@ class OnBoardingPageState extends State { await Navigator.push( context, MaterialPageRoute( - builder: (context) => const VendorListScreen())); + builder: (context) => SettingGroupScreen( + settingGroup: + appSettings.getGroup("Reliability"), + isAppSettings: false, + ))); }, style: ElevatedButton.styleFrom( backgroundColor: colorScheme.primary, @@ -199,7 +205,6 @@ class _AppState extends State { case Routes.rootRoute: final bool? onboarded = GetStorage().read('onboarded'); if (onboarded == null) { - GetStorage().write('first_launch', true); return MaterialPageRoute( builder: (context) => const OnBoardingPage()); } else { diff --git a/lib/settings/data/settings_schema.dart b/lib/settings/data/settings_schema.dart index bbead5ba..050c584a 100644 --- a/lib/settings/data/settings_schema.dart +++ b/lib/settings/data/settings_schema.dart @@ -1,3 +1,5 @@ +import 'package:app_settings/app_settings.dart'; +import 'package:auto_start_flutter/auto_start_flutter.dart'; import 'package:clock_app/alarm/data/alarm_settings_schema.dart'; import 'package:clock_app/alarm/types/notification_action.dart'; import 'package:clock_app/alarm/widgets/notification_actions/area_notification_action.dart'; @@ -8,6 +10,7 @@ import 'package:clock_app/clock/types/time.dart'; import 'package:clock_app/icons/flux_icons.dart'; import 'package:clock_app/settings/screens/vendor_list_screen.dart'; import 'package:clock_app/settings/types/setting.dart'; +import 'package:clock_app/settings/types/setting_action.dart'; import 'package:clock_app/settings/types/setting_group.dart'; import 'package:clock_app/settings/types/setting_link.dart'; import 'package:clock_app/theme/screens/themes_screen.dart'; @@ -20,6 +23,7 @@ import 'package:clock_app/timer/data/timer_settings_schema.dart'; import 'package:clock_app/timer/screens/presets_screen.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:intl/intl.dart'; SelectSettingOption _getDateSettingOption(String format) { @@ -60,41 +64,65 @@ SettingGroup appSettings = SettingGroup( ), SwitchSetting("Show Seconds", true), ]), - SettingPageLink("Reliability", const VendorListScreen()), - // SettingGroup("Reliability", [ - // SettingAction( - // "Disable Battery Optimization", - // () async { - // AppSettings.openAppSettings( - // type: AppSettingsType.batteryOptimization); - // }, - // description: - // "Disable battery optimization for this app to prevent alarms from being delayed", - // ), - // SettingAction( - // "Allow Notifications", - // () async { - // AppSettings.openAppSettings(type: AppSettingsType.notification); - // }, - // description: - // "Allow lock screen notifications for alarms and timers", - // ), - // SettingAction( - // "Auto Start", - // () async { - // try { - // //check auto-start availability. - // var test = await isAutoStartAvailable ?? false; - // //if available then navigate to auto-start setting page. - // if (test) await getAutoStartPermission(); - // } on PlatformException catch (e) { - // if (kDebugMode) print(e.message); - // } - // }, - // description: - // "Enable auto start to allow alarms to go off when the app is closed", - // ) - // ]), + SettingGroup("Reliability", [ + SettingPageLink( + "Vendor Specific", + const VendorListScreen(), + description: "Manually disable vendor-specific optimizations", + ), + SettingAction( + "Disable Battery Optimization", + (context) async { + AppSettings.openAppSettings( + type: AppSettingsType.batteryOptimization); + }, + description: + "Disable battery optimization for this app to prevent alarms from being delayed", + ), + SettingAction( + "Allow Notifications", + (context) async { + AppSettings.openAppSettings(type: AppSettingsType.notification); + }, + description: + "Allow lock screen notifications for alarms and timers", + ), + SettingAction( + "Auto Start", + (context) async { + try { + //check auto-start availability. + var test = await isAutoStartAvailable ?? false; + //if available then navigate to auto-start setting page. + if (test) { + await getAutoStartPermission(); + } else { + // ignore: use_build_context_synchronously + ScaffoldMessenger.of(context).removeCurrentSnackBar(); + + SnackBar snackBar = SnackBar( + content: Container( + alignment: Alignment.centerLeft, + height: 28, + child: const Text( + "Auto Start is not available for your device")), + margin: + const EdgeInsets.only(left: 20, right: 20, bottom: 4), + elevation: 2, + dismissDirection: DismissDirection.none, + ); + + // ignore: use_build_context_synchronously + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + } on PlatformException catch (e) { + if (kDebugMode) print(e.message); + } + }, + description: + "Enable auto start to allow alarms to go off when the app is closed", + ) + ]), ], icon: FluxIcons.settings, description: "Set app wide settings like time format", diff --git a/lib/settings/types/setting_action.dart b/lib/settings/types/setting_action.dart index 5d11a702..8c064def 100644 --- a/lib/settings/types/setting_action.dart +++ b/lib/settings/types/setting_action.dart @@ -2,7 +2,7 @@ import 'package:clock_app/settings/types/setting_item.dart'; import 'package:flutter/material.dart'; class SettingAction extends SettingItem { - VoidCallback action; + void Function(BuildContext context) action; SettingAction( String name, @@ -13,7 +13,8 @@ class SettingAction extends SettingItem { @override SettingAction copy() { - return SettingAction(name, action); + return SettingAction(name, action, + description: description, searchTags: searchTags); } @override diff --git a/lib/settings/types/setting_link.dart b/lib/settings/types/setting_link.dart index f0b4571f..eaba82e5 100644 --- a/lib/settings/types/setting_link.dart +++ b/lib/settings/types/setting_link.dart @@ -13,7 +13,8 @@ class SettingPageLink extends SettingItem { @override SettingPageLink copy() { - return SettingPageLink(name, screen); + return SettingPageLink(name, screen, + description: description, searchTags: searchTags); } @override diff --git a/lib/settings/widgets/setting_action_card.dart b/lib/settings/widgets/setting_action_card.dart index e3b4b4e5..24f8dd0e 100644 --- a/lib/settings/widgets/setting_action_card.dart +++ b/lib/settings/widgets/setting_action_card.dart @@ -26,7 +26,7 @@ class _SettingActionCardState extends State { Widget inner = Material( color: Colors.transparent, child: InkWell( - onTap: widget.setting.action, + onTap: () => widget.setting.action(context), child: Padding( padding: const EdgeInsets.all(16), child: Row( diff --git a/pubspec.lock b/pubspec.lock index 95b8d8bd..5d8aede5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,6 +42,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.1" + app_settings: + dependency: "direct main" + description: + name: app_settings + sha256: "09bc7fe0313a507087bec1a3baf555f0576e816a760cbb31813a88890a09d9e5" + url: "https://pub.dev" + source: hosted + version: "5.1.1" archive: dependency: transitive description: @@ -74,6 +82,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.1.13" + auto_start_flutter: + dependency: "direct main" + description: + name: auto_start_flutter + sha256: "27b12be7dc2d37b1a535189f461a12dad15b54c12f0a36e6ea69e73e579d433b" + url: "https://pub.dev" + source: hosted + version: "0.1.1" awesome_notifications: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 11fa831b..faef369e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -72,6 +72,8 @@ dependencies: flutter_html: ^3.0.0-beta.2 http: ^0.13.6 introduction_screen: ^3.1.12 + app_settings: ^5.1.1 + auto_start_flutter: ^0.1.1 dev_dependencies: flutter_test: