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
#include "Utils/Serialization.h"
#include "Utils/Time.h"
+#include "log.h"
+
namespace model {
typedef int AlarmId;
enum class AlarmType {
#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 */
namespace view {
class EditAlarmView : protected PageView {
+ public:
struct AlarmViewInfo {
utils::Time time;
model::WeekFlags flags;
std::string melody;
model::AlarmType type;
};
- public:
typedef std::function<void(AlarmViewInfo)> EditDoneCallback;
typedef std::function<void(void)> EditCancelCallback;
EditAlarmView();
Evas_Object *GetEvasObject();
+ const AlarmViewInfo& GetData() const { return data_; }
+
protected:
virtual void CreateContent();
virtual void DestroyContent();
static AlarmProvider *instance;
if (!instance) {
BinaryFileReader reader(Utils::APP_DIR_DATA, DATABASE_FILE);
- instance = new AlarmProviderStub(reader);
+ instance = new AlarmProviderFile(reader);
}
return instance;
}
#include <cstdlib>
#include <algorithm>
+#include "log.h"
+
using namespace internal;
using namespace model;
using namespace utils;
--- /dev/null
+#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");
+}
#include "log.h"
#include "Presenter/AlarmPresenter.h"
+#include "Presenter/EditAlarmPresenter.h"
#include "Model/AlarmProvider.h"
#include "Presenter/StopWatchPresenter.h"
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()