TizenRefApp-6591 Implement popup based on timer 85/79385/3
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Mon, 11 Jul 2016 07:05:20 +0000 (10:05 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 12 Jul 2016 13:24:40 +0000 (06:24 -0700)
Change-Id: I30666870698feb566cda7807d2277b06c1f61d73
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-apps-common/inc/Ui/ProcessPopup.h
lib-apps-common/src/Ui/ProcessPopup.cpp
lib-contacts/src/Contacts/List/ListView.cpp
lib-contacts/src/Contacts/List/ManageFavoritesPopup.cpp

index 8fa2b15..7c42eb6 100644 (file)
@@ -33,9 +33,13 @@ namespace Ui
 
                /**
                 * @brief Create popup.
-                * @param[in]   size    Popup size
+                * @param[in]   size            Popup size
+                * @param[in]   showDelayTime   Delay before showing popup
+                * @param[in]   showMinTime     Minimum time popup should be shown
                 */
-               explicit ProcessPopup(Size size = SizeMedium);
+               explicit ProcessPopup(Size size = SizeMedium,
+                               double showDelayTime = 0.2, double showMinTime = 1.0);
+               virtual ~ProcessPopup() override;
 
                /**
                 * @brief Allows method overload instead of shadowing
@@ -52,6 +56,11 @@ namespace Ui
                static ProcessPopup *create(Evas_Object *parent, const char *text, Size size = SizeMedium);
 
                /**
+                * @brief Destroy the popup once minimum show time has elapsed.
+                */
+               void destroy();
+
+               /**
                 * @brief Set Popup text.
                 * @param[in]   text    Popup text
                 */
@@ -61,8 +70,15 @@ namespace Ui
                virtual Evas_Object *onCreate(Evas_Object *parent) override;
 
        private:
+               Eina_Bool onShowDelayElapsed();
+               Eina_Bool onShowMinElapsed();
+
                Size m_Size;
                Evas_Object *m_Layout;
+
+               Ecore_Timer *m_ShowDelayTimer;
+               Ecore_Timer *m_ShowMinTimer;
+               bool m_IsDestroyPending;
        };
 }
 
index 26f7396..1f107ea 100644 (file)
 #include "Ui/Window.h"
 
 #include "App/Path.h"
+#include "Utils/Callback.h"
 #include "AppsCommonPopup.h"
 
-#include <efl_extension.h>
-
 using namespace Ui;
 
-ProcessPopup::ProcessPopup(Size size)
-       : m_Size(size), m_Layout(nullptr)
+ProcessPopup::ProcessPopup(Size size, double showDelayTime, double showMinTime)
+       : m_Size(size), m_Layout(nullptr),
+         m_ShowDelayTimer(nullptr), m_ShowMinTimer(nullptr),
+         m_IsDestroyPending(false)
+{
+       m_ShowDelayTimer = ecore_timer_add(showDelayTime,
+                       makeCallback(&ProcessPopup::onShowDelayElapsed), this);
+       ecore_timer_freeze(m_ShowDelayTimer);
+       m_ShowMinTimer = ecore_timer_add(showMinTime,
+                       makeCallback(&ProcessPopup::onShowMinElapsed), this);
+       ecore_timer_freeze(m_ShowMinTimer);
+
+       setBackCallback([this] {
+               return m_IsDestroyPending;
+       });
+}
+
+ProcessPopup::~ProcessPopup()
 {
-       setBackCallback([]{ return false; });
+       ecore_timer_del(m_ShowDelayTimer);
+       ecore_timer_del(m_ShowMinTimer);
 }
 
 ProcessPopup *ProcessPopup::create(Evas_Object *parent, const char *text, Size size)
@@ -39,6 +55,15 @@ ProcessPopup *ProcessPopup::create(Evas_Object *parent, const char *text, Size s
        return popup;
 }
 
+void ProcessPopup::destroy()
+{
+       if (m_ShowMinTimer && !m_ShowDelayTimer) {
+               m_IsDestroyPending = true;
+       } else {
+               delete this;
+       }
+}
+
 void ProcessPopup::setText(const char *text)
 {
        elm_object_translatable_part_text_set(m_Layout, "elm.text", text);
@@ -50,7 +75,7 @@ Evas_Object *ProcessPopup::onCreate(Evas_Object *parent)
                const char *layout;
                const char *progress;
        } styles[] = {
-               /* SizeSmall  */ { GROUP_PROCESS_SMALL,  "process_small"  },
+               /* SizeSmall  = */ { GROUP_PROCESS_SMALL,  "process_small"  },
                /* SizeMedium = */ { GROUP_PROCESS_MEDIUM, "process_medium" }
        };
 
