fix the unstable life-cycle behavior. 25/71025/3
authorHermet Park <hermet@hermet.pe.kr>
Mon, 23 May 2016 15:36:01 +0000 (00:36 +0900)
committerHermet Park <hermet@hermet.pe.kr>
Mon, 23 May 2016 15:40:24 +0000 (00:40 +0900)
test & implement ui_view life-cycle behaviors.

Change-Id: Id6847f6dc8f24dd721360c5c4c6c08ffe81398e6

src/examples/efl/page1.h
src/examples/efl/page2.h
src/include/efl/mobile/ui_mobile_viewmanager.h
src/include/efl/ui_base_viewmanager.h
src/include/interface/ui_iface_view.h
src/lib/efl/mobile/ui_app.cpp
src/lib/efl/ui_base_viewmgr.cpp
src/lib/interface/ui_iface_view.cpp
src/lib/interface/ui_iface_viewmgr.cpp

index 97c17015aa0a688ad006602394015c86189e8fea..252c5287b74df60daf360049023c257c2e573aaa 100644 (file)
@@ -41,6 +41,30 @@ protected:
                this->set_content(content, "Page1");
        }
 
+       //on_unload() will be called when this page1 is requested to be hidden.
+       void on_unload()
+       {
+               ui_standard_view::on_unload();
+       }
+
+       //on_destroy() will be called when this page1 is requested to be destroyed.
+       void on_destroy()
+       {
+               ui_standard_view::on_destroy();
+       }
+
+       //on_deactivate() will be called when this page1 is requested to be deactivated.
+       void on_deactivate()
+       {
+               ui_standard_view::on_deactivate();
+       }
+
+       //on_activate() will be called when this page1 is requested to be activated.
+       void on_activate()
+       {
+               ui_standard_view::on_activate();
+       }
+
 public:
        page1() : ui_standard_view("page1") {}
        ~page1() {}
index ae4b49670833df56c1687f5294826841f91c6bd1..37f27d983270e4aac448a5afeb450fec2a8ef085 100644 (file)
  */
 class page2: public ui_standard_view
 {
+private:
+       Evas_Object *content;
+       Elm_Button *left_title_btn;
+       Elm_Button *right_title_btn;
+
 protected:
        void on_load()
        {
@@ -48,9 +53,23 @@ protected:
 
                //Arguments: content, title, subtitle, title left button, title right button
                this->set_content(content, "Page2", NULL, left_title_btn, right_title_btn);
+
+               this->content = content;
+               this->left_title_btn = left_title_btn;
+               this->right_title_btn = right_title_btn;
+       }
+       void on_unload()
+       {
+               ui_standard_view::on_unload();
+
+               evas_object_del(this->content);
+               evas_object_del(this->left_title_btn);
+               evas_object_del(this->right_title_btn);
        }
 
 public:
-       page2() : ui_standard_view("page2") {}
+       page2() : ui_standard_view("page2")
+       {
+       }
        ~page2() {}
 };
index 3c8da4bbfe59c6f10ab282e8a95329d16cc718b5..62841eae245646bd0a2e99be91199dd78117ded7 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef _UI_MOBILE_VIEWMANAGER_H_
 #define _UI_MOBILE_VIEWMANAGER_H_
 
-#include <app.h>
 #include "../ui_base_viewmanager.h"
 #include "ui_view.h"
 #include "ui_standard_view.h"
index 6b5f37e3202b1993619680ca563ef398bc3fb09b..ff4f8402dbffec38f8cb8b6dc53487e91427aff3 100644 (file)
@@ -22,6 +22,7 @@
 #define Elm_Conformant Evas_Object
 #endif
 
+#include <app.h>
 #include "../interface/ui_iface_viewmanager.h"
 #include "ui_base_overlay.h"
 #include "ui_base_key_listener.h"
