[MainController] Create not visible pages in idle state. 55/128355/3
authorKamil Lipiszko <k.lipiszko@samsung.com>
Tue, 9 May 2017 11:06:45 +0000 (13:06 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 11 May 2017 08:34:54 +0000 (08:34 +0000)
Create pages that are not visible at launch in idle state
or on user's toolbar item click.

Change-Id: I21f4fbcbdb76c7f82bf2a138b790b65b45b1377d

clock/inc/Controller/MainController.h
clock/inc/View/MainView.h
clock/src/Controller/MainController.cpp
clock/src/View/MainView.cpp

index f60eac1e7f6be0c0ea87543b0cc8752b5bffe54a..60a82f3d58da2b9d7a7d16c94f4b7e4cf13a94ed 100644 (file)
@@ -18,6 +18,7 @@
 #define _CLOCK_MAIN_CONTROLLER_H_
 
 #include <vector>
+#include <Elementary.h>
 
 #include "Utils/EventBus.h"
 #include "View/EditAlarmView.h"
@@ -167,6 +168,9 @@ namespace controller {
                         * @brief intiialized flag
                         */
                        bool initialized_;
+
+                       Ecore_Idler *idler_ = nullptr;
+                       static Eina_Bool IdlerCb(void *data);
        };
 }
 
index 1ba1e52cee44c8f48e625403e7fd843ea0e9aa36..f62fa35d6b0d4b0fc8a753aadd84b662bc5b4a30 100644 (file)
@@ -110,11 +110,6 @@ namespace view {
                         */
                        void NaviframeAdd();
 
-                       /**
-                        * @brief Creates content for Alarm, World Clock, Stopwatch and Timer pages
-                        */
-                       void CreatePages();
-
                        /**
                         * @brief Creates toolbar buttons.
                         */
@@ -130,7 +125,7 @@ namespace view {
                         * @param[in] icon_path absolute icon path
                         * @param[in] translation msgid
                         */
-                       void CreateToolbarItem(const char *icon_path, const char *msgid, IView *content);
+                       void CreateToolbarItem(const char *icon_path, const char *msgid, IView **content);
 
                        Evas_Object *window_;
                        Evas_Object *conformant_;
@@ -139,10 +134,12 @@ namespace view {
                        /* Content */
                        Evas_Object *toolbar_;
 
-                       IView *alarm_;
-                       IView *world_clock_;
-                       IView *stop_watch_;
-                       IView *timer_;
+                       IView *alarm_ = nullptr;
+                       IView *world_clock_ = nullptr;
+                       IView *stop_watch_ = nullptr;
+                       IView *timer_ = nullptr;
+
+                       static void ToolbarItemCb(void *data, Evas_Object *obj, void *event_info);
        };
 }
 
index 40f80b8361f5eeb383b57d1a9e2328318ac4e944..68eda76b7b7e09d58fbf09e4424e00e27e5472db 100644 (file)
@@ -68,18 +68,37 @@ void MainController::Resume()
 
 }
 
+Eina_Bool MainController::IdlerCb(void *data)
+{
+       MainController *controller = static_cast<MainController *>(data);
+       MainView *mainView = &(controller->main_view_);
+
+       controller->world_clock_model_ = new model::WorldClock();
+       controller->world_clock_presenter_ = new WorldClockPresenter(
+                       (WorldClockView *)mainView->GetView(WORLD_CLOCK),
+                       controller->world_clock_model_);
+
+       controller->stop_watch_model_ = new model::StopWatch();
+       controller->stop_watch_presenter_ = new StopWatchPresenter(
+                       (StopWatchView *)mainView->GetView(STOP_WATCH),
+                       controller->stop_watch_model_);
+
+       controller->timer_model_ = new model::Timer();
+       controller->timer_presenter_ = new TimerPresenter(
+                       (TimerView *)mainView->GetView(TIMER),
+                       controller->timer_model_);
+
+       controller->idler_ = nullptr;
+       return ECORE_CALLBACK_CANCEL;
+}
+
 int MainController::Init()
 {
        if (initialized_) return 0;
 
-       world_clock_model_ = new model::WorldClock();
-       stop_watch_model_ = new model::StopWatch();
-       timer_model_ = new model::Timer();
-
        alarm_presenter_ = new AlarmPresenter((AlarmView *)main_view_.GetView(ALARM), provider_->GetAlarms());
-       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_);
+
+       idler_ = ecore_idler_add(IdlerCb, this);
 
        connections_.push_back(utils::EventBus::AddListener<AlarmCreateRequestEvent>(
                        std::bind(&MainController::CreateNewAlarmPage, this, _1)));
@@ -103,6 +122,11 @@ void MainController::Deinit()
 {
        if (!initialized_) return;
 
+       if (idler_) {
+               ecore_idler_del(idler_);
+               idler_ = nullptr;
+       }
+
        delete alarm_presenter_;
 
        delete world_clock_presenter_;
index b0a24dfc1bd21f10822951d601bad1c61d97d35a..881f652a3266595408cde76e0f5221a1b1a5b1d5 100644 (file)
@@ -59,9 +59,25 @@ static Eina_Bool naviframe_pop_cb(void *data, Elm_Object_Item *it)
        return EINA_FALSE;
 }
 