@@ -67,5 +92,30 @@ Evas_Object *ProcessPopup::onCreate(Evas_Object *parent)
        elm_progressbar_pulse(progressbar, EINA_TRUE);
        elm_object_content_set(m_Layout, progressbar);
 
+       if (m_ShowDelayTimer) {
+               evas_object_hide(popup);
+               ecore_timer_thaw(m_ShowDelayTimer);
+       } else {
+               ecore_timer_thaw(m_ShowMinTimer);
+       }
+
        return popup;
 }
+
+Eina_Bool ProcessPopup::onShowDelayElapsed()
+{
+       evas_object_show(getEvasObject());
+       ecore_timer_thaw(m_ShowMinTimer);
+
+       m_ShowDelayTimer = nullptr;
+       return EINA_FALSE;
+}
+
+Eina_Bool ProcessPopup::onShowMinElapsed()
+{
+       m_ShowMinTimer = nullptr;
+       if (m_IsDestroyPending) {
+               delete this;
+       }
+       return EINA_FALSE;
+}
index d0c4f2b..9fa0a48 100644 (file)
@@ -61,7 +61,6 @@ using namespace Ux;
 using namespace std::placeholders;
 
 #define SYMBOL_MAGNIFIER "\U0001f50d"
-#define PROGRESS_RESULTS_LIMIT 40
 
 ListView::ListView(Model::PersonProvider *provider)
        : m_Box(nullptr), m_NoContent(nullptr), m_Genlist(nullptr),
@@ -207,12 +206,9 @@ void ListView::onDeleteSelected()
                        contacts_disconnect_on_thread();
                };
 
-               Ui::ProcessPopup *popup = nullptr;
-               if (results.size() > PROGRESS_RESULTS_LIMIT) {
-                       popup = Ui::ProcessPopup::create(getEvasObject(), "IDS_PB_TPOP_DELETING_ING_ABB");
-               }
+               auto popup = Ui::ProcessPopup::create(getEvasObject(), "IDS_PB_TPOP_DELETING_ING_ABB");
                new Thread(std::bind(task, std::move(results)), [this, popup] {
-                       delete popup;
+                       popup->destroy();
                        onSelectFinished();
                });
 
index 3801bd6..ebd94a4 100644 (file)
@@ -31,8 +31,6 @@ using namespace Common::Database;
 using namespace Contacts::List;
 using namespace Contacts::List::Model;
 
-#define PROGRESS_RESULTS_LIMIT 40
-
 ManageFavoritesPopup::ManageFavoritesPopup(Ui::Navigator *navigator)
        : m_Navigator(navigator)
 {
@@ -75,12 +73,9 @@ void ManageFavoritesPopup::onAddSelected()
        view->setSelectMode(Ux::SelectMulti);
        view->setSectionVisibility(ListView::SectionFavorites, false);
        view->setSelectCallback([view](Ux::SelectResults results) {
-               Ui::ProcessPopup *popup = nullptr;
-               if (results.size() > PROGRESS_RESULTS_LIMIT) {
-                       popup = Ui::ProcessPopup::create(view->getEvasObject(), "IDS_PB_TPOP_PROCESSING_ING");
-               }
+               auto popup = Ui::ProcessPopup::create(view->getEvasObject(), "IDS_PB_TPOP_PROCESSING_ING");
                new Utils::Thread(std::bind(addFavorites, std::move(results)), [view, popup] {
-                       delete popup;
+                       popup->destroy();
                        view->getPage()->close();
                });
                return false;
@@ -102,12 +97,9 @@ void ManageFavoritesPopup::onRemoveSelected()
        //todo Implement separate controller to handle callback, because object is destroyed after popup close.
        auto &onMfcUpdated = m_OnMfcUpdated;
        view->setSelectCallback([view, onMfcUpdated](Ux::SelectResults results) {
-               Ui::ProcessPopup *popup = nullptr;
-               if (results.size() > PROGRESS_RESULTS_LIMIT) {
-                       popup = Ui::ProcessPopup::create(view->getEvasObject(), "IDS_PB_TPOP_PROCESSING_ING");
-               }
+               auto popup = Ui::ProcessPopup::create(view->getEvasObject(), "IDS_PB_TPOP_PROCESSING_ING");
                new Utils::Thread(std::bind(removeFavorites, std::move(results), std::move(onMfcUpdated)), [view, popup] {
-                       delete popup;
+                       popup->destroy();
                        view->getPage()->close();
                });
                return false;