Skip to content

Commit

Permalink
Re add old optimization settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanSarwar45 committed Dec 12, 2023
1 parent 2fbb5a7 commit 2a334d7
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 41 deletions.
9 changes: 7 additions & 2 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -27,6 +28,7 @@ class OnBoardingPageState extends State<OnBoardingPage> {
final introKey = GlobalKey<IntroductionScreenState>();

void _onIntroEnd(context) {
GetStorage().write('onboarded', true);
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => const NavScaffold()),
);
Expand Down Expand Up @@ -70,7 +72,11 @@ class OnBoardingPageState extends State<OnBoardingPage> {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const VendorListScreen()));
builder: (context) => SettingGroupScreen(
settingGroup:
appSettings.getGroup("Reliability"),
isAppSettings: false,
)));
},
style: ElevatedButton.styleFrom(
backgroundColor: colorScheme.primary,
Expand Down Expand Up @@ -199,7 +205,6 @@ class _AppState extends State<App> {
case Routes.rootRoute:
final bool? onboarded = GetStorage().read('onboarded');
if (onboarded == null) {
GetStorage().write('first_launch', true);
return MaterialPageRoute(
builder: (context) => const OnBoardingPage());
} else {
Expand Down
98 changes: 63 additions & 35 deletions lib/settings/data/settings_schema.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -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<String> _getDateSettingOption(String format) {
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions lib/settings/types/setting_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -13,7 +13,8 @@ class SettingAction extends SettingItem {

@override
SettingAction copy() {
return SettingAction(name, action);
return SettingAction(name, action,
description: description, searchTags: searchTags);
}

@override
Expand Down
3 changes: 2 additions & 1 deletion lib/settings/types/setting_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class SettingPageLink extends SettingItem {

@override
SettingPageLink copy() {
return SettingPageLink(name, screen);
return SettingPageLink(name, screen,
description: description, searchTags: searchTags);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/settings/widgets/setting_action_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _SettingActionCardState<T> extends State<SettingActionCard> {
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(
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2a334d7

Please sign in to comment.