-void toolbar_it_cb (void *data, Evas_Object *obj, void *event_info)
+void MainView::ToolbarItemCb(void *data, Evas_Object *obj, void *event_info)
 {
-       ui::IView *page = static_cast<ui::IView*>(data);
+       ui::IView **page = static_cast<ui::IView **>(data);
+       MainView *mainView = static_cast<MainView *>(evas_object_data_get(obj, "parent"));
+       if (!*page) {
+               ViewType type;
+               if (page == &(mainView->alarm_))
+                       type = ViewType::ALARM;
+               else if (page == &(mainView->world_clock_))
+                       type = ViewType::WORLD_CLOCK;
+               else if (page == &(mainView->stop_watch_))
+                       type = ViewType::STOP_WATCH;
+               else if (page == &(mainView->timer_))
+                       type = ViewType::TIMER;
+               else
+                       return;
+
+               mainView->GetView(type);
+       }
 
        Evas_Object *layout = elm_object_parent_widget_get(obj);
        Evas_Object *navi = elm_object_parent_widget_get(layout);
@@ -71,8 +87,8 @@ void toolbar_it_cb (void *data, Evas_Object *obj, void *event_info)
 
        Evas_Object *prev = elm_object_item_content_unset(top);
        evas_object_hide(prev);
-       evas_object_show(page->GetEvasObject());
-       elm_object_item_content_set(top, page->GetEvasObject());
+       evas_object_show((*page)->GetEvasObject());
+       elm_object_item_content_set(top, (*page)->GetEvasObject());
 }
 
 MainView::MainView()
@@ -140,31 +156,25 @@ void MainView::NaviframeAdd()
        elm_object_content_set(conformant_, naviframe_);
 }
 
-void MainView::CreatePages()
-{
-       alarm_ = new AlarmView(*this);
-       world_clock_ = new WorldClockView(*this);
-       stop_watch_ = new StopWatchView(*this);
-       timer_ = new TimerView(*this);
-}
-
-void MainView::CreateToolbarItem(const char *icon_path, const char *msgid, IView *content)
+void MainView::CreateToolbarItem(const char *icon_path, const char *msgid, IView **content)
 {
        Elm_Object_Item *it = elm_toolbar_item_append(toolbar_, icon_path,
-                       Translate::Sprintf(msgid).c_str(), toolbar_it_cb, content);
+                       Translate::Sprintf(msgid).c_str(), ToolbarItemCb, content);
        elm_object_item_translatable_text_set(it, msgid);
+
+       evas_object_data_set(toolbar_, "parent", this);
 }
 
 void MainView::CreateToolbarButtons()
 {
        CreateToolbarItem(TizenAppUtils::GetResourcePath(TizenAppUtils::APP_DIR_RESOURCE,
-                       "images/tabs/clock_tabs_ic_alarm.png"), "IDS_CLOCK_BODY_ALARM", alarm_);
+                       "images/tabs/clock_tabs_ic_alarm.png"), "IDS_CLOCK_BODY_ALARM", &alarm_);
        CreateToolbarItem(TizenAppUtils::GetResourcePath(TizenAppUtils::APP_DIR_RESOURCE,
-                       "images/tabs/clock_tabs_ic_worldclock.png"), "IDS_CLOCK_BODY_WORLD_CLOCK", world_clock_);
+                       "images/tabs/clock_tabs_ic_worldclock.png"), "IDS_CLOCK_BODY_WORLD_CLOCK", &world_clock_);
        CreateToolbarItem(TizenAppUtils::GetResourcePath(TizenAppUtils::APP_DIR_RESOURCE,
-                       "images/tabs/clock_tabs_ic_stopwatch.png"), "IDS_CLOCK_BODY_STOPWATCH", stop_watch_);
+                       "images/tabs/clock_tabs_ic_stopwatch.png"), "IDS_CLOCK_BODY_STOPWATCH", &stop_watch_);
        CreateToolbarItem(TizenAppUtils::GetResourcePath(TizenAppUtils::APP_DIR_RESOURCE,
-                       "images/tabs/clock_tabs_ic_timer.png"), "IDS_CLOCK_BODY_TIMER", timer_);
+                       "images/tabs/clock_tabs_ic_timer.png"), "IDS_CLOCK_BODY_TIMER", &timer_);
 }
 
 void MainView::CreateToolbar()
@@ -182,12 +192,12 @@ void MainView::CreateToolbar()
 
 void MainView::CreateContent()
 {
-       CreatePages();
        CreateToolbar();
 
        Elm_Object_Item *item = elm_naviframe_item_push(naviframe_, NULL, NULL, NULL, NULL,
                        "tabbar/icon/notitle");
 
+       alarm_ = new AlarmView(*this);
        elm_naviframe_item_pop_cb_set(item, naviframe_pop_cb, window_);
 
        elm_object_item_part_content_set(item, "tabbar", toolbar_);
@@ -213,12 +223,20 @@ ui::IView *MainView::GetView(ViewType type)
 {
        switch (type){
                case ALARM:
+                       if (!alarm_)
+                               alarm_ = new AlarmView(*this);
                        return alarm_;
                case WORLD_CLOCK:
+                       if (!world_clock_)
+                               world_clock_ = new WorldClockView(*this);
                        return world_clock_;
                case STOP_WATCH:
+                       if (!stop_watch_)
+                               stop_watch_ = new StopWatchView(*this);
                        return stop_watch_;
                case TIMER:
+                       if (!timer_)
+                               timer_ = new TimerView(*this);
                        return timer_;
                default:
                        ERR("Wrong view type!");