Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable snooze for alarms #85

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/android-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ jobs:
with:
artifacts: "build/app/outputs/bundle/release/*.aab,build/app/outputs/flutter-apk/*.apk"
body: ${{steps.github_release.outputs.changelog}}
draft: true

26 changes: 18 additions & 8 deletions lib/alarm/data/alarm_settings_schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import 'package:clock_app/audio/types/ringtone_player.dart';
import 'package:clock_app/common/types/file_item.dart';
import 'package:clock_app/common/utils/ringtones.dart';
import 'package:clock_app/settings/types/setting.dart';
import 'package:clock_app/settings/types/setting_enable_condition.dart';
import 'package:clock_app/settings/types/setting_group.dart';
import 'package:clock_app/timer/types/time_duration.dart';
import 'package:flutter/material.dart';

const alarmSchemaVersion = 2;
const alarmSchemaVersion = 3;

SettingGroup alarmSettingsSchema = SettingGroup(
version: alarmSchemaVersion,
Expand Down Expand Up @@ -55,22 +56,22 @@ SettingGroup alarmSettingsSchema = SettingGroup(
ToggleSettingOption("S", 7),
],
enableConditions: [
SettingEnableConditionParameter("Type", WeeklyAlarmSchedule)
SettingEnableConditionParameter(["Type"], WeeklyAlarmSchedule)
],
),
DateTimeSetting(
"Dates",
[],
enableConditions: [
SettingEnableConditionParameter("Type", DatesAlarmSchedule)
SettingEnableConditionParameter(["Type"], DatesAlarmSchedule)
],
),
DateTimeSetting(
"Date Range",
[],
rangeOnly: true,
enableConditions: [
SettingEnableConditionParameter("Type", RangeAlarmSchedule)
SettingEnableConditionParameter(["Type"], RangeAlarmSchedule)
],
),
SelectSetting<RangeInterval>(
Expand All @@ -80,7 +81,7 @@ SettingGroup alarmSettingsSchema = SettingGroup(
SelectSettingOption("Weekly", RangeInterval.weekly),
],
enableConditions: [
SettingEnableConditionParameter("Type", RangeAlarmSchedule)
SettingEnableConditionParameter(["Type"], RangeAlarmSchedule)
],
),
],
Expand Down Expand Up @@ -111,7 +112,7 @@ SettingGroup alarmSettingsSchema = SettingGroup(
DurationSetting(
"Time To Full Volume", const TimeDuration(minutes: 1),
enableConditions: [
SettingEnableConditionParameter("Rising Volume", true)
SettingEnableConditionParameter(["Rising Volume"], true)
]),
],
),
Expand All @@ -126,19 +127,28 @@ SettingGroup alarmSettingsSchema = SettingGroup(
SettingGroup(
"Snooze",
[
SliderSetting("Length", 1, 30, 5, unit: "minutes"),
SwitchSetting("Enabled", true),
SliderSetting("Length", 1, 30, 5, unit: "minutes", enableConditions: [
SettingEnableConditionParameter(["Enabled"], true)
]),
SliderSetting("Max Snoozes", 1, 10, 3,
unit: "times",
snapLength: 1,
description:
"The maximum number of times the alarm can be snoozed before it is dismissed"),
"The maximum number of times the alarm can be snoozed before it is dismissed",
enableConditions: [
SettingEnableConditionParameter(["Enabled"], true)
]),
SettingGroup("While Snoozed", [
SwitchSetting("Prevent Disabling", false),
SwitchSetting("Prevent Deletion", false),
], enableConditions: [
SettingEnableConditionParameter(["Enabled"], true)
]),
],
icon: Icons.snooze_rounded,
summarySettings: [
"Enabled",
"Length",
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/alarm/logic/alarm_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void triggerAlarm(int scheduleId, Json params) async {
title: title,
body: TimeOfDayUtils.decode(params['timeOfDay'])
.formatToString(timeFormatString),
showSnoozeButton: !alarm.canBeSnoozed,
showSnoozeButton: alarm.canBeSnoozed,
tasksRequired: alarm.tasks.isNotEmpty,
snoozeActionLabel: "Snooze",
dismissActionLabel: "Dismiss",
Expand Down
3 changes: 2 additions & 1 deletion lib/alarm/screens/alarm_notification_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class _AlarmNotificationScreenState extends State<AlarmNotificationScreen> {
.getGroup("Alarm")
.getSetting("Dismiss Action Type")
.value
.builder(_setNextWidget, _snoozeAlarm, "Dismiss", "Snooze");
.builder(_setNextWidget, alarm.canBeSnoozed ? _snoozeAlarm() : null,
"Dismiss", "Snooze");

void _setNextWidget() {
setState(() {
Expand Down
4 changes: 3 additions & 1 deletion lib/alarm/types/alarm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ class Alarm extends CustomizableListItem {
int get currentScheduleId => activeSchedule.currentAlarmRunnerId;
int get snoozeCount => _snoozeCount;
bool get maxSnoozeIsReached => _snoozeCount >= maxSnoozes;
bool get canBeSnoozed => maxSnoozeIsReached;
bool get canBeSnoozed =>
!maxSnoozeIsReached &&
_settings.getGroup("Snooze").getSetting("Enabled").value;
bool get shouldSkipNextAlarm =>
_skippedTime == currentScheduleDateTime &&
currentScheduleDateTime != null;
Expand Down
2 changes: 1 addition & 1 deletion lib/alarm/types/notification_action.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

class NotificationAction {
final void Function(VoidCallback onDismiss, VoidCallback onSnooze,
final void Function(VoidCallback onDismiss, VoidCallback? onSnooze,
String dismissLabel, String snoozeLabel) builder;

const NotificationAction({
Expand Down
6 changes: 3 additions & 3 deletions lib/common/utils/popup_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'package:clock_app/common/types/popup_action.dart';
import 'package:flutter/material.dart';

PopupAction getDeletePopupAction(BuildContext context, Function callback) {
return PopupAction(
"Delete", callback, Icons.delete, Theme.of(context).colorScheme.error);
return PopupAction("Delete", callback, Icons.delete_rounded,
Theme.of(context).colorScheme.error);
}

PopupAction getDuplicatePopupAction(Function callback) {
return PopupAction("Duplicate", callback, Icons.copy);
return PopupAction("Duplicate", callback, Icons.copy_rounded);
}
3 changes: 3 additions & 0 deletions lib/common/widgets/fields/color_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class _ColorBottomSheetState extends State<ColorBottomSheet> {
ColorPickerType.wheel: true,
},
enableShadesSelection: true,
subheading: Text('Select color shade',
style: textTheme.titleSmall
?.copyWith(color: colorScheme.onSurface)),
showColorCode: true,
copyPasteBehavior: const ColorPickerCopyPasteBehavior(
copyFormat: ColorPickerCopyFormat.hexRRGGBB),
Expand Down
8 changes: 6 additions & 2 deletions lib/common/widgets/slidable_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ class SlideActionState extends State<SlideAction>
child: Row(
children: [
Text(
widget.leftText ?? 'Left',
widget.leftText ?? widget.rightText ?? 'Left',
style: Theme.of(context).textTheme.displaySmall?.copyWith(
color: Theme.of(context).colorScheme.onSecondary),
),
const Spacer(),
Text(
widget.rightText ?? 'Right',
widget.rightText ?? widget.leftText ?? 'Right',
style: Theme.of(context).textTheme.displaySmall?.copyWith(
color: Theme.of(context).colorScheme.onSecondary),
),
Expand All @@ -131,12 +131,16 @@ class SlideActionState extends State<SlideAction>
if (_progress < 0.1) {
if (widget.onSubmitLeft != null) {
widget.onSubmitLeft!();
} else if (widget.onSubmitRight != null) {
widget.onSubmitRight!();
} else {
_cancelAnimation();
}
} else if (_progress > 0.9) {
if (widget.onSubmitRight != null) {
widget.onSubmitRight!();
} else if (widget.onSubmitLeft != null) {
widget.onSubmitLeft!();
} else {
_cancelAnimation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class AreaNotificationAction extends StatelessWidget {
required this.dismissLabel,
required this.snoozeLabel,
required this.onDismiss,
required this.onSnooze})
this.onSnooze})
: super(key: key);

final String dismissLabel;
final String snoozeLabel;
final VoidCallback onDismiss;
final VoidCallback onSnooze;
final VoidCallback? onSnooze;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -47,23 +47,24 @@ class AreaNotificationAction extends StatelessWidget {
),
),
const SizedBox(height: 8),
Expanded(
flex: 1,
child: SizedBox(
width: double.infinity,
child: CardContainer(
color: colorScheme.primary,
onTap: onSnooze,
child: Center(
child: Text(
snoozeLabel,
style: textTheme.titleMedium?.copyWith(
color: colorScheme.onPrimary,
),
)),
if (onSnooze != null)
Expanded(
flex: 1,
child: SizedBox(
width: double.infinity,
child: CardContainer(
color: colorScheme.primary,
onTap: onSnooze,
child: Center(
child: Text(
snoozeLabel,
style: textTheme.titleMedium?.copyWith(
color: colorScheme.onPrimary,
),
)),
),
),
),
)
)
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,41 @@ class ButtonsNotificationAction extends StatelessWidget {
required this.dismissLabel,
required this.snoozeLabel,
required this.onDismiss,
required this.onSnooze})
this.onSnooze})
: super(key: key);

final String dismissLabel;
final String snoozeLabel;
final VoidCallback onDismiss;
final VoidCallback onSnooze;
final VoidCallback? onSnooze;

@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final TextTheme textTheme = theme.textTheme;
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CardContainer(
onTap: onSnooze,
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text(snoozeLabel,
style: Theme.of(context).textTheme.titleMedium),
if (onSnooze != null)
CardContainer(
color: colorScheme.primary,
onTap: onSnooze,
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text(snoozeLabel,
style: textTheme.titleMedium
?.copyWith(color: colorScheme.onPrimary)),
),
),
),
CardContainer(
color: colorScheme.primary,
onTap: onDismiss,
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text(dismissLabel,
style: Theme.of(context).textTheme.titleMedium),
style: textTheme.titleMedium
?.copyWith(color: colorScheme.onPrimary)),
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ class SlideNotificationAction extends StatelessWidget {
required this.dismissLabel,
required this.snoozeLabel,
required this.onDismiss,
required this.onSnooze})
this.onSnooze})
: super(key: key);

final String dismissLabel;
final String snoozeLabel;
final VoidCallback onDismiss;
final VoidCallback onSnooze;
final VoidCallback? onSnooze;

@override
Widget build(BuildContext context) {
return SlideAction(
leftText: snoozeLabel,
leftText: onSnooze != null ? snoozeLabel : null,
rightText: dismissLabel,
onSubmitRight: onDismiss,
onSubmitLeft: onSnooze,
Expand Down
3 changes: 2 additions & 1 deletion lib/settings/data/appearance_settings_schema.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:clock_app/app.dart';
import 'package:clock_app/settings/data/settings_schema.dart';
import 'package:clock_app/settings/types/setting.dart';
import 'package:clock_app/settings/types/setting_enable_condition.dart';
import 'package:clock_app/settings/types/setting_group.dart';
import 'package:clock_app/theme/screens/themes_screen.dart';
import 'package:clock_app/theme/theme.dart';
Expand Down Expand Up @@ -45,7 +46,7 @@ SettingGroup appearanceSettingsSchema = SettingGroup(
ColorSetting("Accent Color", Colors.cyan, onChange: (context, color) {
App.setColorScheme(context);
}, enableConditions: [
SettingEnableConditionParameter("Override Accent Color", true)
SettingEnableConditionParameter(["Override Accent Color"], true)
], searchTags: [
"primary",
"color"
Expand Down
4 changes: 2 additions & 2 deletions lib/settings/data/settings_schema.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:clock_app/settings/data/accessibility_settings_schema.dart';
import 'package:clock_app/settings/data/alarm_settings_schema.dart';
import 'package:clock_app/settings/data/alarm_app_settings_schema.dart';
import 'package:clock_app/settings/data/appearance_settings_schema.dart';
import 'package:clock_app/settings/data/backup_settings_schema.dart';
import 'package:clock_app/settings/data/developer_settings_schema.dart';
import 'package:clock_app/settings/data/general_settings_schema.dart';
import 'package:clock_app/settings/data/stopwatch_settings_schema.dart';
import 'package:clock_app/settings/data/timer_settings_schema.dart';
import 'package:clock_app/settings/data/timer_app_settings_schema.dart';
import 'package:clock_app/settings/screens/about_screen.dart';
import 'package:clock_app/settings/types/setting_group.dart';
import 'package:clock_app/settings/types/setting_link.dart';
Expand Down
5 changes: 4 additions & 1 deletion lib/settings/logic/get_setting_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ Widget? getSettingItemWidget(
VoidCallback? onSettingChanged,
bool isAppSettings = true,
}) {
if (!item.isEnabled) return null;
if (item is SettingGroup) {
// print(
// "setting group ${item.name} ${item.isEnabled} ${item.enableSettings.map((e) => e.setting.name)}");
return SettingGroupCard(
settingGroup: item,
checkDependentEnableConditions: checkDependentEnableConditions,
Expand All @@ -68,7 +71,7 @@ Widget? getSettingItemWidget(
showAsCard: showAsCard,
);
} else if (item is Setting) {
if (!item.isEnabled || !item.isVisual) return null;
if (!item.isVisual) return null;

onChanged(dynamic value) {
if (item.changesEnableCondition) {
Expand Down
Loading