Add new Dismiss and CanSnooze functions.
CanSnooze informs if snooze can be applied on Alarm. It is
possible when Snooze is enabled for alarm and maximum numer
of snooze attempts hasn't been reached.
Dismiss is a function that resets snooze context for given alarm.
It resets current snooze attempt counter. Is alarm do not support
snooze it does nothing.
Change-Id: I554800d5b004dec3f046cd7d5bf08d65b886b222
void EnableSnooze();
void DisableSnooze();
bool IsSnoozeEnabled() const;
+ bool CanSnooze() const;
void SetSnoozeInterval(unsigned int seconds);
unsigned int GetSnoozeInterval() const;
void SetSnoozeMaxAttemps(unsigned int attemps);
void Serialize(utils::IWriter &w) const;
double GetVolume() const;
void SetVolume(double volume);
+ void Dismiss();
/** Implement guideline requirement. Two alarms are considered
* same if they have same time and name */
inline bool operator==(const Alarm &a) { return (time == a.time) && (a.name == name); }
- inline bool operator==(const AlarmId id) { return this->alarm_id == id; }
+ inline bool operator==(const AlarmId id) { return (this->alarm_id == id) || (this->snooze.alarm_id == id); }
private:
int alarm_id;
std::string name;
view_ = nullptr;
model_ = nullptr;
presenter_ = nullptr;
+
+ model::AlarmProvider::Sync();
}
}
Alarm::Alarm() :
flags(WeekDay::ALL_WEEK)
{
- snooze.attempts_max = 3;
+ SetSnoozeMaxAttemps(3);
+ SetSnoozeInterval(5 * 60);
+ DisableSnooze();
activated = false;
- snooze_enabled = false;
- snooze.alarm_id = -1;
alarm_id = -1;
+ snooze.alarm_id = -1;
+ snooze.attempt = 0;
}
void Alarm::Activate()
app_control_destroy(control);
}
+void Alarm::Dismiss()
+{
+ if (!activated || !snooze_enabled)
+ return;
+
+ snooze.attempt = 0;
+}
+
+bool Alarm::CanSnooze() const
+{
+ if (!activated || !snooze_enabled)
+ return false;
+
+ if (snooze.attempt >= snooze.attempts_max)
+ return false;
+
+ return true;
+}
+
void Alarm::EnableSnooze()
{
snooze_enabled = true;
view->SetTitle(alarm->GetName().c_str());
view->SetTimeLabel(time.Meridiem().c_str(), time.GetFormattedTime("HH:mm").c_str(), time.GetDate().c_str());
- if (alarm->IsSnoozeEnabled())
+ if (alarm->CanSnooze())
view_->EnableSnooze(true);
else
view_->EnableSnooze(false);
void RingPresenter::DismissButtonClicked()
{
+ alarm_->Dismiss();
animator_.Remove();
controller::RingController::GetInstance().ShutDown();
}