#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,
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>;
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();
void showProgress();
void tryShowPopup();
- void dismissPopup(bool force = false);
+ void dismissPopup();
+ void deletePopup();
void animateIcon();
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;
};
}
#include "presenters/ProcessingPresenter.h"
+#include "ucl/gui/Window.h"
+
#include "common.h"
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;
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,
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!");
LOG_RETURN(RES_FAIL, "resetTimer() failed!");
}
+ addDeactivatorException(this);
+ broadcastDeactivateBy(this);
+
return RES_OK;
}
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);
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);
}
}
- 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();
}
}
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;
+ }
}