EditAlarmPresenter: implement basic functionality
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 30 Aug 2016 13:49:09 +0000 (15:49 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Sun, 11 Sep 2016 05:58:30 +0000 (07:58 +0200)
Allow to create new Alarm on basic edit alarm view (shown at startup).
The synchronization with different view is not supported yet, so
app restart is required to sync other views.

Change-Id: I1715f730197e4bde6a3b9af30c5c7b0cb64241c4

clock/inc/Model/Alarm.h
clock/inc/Presenter/EditAlarmPresenter.h
clock/inc/View/EditAlarmView.h
clock/src/Model/AlarmProvider.cpp
clock/src/Model/AlarmProviderFile.cpp
clock/src/Presenter/EditAlarmPresenter.cpp [new file with mode: 0644]
clock/src/View/MainView.cpp

index ddfa63c..f3e39a8 100644 (file)
@@ -9,6 +9,8 @@
 #include "Utils/Serialization.h"
 #include "Utils/Time.h"
 
+#include "log.h"
+
 namespace model {
        typedef int AlarmId;
        enum class AlarmType {
index d489750..3ed6ff7 100644 (file)
 #ifndef _CLOCK_PRESENTER_EDIT_ALARM_H_
 #define _CLOCK_PRESENTER_EDIT_ALARM_H_
 
+#include "View/EditAlarmView.h"
+#include "Model/Alarm.h"
+
 namespace presenter {
        class EditAlarmPresenter {
+               public:
+                       EditAlarmPresenter(model::Alarm *alarm, view::EditAlarmView& view);
+               private:
+                       model::Alarm *alarm_;
+                       view::EditAlarmView &view_;
+                       void OnEditDone();
+                       void OnEditCancel();
        };
 } /* presenter */
 
index 6c529cc..f9ed19c 100644 (file)
@@ -27,6 +27,7 @@
 
 namespace view {
        class EditAlarmView : protected PageView {
+               public:
                struct AlarmViewInfo {
                        utils::Time time;
                        model::WeekFlags flags;
@@ -36,7 +37,6 @@ namespace view {
                        std::string melody;
                        model::AlarmType type;
                };
-               public:
                        typedef std::function<void(AlarmViewInfo)> EditDoneCallback;
                        typedef std::function<void(void)> EditCancelCallback;
 
@@ -46,6 +46,8 @@ namespace view {
                        EditAlarmView();
                        Evas_Object *GetEvasObject();
 
+                       const AlarmViewInfo& GetData() const { return data_; }
+
                protected:
                        virtual void CreateContent();
                        virtual void DestroyContent();
index 035a292..c6f0737 100644 (file)
@@ -16,7 +16,7 @@ AlarmProvider *AlarmProvider::GetInstance()
        static AlarmProvider *instance;
        if (!instance) {
                BinaryFileReader reader(Utils::APP_DIR_DATA, DATABASE_FILE);
-               instance = new AlarmProviderStub(reader);
+               instance = new AlarmProviderFile(reader);
        }
        return instance;
 }
index 7703762..7a2c6fc 100644 (file)
@@ -4,6 +4,8 @@
 #include <cstdlib>
 #include <algorithm>
 
+#include "log.h"
+
 using namespace internal;
 using namespace model;
 using namespace utils;
diff --git a/clock/src/Presenter/EditAlarmPresenter.cpp b/clock/src/Presenter/EditAlarmPresenter.cpp
new file mode 100644 (file)
index 0000000..99e1b83
--- /dev/null
@@ -0,0 +1,51 @@
+#include "Presenter/EditAlarmPresenter.h"
+#include "log.h"
+#include "Model/AlarmProvider.h"
+
+using namespace presenter;
+using namespace view;
+using namespace model;
+
+
+EditAlarmPresenter::EditAlarmPresenter(model::Alarm *alarm, view::EditAlarmView& view) :
+       alarm_(alarm), view_(view)
+{
+       view_.RegisterEditDoneCallback(std::bind(&EditAlarmPresenter::OnEditDone, this));
+       view_.RegisterEditCancelCallback(std::bind(&EditAlarmPresenter::OnEditCancel, this));
+}
+
+void EditAlarmPresenter::OnEditDone()
+{
+       Alarm *alarm = alarm_;
+
+       // new alarm should be created
+       if (!alarm) {
+               alarm = new Alarm;
+       }
+
+       alarm->SetName(view_.GetData().name);
+       alarm->SetTime(view_.GetData().time);
+       alarm->SetType(view_.GetData().type);
+       alarm->SetMelody(view_.GetData().melody);
+       alarm->SetWeekFlags(view_.GetData().flags);
+       alarm->SetVolume(view_.GetData().volume);
+       alarm->SetMelody(view_.GetData().melody);
+
+       if (view_.GetData().snooze) {
+               alarm->EnableSnooze();
+       } else {
+               alarm->DisableSnooze();
+       }
+       alarm->Activate();
+
+       if (!alarm_) {
+               AlarmProvider::GetInstance()->Add(*alarm);
+       }
+
+       AlarmProvider::Sync();
+}
+
+void EditAlarmPresenter::OnEditCancel()
+{
+       DBG("Cancel adding alarm");
+}
index 3ef2625..b7b9ee1 100644 (file)
@@ -30,6 +30,7 @@
 #include "log.h"
 
 #include "Presenter/AlarmPresenter.h"
+#include "Presenter/EditAlarmPresenter.h"
 #include "Model/AlarmProvider.h"
 
 #include "Presenter/StopWatchPresenter.h"
@@ -204,7 +205,8 @@ void MainView::CreateContent()
        evas_object_show(alarm_->GetEvasObject());
        elm_object_item_content_set(item, alarm_->GetEvasObject());
 
-       new EditAlarmView();
+       EditAlarmView *ev = new EditAlarmView();
+       new EditAlarmPresenter(nullptr, *ev);
 }
 
 Evas_Object *MainView::GetEvasObject()