TizenRefApp-8431 [Gallery] Change ProcessingPresenter to use modal view 50/127250/3
authorIgor Nazarov <i.nazarov@samsung.com>
Wed, 26 Apr 2017 17:00:59 +0000 (20:00 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Thu, 27 Apr 2017 13:59:04 +0000 (16:59 +0300)
- ProcessingPresenter Chnaged to use modal view;
- ProcessingPresenter derived from Presenter.

Change-Id: I6cdf203671f963173b0df141dbe77524a97b8171

inc/presenters/ProcessingPresenter.h
src/presenters/ProcessingPresenter.cpp

index ed6c41005fa8573cb96fd5e8ea58ea4d1912421e..270c7ec1b8c98a6dfede4cae02658027de8ab307 100644 (file)
 #include "ucl/gui/Layout.h"
 #include "ucl/gui/StyledWidget.h"
 
-#include "types.h"
+#include "Presenter.h"
 
 namespace gallery {
 
-       class ProcessingPresenter final : public ucl::RefCountAware {
+       class ProcessingPresenter final : public Presenter {
        public:
                enum class IconType {
                        NONE,
@@ -49,9 +49,9 @@ namespace gallery {
                using DismissHandler = ucl::WeakDelegate<void()>;
 
        public:
-               ucl::Widget &getWidget();
+               void complete();
 
-               void complete(const DismissHandler &dismissHandler);
+               void setDismissHandler(const DismissHandler &handler);
 
        private:
                friend class ucl::RefCountObj<ProcessingPresenter>;
@@ -65,6 +65,7 @@ namespace gallery {
 
                ucl::Result createWidget(ucl::ElmWidget &parent,
                                const ucl::TString &processingText);
+               ucl::Result moveWidget();
                ucl::Result createProgress();
                ucl::Result createPopup(const ucl::TString &completeText);
                ucl::Result createIcon();
@@ -75,7 +76,8 @@ namespace gallery {
                void showProgress();
 
                void tryShowPopup();
-               void dismissPopup(bool force = false);
+               void dismissPopup();
+               void deletePopup();
 
                void animateIcon();
 
@@ -95,13 +97,14 @@ namespace gallery {
        private:
                const IconType m_iconType;
                ucl::LayoutSRef m_widget;
-               ucl::StyledWidgetWRef m_popup;
+               ucl::StyledWidgetSRef m_popup;
                ucl::LayoutWRef m_icon;
                DismissHandler m_dismissHandler;
                Ecore_Timer *m_timer;
                State m_state;
                bool m_mayComplete;
                bool m_isComplete;
+               bool m_isDismissed;
        };
 }
 
index 42887ed697a0d26c4d95b3a6a188c0b7afbec28c..a6631a811a5c066465454eaa552dde04a5a2eee0 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "presenters/ProcessingPresenter.h"
 
+#include "ucl/gui/Window.h"
+
 #include "common.h"
 
 namespace gallery { namespace { namespace impl {
@@ -23,7 +25,7 @@ namespace gallery { namespace { namespace impl {
        using namespace ucl;
 
        constexpr auto IDLE_WAIT_TIME_SEC = 0.2;
-       constexpr auto PROCESSING_MIN_TIME_SEC = 1.0;
+       constexpr auto PROCESSING_MIN_TIME_SEC = 0.5;
 
        constexpr auto POPUP_SHOW_TIME_SEC = 0.3;
        constexpr auto POPUP_DURATION_SEC = 2.0;
@@ -102,19 +104,20 @@ namespace gallery {
 
        ProcessingPresenter::ProcessingPresenter(RefCountObjBase &rc,
                        const IconType iconType) :
-               RefCountAware(&rc),
+               Presenter(rc),
                m_iconType(iconType),
                m_timer(nullptr),
                m_state(State::WAITING),
                m_mayComplete(true),
-               m_isComplete(false)
+               m_isComplete(false),
+               m_isDismissed(false)
        {
        }
 
        ProcessingPresenter::~ProcessingPresenter()
        {
                stopTimer();
-               dismissPopup(true);
+               deletePopup();
        }
 
        Result ProcessingPresenter::prepare(ElmWidget &parent,
@@ -122,8 +125,12 @@ namespace gallery {
                        const TString &completeText,
                        const bool forceProgress)
        {
+               FAIL_RETURN(Presenter::prepare(parent),
+                               "Presenter::prepare() failed!");
+
                FAIL_RETURN(createWidget(parent, processingText),
                                "createWidget() failed!");
+               FAIL_RETURN(moveWidget(), "moveWidget() failed!");
 
                FAIL_RETURN(createProgress(), "createProgress() failed!");
 
@@ -139,6 +146,9 @@ namespace gallery {
                        LOG_RETURN(RES_FAIL, "resetTimer() failed!");
                }
 
+               addDeactivatorException(this);
+               broadcastDeactivateBy(this);
+
                return RES_OK;
        }
 
@@ -158,6 +168,22 @@ namespace gallery {
                return RES_OK;
        }
 
+       Result ProcessingPresenter::moveWidget()
+       {
+               const auto win = m_widget->getWindow();
+               if (!win) {
+                       LOG_RETURN(RES_FAIL, "win is NULL!");
+               }
+
+               int w = 0;
+               int h = 0;
+               win->getScreenSize(&w, &h);
+
+               m_widget->setGeometry(0, 0, w, h);
+
+               return RES_OK;
+       }
+
        Result ProcessingPresenter::createProgress()
        {
                Evas_Object *const progressEo = elm_progressbar_add(*m_widget);
@@ -176,12 +202,12 @@ namespace gallery {
 
        Result ProcessingPresenter::createPopup(const TString &completeText)
        {
-               Evas_Object *const popupEo = elm_popup_add(*m_widget);
+               Evas_Object *const popupEo = elm_popup_add(m_widget->getTopWidget());
                if (!popupEo) {
                        LOG_RETURN(RES_FAIL, "elm_popup_add() failed!");
                }
 
-               m_popup = makeShared<StyledWidget>(popupEo);
+               m_popup = makeShared<StyledWidget>(popupEo, true);
                m_popup->setStyle(impl::POPUP_STYLE);
                m_popup->setText(completeText, PART_TEXT);
 
@@ -251,17 +277,25 @@ namespace gallery {
                }
        }
 
-       void ProcessingPresenter::dismissPopup(const bool force)
+       void ProcessingPresenter::dismissPopup()
+       {
+               if (m_popup && !m_isDismissed) {
+                       m_isDismissed = true;
+                       deactivateBy(m_popup.get());
+                       elm_popup_dismiss(*m_popup);
+               }
+       }
+
+       void ProcessingPresenter::deletePopup()
        {
                if (m_popup) {
                        eext_object_event_callback_del(*m_popup, EEXT_CALLBACK_BACK,
                                        CALLBACK_A(ProcessingPresenter::onPopupHWBackKey));
-                       if (force) {
-                               m_popup->markForDeletion();
-                       } else {
-                               elm_popup_dismiss(*m_popup);
-                       }
+
                        m_popup.reset();
+
+                       broadcastActivateBy(this);
+                       m_rc->unref();
                }
        }
 
@@ -305,40 +339,37 @@ namespace gallery {
 
        void ProcessingPresenter::onPopupDismissed(Widget &widget, void *eventInfo)
        {
-               widget.markForDeletion();
-
+               const auto keepAliver = asShared(*this);
                if (m_dismissHandler) {
                        m_dismissHandler();
                }
+               deletePopup();
        }
 
        void ProcessingPresenter::onPopupHWBackKey(
                        Evas_Object *obj, void *eventInfo)
        {
-               if (m_popup) {
+               if (isActive()) {
                        m_widget->emit(impl::SIGNAL_HIDE);
                        stopTimer();
                        dismissPopup();
                }
        }
 
-       Widget &ProcessingPresenter::getWidget()
-       {
-               return *m_widget;
-       }
-
-       void ProcessingPresenter::complete(const DismissHandler &dismissHandler)
+       void ProcessingPresenter::complete()
        {
-               if (!dismissHandler) {
-                       LOG_RETURN_VOID(RES_INVALID_ARGUMENTS, "dismissHandler is NULL");
-               }
                if (m_isComplete) {
                        LOG_RETURN_VOID(RES_ILLEGAL_STATE, "Already in complete state!");
                }
-
-               m_dismissHandler = dismissHandler;
                m_isComplete = true;
 
+               m_rc->ref();
+
                tryShowPopup();
        }
+
+       void ProcessingPresenter::setDismissHandler(const DismissHandler &handler)
+       {
+               m_dismissHandler = handler;
+       }
 }