index b162382d3678d93f3ba9eabc79e95e4df6777943..7107eb24d8e13edebe9117f92771e9fb7b6f3bd4 100644 (file)
@@ -245,7 +245,7 @@ protected:
         *  @brief View destroy state.
         *
         *  @note When this view is on destroyed by popping or by somehow, destroy will be triggered. Most of the cases, you can free your personal resources for
-        *        the view because this view instance will be totally freed at the end of destroy. Be awre that you must not request any view functions on this
+        *        the view because this view instance will be totally freed at the end of destroy. Be aware that you must not request any view functions on this
         *        state.
         */
        virtual void on_destroy();
index 2bf7853ff31ddefcea7aa157833783201b770112..0737421cdd1558cedc8ae4e627c70695d467211c 100644 (file)
@@ -278,7 +278,7 @@ void ui_app::on_pause()
 
 void ui_app::on_resume()
 {
-       this->impl->get_viewmgr()->activate();
+//     this->impl->get_viewmgr()->activate();
 }
 
 void ui_app::on_control(app_control_h app_control)
@@ -289,6 +289,7 @@ void ui_app::on_control(app_control_h app_control)
 
 void ui_app::on_terminate()
 {
+       delete(this);
 }
 
 ui_app::ui_app(const char *pkg, const char *locale_dir)
index c8d52a0f0b233f393946783b2094a13faca0d382..daddf2aa5ac382318e322fc90f944b87624b6a02 100644 (file)
@@ -294,8 +294,6 @@ ui_base_viewmgr_impl::ui_base_viewmgr_impl(ui_base_viewmgr *viewmgr, const char
                        {
                                ui_base_viewmgr *viewmgr = static_cast<ui_base_viewmgr*>(data);
                                delete(viewmgr);
-                               //FIXME: Window is destroyed. Terminate Application!
-                               //ui_app_exit();
                        },
                        this->viewmgr);
 
