Skip to content

Commit

Permalink
Merge pull request #327 from vicolo-dev/release/0.5.2
Browse files Browse the repository at this point in the history
Merge changes into develop
  • Loading branch information
AhsanSarwar45 authored Sep 8, 2024
2 parents 115a689 + e5c58b6 commit 08ede4d
Show file tree
Hide file tree
Showing 135 changed files with 6,431 additions and 942 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- uses: subosito/flutter-action@v2
with:
flutter-version: "3.19.3"
flutter-version: "3.22.2"
channel: 'stable'
cache: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/android-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- uses: subosito/flutter-action@v2
with:
flutter-version: "3.19.3"
flutter-version: "3.22.2"
channel: 'stable'
cache: false

Expand Down
17 changes: 12 additions & 5 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission
android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission
android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission
android:name="android.permission.VIBRATE" />
<uses-permission
android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED" />

<application
android:label="@string/app_name"
tools:replace="android:label"
Expand Down Expand Up @@ -101,12 +104,16 @@
android:permission="android.permission.BIND_JOB_SERVICE"
android:directBootAware="true"
/>
<service
android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
android:foregroundServiceType="systemExempted"
android:exported="false" />
<!-- <service android:name="me.carda.awesome_notifications.core.services.ForegroundService" -->
<!-- android:enabled="true" -->
<!-- android:exported="false" -->
<!-- android:stopWithTask="true" -->
<!-- android:foregroundServiceType="phoneCall" -->
<!-- tools:replace="android:foregroundServiceType" -->
<!-- android:stopWithTask="false" -->
<!-- android:foregroundServiceType="systemExempted" -->
<!-- tools:replace="android:foregroundServiceType, android:stopWithTask" -->
<!-- ></service> -->
<receiver
android:enabled="true"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/251.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
✨ Enhancements

* Added option to turn on foreground notification to keep app alive. Go to General > Display > Reliability > Show Foreground Notification
* Added current lap card for stopwatch. Now you can view the current lap time in real time.
* Added option to show next alarm in filters. Go to Settings > Alarms > Filters > Show Next Alarm.
* Changed timer and stopwatch notification so time appears in title
* Updated translations

🐛 Fixes

* Fixed range schedule automatically getting disabled
* Fixed timer dismiss actions being mapped incorrectly
* Fixed timer add length not working correctly after timer rings

14 changes: 14 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/252.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
✨ Enhancements

* Added option to turn on foreground notification to keep app alive. Go to General > Display > Reliability > Show Foreground Notification
* Added current lap card for stopwatch. Now you can view the current lap time in real time.
* Added option to show next alarm in filters. Go to Settings > Alarms > Filters > Show Next Alarm.
* Changed timer and stopwatch notification so time appears in title
* Updated translations

🐛 Fixes

* Fixed range schedule automatically getting disabled
* Fixed timer dismiss actions being mapped incorrectly
* Fixed timer add length not working correctly after timer rings

14 changes: 14 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/253.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
✨ Enhancements

* Added option to turn on foreground notification to keep app alive. Go to General > Display > Reliability > Show Foreground Notification
* Added current lap card for stopwatch. Now you can view the current lap time in real time.
* Added option to show next alarm in filters. Go to Settings > Alarms > Filters > Show Next Alarm.
* Changed timer and stopwatch notification so time appears in title
* Updated translations

🐛 Fixes

* Fixed range schedule automatically getting disabled
* Fixed timer dismiss actions being mapped incorrectly
* Fixed timer add length not working correctly after timer rings

14 changes: 13 additions & 1 deletion lib/alarm/data/alarm_settings_schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

