Alarm: fix snooze by adding new API
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 16 Sep 2016 15:44:52 +0000 (17:44 +0200)
committerr.czerski <r.czerski@samsung.com>
Mon, 19 Sep 2016 08:32:05 +0000 (10:32 +0200)
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

clock/inc/Model/Alarm.h
clock/src/Controller/RingController.cpp
clock/src/Model/Alarm.cpp
clock/src/Presenter/RingPresenter.cpp

index e012554..e3cdcaa 100644 (file)
@@ -31,6 +31,7 @@ namespace model {
                        void EnableSnooze();
                        void DisableSnooze();
                        bool IsSnoozeEnabled() const;
+                       bool CanSnooze() const;
                        void SetSnoozeInterval(unsigned int seconds);
                        unsigned int GetSnoozeInterval() const;
                        void SetSnoozeMaxAttemps(unsigned int attemps);
@@ -48,11 +49,12 @@ namespace model {
                        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;
index e248d37..09b6bdf 100644 (file)
@@ -68,6 +68,8 @@ void RingController::ShutDown()
        view_ = nullptr;
        model_ = nullptr;
        presenter_ = nullptr;
+
+       model::AlarmProvider::Sync();
 }
 
 }
index 59199fc..e9eef2c 100644 (file)
@@ -36,11 +36,13 @@ static app_control_h AppControlCreate()
 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()
@@ -123,6 +125,25 @@ void Alarm::Snooze()
        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;
index 09cc938..085e0c1 100644 (file)
@@ -52,7 +52,7 @@ RingPresenter::RingPresenter(view::RingView *view, model::Alarm *alarm)
        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);
@@ -69,6 +69,7 @@ void RingPresenter::TimeUpdateRequest()
 
 void RingPresenter::DismissButtonClicked()
 {
+       alarm_->Dismiss();
        animator_.Remove();
        controller::RingController::GetInstance().ShutDown();
 }