@@ -343,11 +341,6 @@ bool ui_base_viewmgr_impl::term()
 bool ui_base_viewmgr_impl::activate()
 {
        this->activate_top_view();
-
-       //FIXME: Necessary??
-       ui_base_view *view = this->viewmgr->get_last_view();
-       view->on_activate();
-
        evas_object_show(this->win);
 
        return true;
@@ -358,14 +351,11 @@ bool ui_base_viewmgr_impl::deactivate()
        //FIXME: based on the profile, we should app to go behind or terminate.
        if (true)
        {
-               ui_base_view *view = this->viewmgr->get_last_view();
-               if (view) view->on_deactivate();
                evas_object_lower(this->win);
        }
        else
        {
-               //FIXME: exit app
-               //ui_app_exit();
+               delete(this->viewmgr);
        }
 
        return true;
@@ -376,7 +366,7 @@ bool ui_base_viewmgr_impl::pop_view()
        ui_base_view *pview = this->viewmgr->get_view(this->viewmgr->get_view_count() - 2);
        ui_base_view *view = this->viewmgr->get_last_view();
 
-       //In case, if view doesn't have transition effect
+       //In case, if view doesn't have any transition effects.
        if (!strcmp(view->get_transition_style(), "none"))
        {
                this->viewmgr->pop_view_finished(pview);
@@ -474,12 +464,12 @@ ui_base_viewmgr::~ui_base_viewmgr()
 {
        this->impl->term();
        delete(this->impl);
+       ui_app_exit();
 }
 
 bool ui_base_viewmgr::activate()
 {
        if (!ui_iface_viewmgr::activate()) return false;
-
        this->impl->activate();
 
        return true;
@@ -488,7 +478,6 @@ bool ui_base_viewmgr::activate()
 bool ui_base_viewmgr::deactivate()
 {
        if (!ui_iface_viewmgr::deactivate()) return false;
-
        this->impl->deactivate();
 
        return true;
index f62e27395da0deff7db11ad2f6e95504a257d013..37aeb9633f34ffb9a8b2a7989f8b44a319939306 100644 (file)
@@ -121,6 +121,7 @@ void ui_iface_view_impl::on_resume()
 
 void ui_iface_view_impl::on_destroy()
 {
+
 }
 
 ui_iface_view_impl::ui_iface_view_impl(ui_iface_view *view, const char *name)
index bbe825457a9ab7679d363ceffe4a209df1b2fcd8..566953828cd5b2a5b45f4c129f4167db588ad8a1 100644 (file)
@@ -38,6 +38,7 @@ private:
        static bool event_block;                   //Event block on view transition. This value should be configurable by system.
        list<ui_iface_view *> view_list;           //View list.
        bool activated;                            //Activated status of this viewmgr.
+       bool destroying;                           //True, if viewmgr is on destroying.
 
 public:
        bool connect_view(ui_iface_view *view);
@@ -182,7 +183,7 @@ bool ui_iface_viewmgr_impl::pop_view_finished(ui_iface_view *view)
 }
 
 ui_iface_viewmgr_impl::ui_iface_viewmgr_impl(ui_iface_viewmgr* viewmgr)
-               : activated(false)
+               : activated(false), destroying(false)
 {
        ui_iface_viewmgr_impl::inst = viewmgr;
 }
@@ -190,14 +191,23 @@ ui_iface_viewmgr_impl::ui_iface_viewmgr_impl(ui_iface_viewmgr* viewmgr)
 ui_iface_viewmgr_impl::~ui_iface_viewmgr_impl()
 {
        //Terminate views
-       for (VIEW_RITR it = this->view_list.rbegin(); it != this->view_list.rend(); it++)
+       this->destroying = EINA_TRUE;
+       for (VIEW_RITR ritr = this->view_list.rbegin(); ritr != this->view_list.rend(); ritr++)
        {
-               ui_iface_view *view = *it;
-               view->on_deactivate();
-               view->on_unload();
+               ui_iface_view *view = *ritr;
+               if ((view->get_state() != UI_VIEW_STATE_DEACTIVATE) &&
+                       (view->get_state() != UI_VIEW_STATE_UNLOAD))
+               {
+                       view->on_deactivate();
+               }
+               if (view->get_state() != UI_VIEW_STATE_UNLOAD)
+               {
+                       view->on_unload();
+               }
                view->on_destroy();
                delete (view);
        }
+       this->destroying = EINA_FALSE;
 
        //FIXME: Window is destroyed. Terminate Application!
        ui_app_exit();
@@ -231,11 +241,10 @@ ui_iface_view *ui_iface_viewmgr_impl::push_view(ui_iface_view *view)
 
        this->view_list.push_back(view);
 
-       if (!view->get_content())
-       {
-               view->on_load();
-       }
+       //If view manager is not activated yet, don't load view.
+       if (!this->is_activated()) return view;
 
+       view->on_load();
        view->on_deactivate();
 
        if (this->view_list.size() != 1)
@@ -329,6 +338,8 @@ bool ui_iface_viewmgr_impl::insert_view_before(ui_iface_view *view, ui_iface_vie
 
 bool ui_iface_viewmgr_impl::remove_view(ui_iface_view *view)
 {
+       if (this->destroying) return false;
+
        this->view_list.remove(view);
        this->disconnect_view(view);
 
@@ -372,6 +383,10 @@ bool ui_iface_viewmgr_impl::activate()
        if (this->activated) return false;
        if (this->get_view_count() == 0) return false;
        this->activated = true;
+       ui_iface_view *view = this->get_last_view();
+       view->on_load();
+       view->on_deactivate();
+       view->on_activate();
        return true;
 }
 
@@ -379,6 +394,18 @@ bool ui_iface_viewmgr_impl::deactivate()
 {
        if (!this->activated) return false;
        this->activated = false;
+       ui_iface_view *view = this->get_last_view();
+
+       if ((view->get_state() != UI_VIEW_STATE_DEACTIVATE) &&
+               (view->get_state() != UI_VIEW_STATE_UNLOAD))
+       {
+               view->on_deactivate();
+       }
+       if (view->get_state() != UI_VIEW_STATE_UNLOAD)
+       {
+               view->on_unload();
+       }
+
        return true;
 }