#include "Utils/EventBus.h"
#include "View/EditAlarmView.h"
+#include "View/DeleteAlarmView.h"
+#include "View/MainView.h"
#include "Presenter/EditAlarmPresenter.h"
+#include "Presenter/DeleteAlarmPresenter.h"
#include "View/AlarmView.h"
#include "View/StopWatchView.h"
/**
* @brief Constructs MainController class object.
*/
- MainController() {};
+ MainController();
/**
* @brief Creates new "Edit/Create" alarm page.
presenter::StopWatchPresenter *stop_watch_presenter_;
presenter::TimerPresenter *timer_presenter_;
presenter::EditAlarmPresenter *edit_presenter_;
+ presenter::DeleteAlarmPresenter *delete_presenter_;
- view::EditAlarmView *edit_view_;
+ view::MainView main_view_;
+
+ view::EditAlarmView edit_page_;
+ view::DeleteAlarmView delete_page_;
/**
* @brief Creates new "Edit" alarm page.
class DeleteAlarmPresenter {
public:
DeleteAlarmPresenter(view::DeleteAlarmView *view, model::AlarmProvider *model);
+ ~DeleteAlarmPresenter();
private:
view::DeleteAlarmView *view_;
model::AlarmProvider *model_;
class EditAlarmPresenter {
public:
EditAlarmPresenter(model::Alarm *alarm, view::EditAlarmView& view);
+ ~EditAlarmPresenter();
private:
model::Alarm *alarm_;
view::EditAlarmView &view_;
typedef std::function<void(int)> ToggleCallback;
typedef std::function<void(void)> ButtonClickedCallback;
- AlarmView();
+ AlarmView(ui::IView &main);
void Clear();
int ItemAppend(utils::Time time, const char *name,
const model::WeekFlags flags, bool active);
public:
typedef std::function<void(void)> ButtonClickedCallback;
- DeleteAlarmView();
+ DeleteAlarmView(ui::IView &main);
void RegisterCancelButtonClickedCallback(ButtonClickedCallback cb) { onCancelButtonClicked_ = cb; }
void RegisterDeleteButtonClickedCallback(ButtonClickedCallback cb) { onDeleteButtonClicked_ = cb; }
const model::WeekFlags flags, bool active);
std::vector<int> GetSelectedItems() const;
protected:
- virtual void CreateContent();
+ virtual void CreateContent(Evas_Object *parent);
virtual void DestroyContent();
private:
Evas_Object *content_;
#include "View/WeekFlagsView.h"
namespace view {
- class EditAlarmView : protected PageView {
+ class EditAlarmView : public PageView {
public:
struct AlarmViewInfo {
utils::Time time;
void RegisterEditDoneCallback(EditDoneCallback cb) { onEditDone_ = cb; }
void RegisterEditCancelCallback(EditCancelCallback cb) { onEditCancel_ = cb; }
- EditAlarmView();
+ EditAlarmView(ui::IView &main);
+
Evas_Object *GetEvasObject();
const AlarmViewInfo& GetData() const { return data_; }
void SetData(const AlarmViewInfo &info);
protected:
- virtual void CreateContent();
+ virtual void CreateContent(Evas_Object *parent);
virtual void DestroyContent();
private:
public:
/**
- * @brief Retrieves singleton instance.
+ * @brief Constructs MainView class object
+ * @remarks Creates base GUI
*/
- static MainView &GetInstance();
+ MainView();
/**
* @brief Destructor
*/
IView *GetView(ViewType type);
private:
-
- /**
- * @brief Constructs MainView class object
- * @remarks Creates base GUI
- */
- MainView();
-
/**
* Adds conformant to window.
*/
/**
* @brief Constructs class object.
*/
- PageView();
+ PageView(ui::IView &main);
/**
* @brief Cleans all resources needed to be cleaned up.
/**
* @brief Creates page content.
*/
- virtual void CreateContent() = 0;
+ virtual void CreateContent(Evas_Object *parent) = 0;
/**
* @brief Creates page content.
void RegisterPoppedCallback(std::function<void(void)>);
protected:
+ Elm_Object_Item *navi_item_;
- /*
- * Get parent naviframe handle
+ /**
+ * Returns naviframe parent of the page.
*/
Evas_Object *GetNaviframe();
-
- Elm_Object_Item *navi_item_;
private:
+ Evas_Object *naviframe_;
+
static void ItemDeletedCallback(void*, Evas_Object*, void *);
std::vector<std::function<void(void)>> onPopped_;
void EmitPoppedEvent();
class StopWatchView : public ui::IView {
public:
- StopWatchView();
+ StopWatchView(ui::IView &main);
~StopWatchView();
Evas_Object *GetEvasObject(void);
class TimerView : public ui::IView {
public:
- TimerView();
+ TimerView(ui::IView &main);
~TimerView();
Evas_Object *GetEvasObject();
namespace view {
class WeekFlagsView : public PageView {
public:
- WeekFlagsView(model::WeekFlags &flags);
+ WeekFlagsView(ui::IView &main, model::WeekFlags &flags);
Evas_Object *GetEvasObject();
protected:
- virtual void CreateContent();
+ virtual void CreateContent(Evas_Object *parent);
virtual void DestroyContent();
private:
struct CheckBoxDesc {
class WorldClockView: public ui::IView {
public:
- WorldClockView();
+ WorldClockView(ui::IView &main);
Evas_Object *GetEvasObject(){return world_clock_main_;};
private:
void CreateTimezoneDetails();
- void CreateCustomLocationsList();
+ void CreateCustomLocationsList(Evas_Object *parent);
void CreateTimezoneCitiesList();
Evas_Object *CreateFloatingButton();
return instance;
}
+MainController::MainController() :
+ edit_page_(main_view_), delete_page_(main_view_),
+ delete_presenter_(nullptr), edit_presenter_(nullptr)
+{
+}
+
MainController::~MainController()
{
stop_watch_model_ = new model::StopWatch();
timer_model_ = new model::Timer();
- MainView::GetInstance().CreateContent();
-
- alarm_presenter_ = new AlarmPresenter((AlarmView *)MainView::GetInstance().GetView(ALARM), AlarmProvider::GetInstance());
- world_clock_presenter_ = new WorldClockPresenter((WorldClockView *)MainView::GetInstance().GetView(WORLD_CLOCK), world_clock_model_);
- stop_watch_presenter_ = new StopWatchPresenter((StopWatchView *)MainView::GetInstance().GetView(STOP_WATCH), stop_watch_model_);
- timer_presenter_ = new TimerPresenter((TimerView *)MainView::GetInstance().GetView(TIMER), timer_model_);
+ alarm_presenter_ = new AlarmPresenter((AlarmView *)main_view_.GetView(ALARM), AlarmProvider::GetInstance());
+ world_clock_presenter_ = new WorldClockPresenter((WorldClockView *)main_view_.GetView(WORLD_CLOCK), world_clock_model_);
+ stop_watch_presenter_ = new StopWatchPresenter((StopWatchView *)main_view_.GetView(STOP_WATCH), stop_watch_model_);
+ timer_presenter_ = new TimerPresenter((TimerView *)main_view_.GetView(TIMER), timer_model_);
listeners_.push_back(utils::EventBus::AddListener<AlarmCreateRequestEvent>(
std::bind(&MainController::CreateNewAlarmPage, this, _1)));
void MainController::CreateNewAlarmPage(Event &e)
{
- delete edit_view_;
delete edit_presenter_;
- edit_view_ = new EditAlarmView();
- edit_presenter_ = new EditAlarmPresenter(nullptr, *edit_view_);
+ edit_presenter_ = new EditAlarmPresenter(nullptr, edit_page_);
}
void MainController::CreateEditAlarmPage(Event &e)
{
AlarmEditRequestEvent &ev = (AlarmEditRequestEvent&)e;
- delete edit_view_;
delete edit_presenter_;
- edit_view_ = new EditAlarmView();
- edit_presenter_ = new EditAlarmPresenter(&ev.GetAlarm(), *edit_view_);
+ edit_presenter_ = new EditAlarmPresenter(&ev.GetAlarm(), edit_page_);
}
void MainController::CreateNewDeleteAlarmsPage(Event &e)
{
- static DeleteAlarmView *view;
- static DeleteAlarmPresenter *presenter;
-
- if (view) delete view;
- if (presenter) delete presenter;
+ delete delete_presenter_;
- view = new DeleteAlarmView();
- presenter = new DeleteAlarmPresenter(view, AlarmProvider::GetInstance());
+ delete_presenter_ = new DeleteAlarmPresenter(&delete_page_, AlarmProvider::GetInstance());
}
std::vector<std::reference_wrapper<Alarm>> alarms = model_->GetAlarms();
+ view_->PushPage();
+
for (auto a: alarms) {
int id = view_->ItemAppend(
a.get().GetTime(),
}
}
+DeleteAlarmPresenter::~DeleteAlarmPresenter()
+{
+ view_->PopPage();
+}
+
void DeleteAlarmPresenter::OnDeleteButtonClicked()
{
std::vector<int> deleted = view_->GetSelectedItems();
view_.RegisterEditDoneCallback(std::bind(&EditAlarmPresenter::OnEditDone, this));
view_.RegisterEditCancelCallback(std::bind(&EditAlarmPresenter::OnEditCancel, this));
view_.SetData(GetInfoForAlarm(alarm));
+
+ view_.PushPage();
+}
+
+EditAlarmPresenter::~EditAlarmPresenter()
+{
+ view_.PopPage();
}
view::EditAlarmView::AlarmViewInfo EditAlarmPresenter::GetDefaultInfo() const
delete id;
}
-AlarmView::AlarmView()
+AlarmView::AlarmView(ui::IView &main)
{
/* Base Layout */
- content_ = elm_layout_add(MainView::GetInstance().GetEvasObject());
+ content_ = elm_layout_add(main.GetEvasObject());
evas_object_size_hint_weight_set(content_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_layout_theme_set(content_, "layout", "application", "default");
evas_object_show(content_);
return strdup(formatted_time.str().c_str());
}
-DeleteAlarmView::DeleteAlarmView()
- : all_selected_(false)
+DeleteAlarmView::DeleteAlarmView(ui::IView &main)
+ : PageView(main), all_selected_(false)
{
- PushPage();
}
void DeleteAlarmView::ItemSelectToggle(void *data, Evas_Object *obj, void *event)
elm_genlist_item_selected_set(id->it, EINA_FALSE);
}
-void DeleteAlarmView::CreateContent()
+void DeleteAlarmView::CreateContent(Evas_Object *parent)
{
elm_object_item_style_set(navi_item_, "basic");
// left toolbar button
- left_btn_ = elm_button_add(GetNaviframe());
+ left_btn_ = elm_button_add(parent);
elm_object_text_set(left_btn_, "CANCEL");
elm_object_style_set(left_btn_, "naviframe/title_left");
evas_object_smart_callback_add(left_btn_, "clicked", OnCancelButtonClickedCb, this);
evas_object_show(left_btn_);
// right toolbar button
- right_btn_ = elm_button_add(GetNaviframe());
+ right_btn_ = elm_button_add(parent);
elm_object_style_set(right_btn_, "naviframe/title_right");
elm_object_text_set(right_btn_, "DELETE");
evas_object_smart_callback_add(right_btn_, "clicked", OnDeleteButtonClickedCb, this);
evas_object_show(right_btn_);
// main scrollable content
- content_ = elm_genlist_add(GetNaviframe());
+ content_ = elm_genlist_add(parent);
evas_object_size_hint_expand_set(content_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(content_, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_genlist_mode_set(content_, ELM_LIST_COMPRESS);
using namespace model;
-EditAlarmView::EditAlarmView() :
- week_flags_view_(data_.flags)
+EditAlarmView::EditAlarmView(ui::IView &main)
+ : PageView(main), week_flags_view_(main, data_.flags)
{
week_flags_view_.RegisterPoppedCallback(
std::bind(&EditAlarmView::OnWeekFlagsPagePopped, this));
- PushPage();
}
Evas_Object *EditAlarmView::GetEvasObject()
view->PopPage();
}
-void EditAlarmView::CreateContent()
+void EditAlarmView::CreateContent(Evas_Object *parent)
{
// set page style - "basic" style is supported by default tizen theme
elm_object_item_style_set(navi_item_, "basic");
// left toolbar button
- left_btn_ = elm_button_add(GetNaviframe());
+ left_btn_ = elm_button_add(parent);
elm_object_text_set(left_btn_, "CANCEL");
elm_object_style_set(left_btn_, "naviframe/title_left");
evas_object_smart_callback_add(left_btn_, "clicked", OnCancelButtonClickedCb, this);
evas_object_show(left_btn_);
// right toolbar button
- right_btn_ = elm_button_add(GetNaviframe());
+ right_btn_ = elm_button_add(parent);
elm_object_text_set(right_btn_, "DONE");
elm_object_style_set(right_btn_, "naviframe/title_right");
evas_object_smart_callback_add(right_btn_, "clicked", OnConfirmButtonClickedCb, this);
evas_object_show(right_btn_);
// main scrollable content
- content_ = elm_genlist_add(GetNaviframe());
+ content_ = elm_genlist_add(parent);
evas_object_size_hint_expand_set(content_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(content_, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_genlist_mode_set(content_, ELM_LIST_COMPRESS);
elm_object_item_content_set(top, page->GetEvasObject());
}
-
-MainView &MainView::GetInstance()
-{
- static MainView instance;
- return instance;
-}
-
MainView::MainView()
{
DBG("CreateBaseGui()");
ConformantAdd();
NaviframeAdd();
+ CreateContent();
evas_object_show(window_);
}
void MainView::CreatePages()
{
- alarm_ = new AlarmView();
- world_clock_ = new WorldClockView();
- stop_watch_ = new StopWatchView();
- timer_ = new TimerView();
+ alarm_ = new AlarmView(*this);
+ world_clock_ = new WorldClockView(*this);
+ stop_watch_ = new StopWatchView(*this);
+ timer_ = new TimerView(*this);
}
PopPage();
}
-PageView::PageView()
+PageView::PageView(ui::IView &main)
+ : naviframe_(main.GetEvasObject()), navi_item_(nullptr)
{
- navi_item_ = NULL;
}
void PageView::ItemDeletedCallback(void *data, Evas_Object *o, void *event)
if (navi_item_) return;
navi_item_ = elm_naviframe_item_push(
- MainView::GetInstance().GetEvasObject(),
+ GetNaviframe(),
NULL, NULL, NULL, NULL, NULL);
elm_object_item_data_set(navi_item_, this);
elm_object_item_del_cb_set(navi_item_, PageView::ItemDeletedCallback);
- CreateContent();
+ CreateContent(GetNaviframe());
}
void PageView::PopPage()
Evas_Object *PageView::GetNaviframe()
{
- return MainView::GetInstance().GetEvasObject();
+ return naviframe_;
}
void PageView::RegisterPoppedCallback(std::function<void(void)> f)
.func.text_get = GetListText,
};
-StopWatchView::StopWatchView()
+StopWatchView::StopWatchView(ui::IView &main)
{
- layout_ = elm_layout_add(MainView::GetInstance().GetEvasObject());
+ layout_ = elm_layout_add(main.GetEvasObject());
if (!elm_layout_file_set(layout_, GetEdjeFilePath(), GROUP)) {
ERR("elm_layout_file_set failed");
.max_byte_count = 0
};
-TimerView::TimerView() : set_time_()
+TimerView::TimerView(ui::IView &main) : set_time_()
{
- layout_ = elm_layout_add(MainView::GetInstance().GetEvasObject());
+ layout_ = elm_layout_add(main.GetEvasObject());
if (!elm_layout_file_set(layout_, GetEdjeFilePath(), GROUP)) {
ERR("elm_layout_file_set failed");
using namespace model;
-WeekFlagsView::WeekFlagsView(WeekFlags &flags)
- : flags_(flags)
+WeekFlagsView::WeekFlagsView(ui::IView &main, WeekFlags &flags)
+ : PageView(main), flags_(flags)
{
}
check_boxes_.push_back(desc);
}
-void WeekFlagsView::CreateContent()
+void WeekFlagsView::CreateContent(Evas_Object *parent)
{
- list_ = elm_list_add(GetNaviframe());
+ list_ = elm_list_add(parent);
evas_object_size_hint_weight_set(list_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(list_, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(list_);
};
-void WorldClockView::CreateCustomLocationsList()
+void WorldClockView::CreateCustomLocationsList(Evas_Object *parent)
{
- custom_locations_list_ = elm_genlist_add(MainView::GetInstance().GetEvasObject());
+ custom_locations_list_ = elm_genlist_add(parent);
evas_object_size_hint_expand_set(custom_locations_list_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(custom_locations_list_, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_genlist_homogeneous_set(custom_locations_list_, EINA_TRUE);
}
}
-WorldClockView::WorldClockView()
+WorldClockView::WorldClockView(ui::IView &main)
{
- world_clock_main_ = elm_layout_add(MainView::GetInstance().GetEvasObject());
+ world_clock_main_ = elm_layout_add(main.GetEvasObject());
evas_object_size_hint_align_set(world_clock_main_, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(world_clock_main_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_layout_theme_set(world_clock_main_, "layout", "application", "default");
edje_object_message_handler_set(elm_layout_edje_get(world_clock_), message_cb, NULL);
CreateTimezoneDetails();
- CreateCustomLocationsList();
+ CreateCustomLocationsList(main.GetEvasObject());
Evas_Object *fb = CreateFloatingButton();
elm_object_part_content_set(world_clock_main_, "elm.swallow.floatingbutton", fb);