Expand Down Expand Up @@ -209,6 +210,15 @@ SettingGroup alarmSettingsSchema = SettingGroup(
100,
100,
unit: "%"),
SliderSetting(
"task_volume",
(context) => AppLocalizations.of(context)!.volumeWhileTasks,
0,
100,
50,
unit: "%",
getDescription: (context) => "Percentage of base volume",
),
SwitchSetting(
"Rising Volume",
(context) => AppLocalizations.of(context)!.risingVolumeSetting,
Expand Down Expand Up @@ -294,7 +304,9 @@ SettingGroup alarmSettingsSchema = SettingGroup(
ListSetting<AlarmTask>(
"Tasks",
(context) => AppLocalizations.of(context)!.tasksSetting,
[],
kDebugMode
? [AlarmTask(AlarmTaskType.math), AlarmTask(AlarmTaskType.sequence)]
: [],
alarmTaskSchemasMap.keys.map((key) => AlarmTask(key)).toList(),
addCardBuilder: (item) => AlarmTaskCard(task: item, isAddCard: true),
cardBuilder: (item, [onDelete, onDuplicate]) => AlarmTaskCard(
Expand Down
41 changes: 25 additions & 16 deletions lib/alarm/logic/alarm_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'dart:ui';
import 'package:clock_app/common/types/json.dart';
import 'package:clock_app/common/types/notification_type.dart';
import 'package:clock_app/common/utils/list_storage.dart';
import 'package:clock_app/debug/logic/logger.dart';
import 'package:clock_app/system/logic/initialize_isolate.dart';
import 'package:clock_app/timer/types/time_duration.dart';
import 'package:clock_app/timer/types/timer.dart';
import 'package:flutter/foundation.dart';
import 'package:clock_app/alarm/logic/schedule_alarm.dart';
Expand All @@ -21,18 +21,23 @@ import 'package:clock_app/timer/utils/timer_id.dart';

const String stopAlarmPortName = "stopAlarmPort";
const String updatePortName = "updatePort";
const String setAlarmVolumePortName = "setAlarmVolumePort";

@pragma('vm:entry-point')
void triggerScheduledNotification(int scheduleId, Json params) async {
debugPrint("Alarm triggered: $scheduleId");
FlutterError.onError = (FlutterErrorDetails details) {
logger.f(details.exception.toString());
};

logger.i("Alarm isolate triggered $scheduleId");
// print("Alarm Trigger Isolate: ${Service.getIsolateID(Isolate.current)}");
if (params == null) {
debugPrint("Params was null when triggering alarm");
logger.e("Params was null when triggering alarm");
return;
}

if (params['type'] == null) {
debugPrint("Params Type was null when triggering alarm");
logger.e("Params Type was null when triggering alarm");
return;
}

Expand Down Expand Up @@ -73,10 +78,9 @@ void stopScheduledNotification(List<dynamic> message) {
}

void triggerAlarm(int scheduleId, Json params) async {
logger.i("Alarm triggered $scheduleId");
if (params == null) {
if (kDebugMode) {
print("Params was null when triggering alarm");
}
logger.e("Params was null when triggering alarm");
return;
}

Expand All @@ -100,6 +104,7 @@ void triggerAlarm(int scheduleId, Json params) async {
now.millisecondsSinceEpoch >
alarm.currentScheduleDateTime!.millisecondsSinceEpoch +
1000 * 60 * 60) {
logger.i("Skipping alarm $scheduleId");
return;
}

Expand All @@ -118,6 +123,14 @@ void triggerAlarm(int scheduleId, Json params) async {
RingtonePlayer.playAlarm(alarm);
RingingManager.ringAlarm(scheduleId);

ReceivePort receivePort = ReceivePort();
IsolateNameServer.removePortNameMapping(setAlarmVolumePortName);
IsolateNameServer.registerPortWithName(
receivePort.sendPort, setAlarmVolumePortName);
receivePort.listen((message) {
setVolume(message[0]);
});

String timeFormatString = await loadTextFile("time_format_string");
String title = alarm.label.isEmpty ? "Alarm Ringing..." : alarm.label;

Expand All @@ -137,10 +150,11 @@ void triggerAlarm(int scheduleId, Json params) async {
}

void setVolume(double volume) {
RingtonePlayer.setVolume(volume);
RingtonePlayer.setVolume(volume / 100);
}

void stopAlarm(int scheduleId, AlarmStopAction action) async {
logger.i("Stopping alarm $scheduleId with action: ${action.name}");
if (action == AlarmStopAction.snooze) {
await updateAlarmById(scheduleId, (alarm) async => await alarm.snooze());
// await createSnoozeNotification(scheduleId);
Expand All @@ -158,6 +172,7 @@ void stopAlarm(int scheduleId, AlarmStopAction action) async {
}

void triggerTimer(int scheduleId, Json params) async {
logger.i("Timer triggered $scheduleId");
ClockTimer? timer = getTimerById(scheduleId);

if (timer == null || !timer.isRunning) {
Expand Down Expand Up @@ -194,18 +209,12 @@ void triggerTimer(int scheduleId, Json params) async {
}

void stopTimer(int scheduleId, AlarmStopAction action) async {
logger.i("Stopping timer $scheduleId with action: ${action.name}");
ClockTimer? timer = getTimerById(scheduleId);
if (timer == null) return;
if (action == AlarmStopAction.snooze) {
await scheduleSnoozeAlarm(
scheduleId,
Duration(minutes: timer.addLength.floor()),
ScheduledNotificationType.timer,
"stopTimer(): ${timer.addLength.floor()} added to timer",
);
updateTimerById(scheduleId, (timer) async {
timer.setTime(const TimeDuration(minutes: 1));
await timer.start();
await timer.snooze();
});
} else if (action == AlarmStopAction.dismiss) {
// If there was an alarm already ringing when the timer was triggered, we
Expand Down
32 changes: 20 additions & 12 deletions lib/alarm/logic/alarm_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@ import 'package:clock_app/common/utils/date_time.dart';
// Calculates the DateTime when the provided `time` will next occur
DateTime getDailyAlarmDate(
Time time, {
DateTime? scheduledDate,
DateTime? scheduleStartDate,
int interval = 1,
}) {
if (scheduledDate != null && scheduledDate.isAfter(DateTime.now())) {
return DateTime(scheduledDate.year, scheduledDate.month, scheduledDate.day,
time.hour, time.minute, time.second);
if (scheduleStartDate != null && scheduleStartDate.isAfter(DateTime.now())) {
return DateTime(scheduleStartDate.year, scheduleStartDate.month,
scheduleStartDate.day, time.hour, time.minute, time.second);
}

// If a date has not been provided, assume it to be today
scheduledDate = DateTime.now();
DateTime scheduleDate = DateTime.now();
DateTime alarmTime;

if (time.toHours() > scheduledDate.toHours()) {
if (time.toHours() > scheduleDate.toHours()) {
// If the time is in the future, set the alarm for today
alarmTime = DateTime(scheduledDate.year, scheduledDate.month,
scheduledDate.day, time.hour, time.minute, time.second);
alarmTime = DateTime(scheduleDate.year, scheduleDate.month,
scheduleDate.day, time.hour, time.minute, time.second);
} else {
// If the time has already passed, set the alarm for tomorrow
DateTime nextDateTime = scheduledDate.add(const Duration(days: 1));
alarmTime = DateTime(nextDateTime.year, nextDateTime.month,
nextDateTime.day, time.hour, time.minute, time.second);
// If the time has already passed, set the alarm for next occurence
if (scheduleStartDate != null) {
scheduleDate = scheduleStartDate;
}

while (scheduleDate.isBefore(DateTime.now())) {
scheduleDate = scheduleDate.add(Duration(days: interval));
}

alarmTime = DateTime(scheduleDate.year, scheduleDate.month,
scheduleDate.day, time.hour, time.minute, time.second);
}

return alarmTime;
Expand Down
11 changes: 9 additions & 2 deletions lib/alarm/logic/schedule_alarm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:clock_app/common/types/schedule_id.dart';
import 'package:clock_app/common/utils/date_time.dart';
import 'package:clock_app/common/utils/list_storage.dart';
import 'package:clock_app/common/utils/time_of_day.dart';
import 'package:clock_app/debug/logic/logger.dart';
import 'package:clock_app/settings/data/settings_schema.dart';

Future<void> scheduleAlarm(
Expand Down Expand Up @@ -68,7 +69,7 @@ Future<void> scheduleAlarm(
scheduleIds.add(ScheduleId(id: scheduleId));
await saveList<ScheduleId>(name, scheduleIds);

//
//
// if (type == ScheduledNotificationType.alarm && !snooze) {
// }
//
Expand All @@ -88,8 +89,10 @@ Future<void> scheduleAlarm(
'type': type.name,
},
);

logger.i('Scheduled alarm $scheduleId for $startDate of type ${type.name}: $description');
}
}
}

Future<void> cancelAlarm(int scheduleId, ScheduledNotificationType type) async {
if (!Platform.environment.containsKey('FLUTTER_TEST')) {
Expand All @@ -113,6 +116,8 @@ Future<void> cancelAlarm(int scheduleId, ScheduledNotificationType type) async {
}

AndroidAlarmManager.cancel(scheduleId);

logger.i('Canceled alarm $scheduleId of type ${type.name}');
}
}

Expand All @@ -128,4 +133,6 @@ Future<void> scheduleSnoozeAlarm(int scheduleId, Duration delay,
if (!Platform.environment.containsKey('FLUTTER_TEST')) {
await createSnoozeNotification(scheduleId, DateTime.now().add(delay));
}

logger.i('Scheduled snooze alarm $scheduleId for ${DateTime.now().add(delay)} with type ${type.name}: $description');
}
10 changes: 9 additions & 1 deletion lib/alarm/screens/alarm_notification_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'dart:ui';

import 'package:clock_app/alarm/logic/alarm_isolate.dart';
import 'package:clock_app/alarm/logic/update_alarms.dart';
import 'package:clock_app/alarm/utils/alarm_id.dart';
import 'package:clock_app/alarm/types/alarm.dart';
import 'package:clock_app/common/types/notification_type.dart';
import 'package:clock_app/common/widgets/clock/clock.dart';
import 'package:clock_app/debug/logic/logger.dart';
import 'package:clock_app/navigation/types/routes.dart';
import 'package:clock_app/notifications/types/fullscreen_notification_manager.dart';
import 'package:clock_app/navigation/types/alignment.dart';
Expand Down Expand Up @@ -37,6 +41,8 @@ class _AlarmNotificationScreenState extends State<AlarmNotificationScreen> {
void _setNextWidget() {
setState(() {
if (_currentIndex < 0) {
IsolateNameServer.lookupPortByName(setAlarmVolumePortName)
?.send([alarm.volume]);
_currentWidget = actionWidget;
} else if (_currentIndex >= alarm.tasks.length) {
if (widget.onPop != null) {
Expand All @@ -47,6 +53,8 @@ class _AlarmNotificationScreenState extends State<AlarmNotificationScreen> {
widget.dismissType, ScheduledNotificationType.alarm);
}
} else {
IsolateNameServer.lookupPortByName(setAlarmVolumePortName)
?.send([alarm.volume * alarm.volumeDuringTasks / 100]);
// RingtonePlayer.setVolume(0);
_currentWidget = alarm.tasks[_currentIndex].builder(_setNextWidget);
}
Expand Down Expand Up @@ -81,7 +89,7 @@ class _AlarmNotificationScreenState extends State<AlarmNotificationScreen> {
snoozeLabel: "Snooze",
);

debugPrint(e.toString());
logger.e(e.toString());
}

_setNextWidget();
Expand Down
Loading

0 comments on commit 08ede4d

Please sign in to comment.