M module-services/service-time/AlarmOperations.cpp => module-services/service-time/AlarmOperations.cpp +5 -3
@@ 264,12 264,12 @@ namespace alarms
}
}
- auto AlarmOperationsCommon::minuteUpdated(TimePoint now) -> void
+ auto AlarmOperationsCommon::minuteUpdated(TimePoint now) -> bool
{
- processEvents(now);
+ return processEvents(now);
}
- void AlarmOperationsCommon::processEvents(TimePoint now)
+ bool AlarmOperationsCommon::processEvents(TimePoint now)
{
const auto isHandlingInProgress = !ongoingSingleEvents.empty();
if (!nextSingleEvents.empty()) {
@@ 284,7 284,9 @@ namespace alarms
switchAlarmExecution(*(ongoingSingleEvents.front()), true);
handleActiveAlarmsCountChange();
handleSnoozedAlarmsCountChange();
+ return true;
}
+ return false;
}
void AlarmOperationsCommon::addAlarmExecutionHandler(const alarms::AlarmType type,
M module-services/service-time/AlarmOperations.hpp => module-services/service-time/AlarmOperations.hpp +3 -3
@@ 56,7 56,7 @@ namespace alarms
virtual void postponeSnooze(const std::uint32_t id,
const TimePoint nextAlarmTime,
OnSnoozeRingingAlarm callback) = 0;
- virtual void minuteUpdated(TimePoint now) = 0;
+ virtual bool minuteUpdated(TimePoint now) = 0;
virtual void addAlarmExecutionHandler(const alarms::AlarmType type,
const std::shared_ptr<alarms::AlarmHandler> handler) = 0;
virtual void stopAllSnoozedAlarms() = 0;
@@ 100,7 100,7 @@ namespace alarms
void postponeSnooze(const std::uint32_t id,
const TimePoint nextAlarmTime,
OnSnoozeRingingAlarm callback) override;
- void minuteUpdated(TimePoint now) override;
+ bool minuteUpdated(TimePoint now) override;
void addAlarmExecutionHandler(const alarms::AlarmType type,
const std::shared_ptr<alarms::AlarmHandler> handler) override;
void stopAllSnoozedAlarms() override;
@@ 140,7 140,7 @@ namespace alarms
OnGetAlarmsProcessed handledCallback);
void checkAndUpdateCache(AlarmEventRecord record);
void switchAlarmExecution(const SingleEventRecord &singleAlarmEvent, bool newStateOn);
- void processEvents(TimePoint now);
+ bool processEvents(TimePoint now);
void processNextEventsQueue(const TimePoint now);
void processSnoozedEventsQueue(const TimePoint now);
virtual void onAlarmTurnedOff(const std::shared_ptr<AlarmEventRecord> &event, alarms::AlarmType alarmType);
M products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsProgressPresenter.cpp => products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsProgressPresenter.cpp +4 -0
@@ 92,4 92,8 @@ namespace app::bgSounds
{
return player.isPaused();
}
+ void BGSoundsProgressPresenter::onBeforeShow()
+ {
+ getView()->setTimeFormat(timeModel->getTimeFormat());
+ }
} // namespace app::bgSounds
M products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsProgressPresenter.hpp => products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsProgressPresenter.hpp +2 -0
@@ 47,6 47,7 @@ namespace app::bgSounds
virtual void setTimer(std::unique_ptr<app::TimerWithCallbacks> &&timer) = 0;
virtual void handleUpdateTimeEvent() = 0;
virtual bool isPaused() = 0;
+ virtual void onBeforeShow() = 0;
};
};
@@ 66,6 67,7 @@ namespace app::bgSounds
void setTimer(std::unique_ptr<app::TimerWithCallbacks> &&_timer) override;
void handleUpdateTimeEvent() override;
bool isPaused() override;
+ void onBeforeShow() override;
void onFinished();
M products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsProgressWindow.cpp => products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsProgressWindow.cpp +2 -0
@@ 75,6 75,8 @@ namespace gui
void BGSoundsProgressWindow::onBeforeShow(ShowMode mode, SwitchData *data)
{
+ presenter->onBeforeShow();
+
if (mode == ShowMode::GUI_SHOW_RETURN && presenter->isPaused()) {
presenter->resume();
return;
M products/BellHybrid/services/time/AlarmOperations.cpp => products/BellHybrid/services/time/AlarmOperations.cpp +33 -14
@@ 152,12 152,26 @@ namespace alarms
bedtime(std::move(bedtimeSettingsProvider))
{}
- void AlarmOperations::minuteUpdated(TimePoint now)
+ bool AlarmOperations::minuteUpdated(TimePoint now)
{
- AlarmOperationsCommon::minuteUpdated(now);
- processPreWakeUp(now);
- processSnoozeChime(now);
- processBedtime(now);
+ /**
+ * A very simple alarm priority:
+ * 1. Main alarm
+ * 2. Pre wake up
+ * 3. Snooze
+ * 4. Bedtime
+ * By design, there is no possibility to have both the main alarm, pre wakeup, and snooze alarm set for the same
+ * timestamp hence it is safe to process these three in the one go.
+ */
+ auto wasAlarmConsumed = AlarmOperationsCommon::minuteUpdated(now);
+ wasAlarmConsumed |= processPreWakeUp(now);
+ wasAlarmConsumed |= processSnoozeChime(now);
+
+ if (not wasAlarmConsumed) {
+ processBedtime(now);
+ }
+
+ return false;
}
void AlarmOperations::stopAllSnoozedAlarms()
@@ 166,22 180,22 @@ namespace alarms
AlarmOperationsCommon::stopAllSnoozedAlarms();
}
- void AlarmOperations::processPreWakeUp(TimePoint now)
+ bool AlarmOperations::processPreWakeUp(TimePoint now)
{
if (nextSingleEvents.empty()) {
- return;
+ return false;
}
auto nextEvent = getNextPreWakeUpEvent();
if (!nextEvent.isValid()) {
- return;
+ return false;
}
const auto decision = preWakeUp.decide(now, nextEvent);
if (!decision.timeForChime && !decision.timeForFrontlight) {
- return;
+ return false;
}
- handlePreWakeUp(nextEvent, decision);
+ return handlePreWakeUp(nextEvent, decision);
}
void AlarmOperations::processBedtime(TimePoint now)
@@ 210,27 224,30 @@ namespace alarms
return event;
}
- void AlarmOperations::handlePreWakeUp(const SingleEventRecord &event, PreWakeUp::Decision decision)
+ bool AlarmOperations::handlePreWakeUp(const SingleEventRecord &event, PreWakeUp::Decision decision)
{
if (auto alarmEventPtr = std::dynamic_pointer_cast<AlarmEventRecord>(event.parent); alarmEventPtr) {
if (decision.timeForChime) {
handleAlarmEvent(alarmEventPtr, alarms::AlarmType::PreWakeUpChime, true);
+ return true;
}
if (decision.timeForFrontlight) {
handleAlarmEvent(alarmEventPtr, alarms::AlarmType::PreWakeUpFrontlight, true);
+ return true;
}
}
+ return false;
}
- void AlarmOperations::processSnoozeChime(TimePoint now)
+ bool AlarmOperations::processSnoozeChime(TimePoint now)
{
if (!ongoingSingleEvents.empty()) {
- return;
+ return false;
}
auto settings = snoozeChimeSettings->getSettings();
if (!settings.enabled) {
- return;
+ return false;
}
for (auto &snoozedEvent : snoozedSingleEvents) {
@@ 239,8 256,10 @@ namespace alarms
const auto isTimeForChime = (minuteDelta % settings.chimeInterval.count()) == 0;
if (isTimeForChime) {
handleSnoozeChime(*snoozedEvent, true);
+ return true;
}
}
+ return false;
}
void AlarmOperations::handleSnoozeChime(const SingleEventRecord &event, bool newStateOn)
M products/BellHybrid/services/time/include/time/AlarmOperations.hpp => products/BellHybrid/services/time/include/time/AlarmOperations.hpp +5 -5
@@ 94,15 94,15 @@ namespace alarms
std::unique_ptr<SnoozeChimeSettingsProvider> &&snoozeChimeSettingsProvider,
std::unique_ptr<AbstractBedtimeSettingsProvider> &&BedtimeModel);
- void minuteUpdated(TimePoint now) override;
+ private:
+ bool minuteUpdated(TimePoint now) override;
void stopAllSnoozedAlarms() override;
- void processPreWakeUp(TimePoint now);
- void processSnoozeChime(TimePoint now);
+ bool processPreWakeUp(TimePoint now);
+ bool processSnoozeChime(TimePoint now);
void stopAllSnoozeChimes();
- private:
SingleEventRecord getNextPreWakeUpEvent();
- void handlePreWakeUp(const SingleEventRecord &event, PreWakeUp::Decision decision);
+ bool handlePreWakeUp(const SingleEventRecord &event, PreWakeUp::Decision decision);
void handleSnoozeChime(const SingleEventRecord &event, bool newStateOn);
void handleBedtime(const SingleEventRecord &event, bool decision);
void processBedtime(TimePoint now);
M products/PurePhone/services/time/AlarmOperations.cpp => products/PurePhone/services/time/AlarmOperations.cpp +2 -2
@@ 25,8 25,8 @@ namespace alarms
: AlarmOperationsCommon{std::move(alarmEventsRepo), std::move(getCurrentTimeCallback)}
{}
- void AlarmOperations::minuteUpdated(TimePoint now)
+ bool AlarmOperations::minuteUpdated(TimePoint now)
{
- AlarmOperationsCommon::minuteUpdated(now);
+ return AlarmOperationsCommon::minuteUpdated(now);
}
} // namespace alarms
M products/PurePhone/services/time/include/time/AlarmOperations.hpp => products/PurePhone/services/time/include/time/AlarmOperations.hpp +1 -1
@@ 22,7 22,7 @@ namespace alarms
AlarmOperations(std::unique_ptr<AbstractAlarmEventsRepository> &&alarmEventsRepo,
GetCurrentTime getCurrentTimeCallback);
- void minuteUpdated(TimePoint now) override;
+ bool minuteUpdated(TimePoint now) override;
private:
};