summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Nazarov <i.nazarov@samsung.com>2017-07-21 20:08:05 +0300
committerIgor Nazarov <i.nazarov@samsung.com>2017-07-24 11:59:10 +0300
commitec0e8d53a3d267f067e0f89748663ba7c397e10f (patch)
treea189952541c27f03b42c004e2deb7974c9c0be68
parent79eccff0c950c42267a126318ae59885090ab508 (diff)
downloadgallery-ec0e8d53a3d267f067e0f89748663ba7c397e10f.tar.gz
gallery-ec0e8d53a3d267f067e0f89748663ba7c397e10f.tar.bz2
gallery-ec0e8d53a3d267f067e0f89748663ba7c397e10f.zip
TizenRefApp-8907 [Gallery] Add IDisposable support to Page class
Change-Id: Icfb77b16eca8796875860e8b4e1399f39bb3c255
-rw-r--r--inc/gallery/presenters/Page.h9
-rw-r--r--src/common.h1
-rw-r--r--src/presenters/Instance.cpp8
-rw-r--r--src/presenters/Page.cpp21
-rw-r--r--src/presenters/PreviewPage.cpp8
-rw-r--r--src/presenters/ThumbnailPage.cpp4
-rw-r--r--src/presenters/VideoPlayerPage.cpp4
-rw-r--r--ucl/inc/ucl/util/helpers.h11
-rw-r--r--ucl/inc/ucl/util/memory/helpers.h25
9 files changed, 65 insertions, 26 deletions
diff --git a/inc/gallery/presenters/Page.h b/inc/gallery/presenters/Page.h
index b98569c..d4de6f0 100644
--- a/inc/gallery/presenters/Page.h
+++ b/inc/gallery/presenters/Page.h
@@ -25,7 +25,8 @@ namespace gallery {
UCL_DECLARE_REF_ALIASES(Page);
- class Page : public ucl::GuiPresenter {
+ class Page : public ucl::GuiPresenter,
+ public ucl::IDisposable {
public:
using ExitRequestHandler = ucl::WeakDelegate<void(Page &page)>;
@@ -36,7 +37,6 @@ namespace gallery {
bool isAtBottom() const;
void exit();
- void exitNoTransition();
void popTo();
void deleteTo();
@@ -48,6 +48,11 @@ namespace gallery {
template <class ...ARGS>
ucl::NaviItem insertBefore(ARGS &&...args);
+ // ucl::IDisposable //
+
+ virtual void dispose() override;
+ virtual bool isDisposed() const final override;
+
protected:
Page(ucl::IRefCountObj &rc, const ucl::NaviframeSRef &navi,
const ExitRequestHandler &onExitRequest);
diff --git a/src/common.h b/src/common.h
index eff0cb0..659c330 100644
--- a/src/common.h
+++ b/src/common.h
@@ -58,6 +58,7 @@ namespace gallery {
namespace util {
using ucl::util::makeUnique;
+ using ucl::util::dispose;
}
}
diff --git a/src/presenters/Instance.cpp b/src/presenters/Instance.cpp
index 4c0fa53..392ce50 100644
--- a/src/presenters/Instance.cpp
+++ b/src/presenters/Instance.cpp
@@ -58,9 +58,7 @@ namespace gallery {
Instance::~Instance()
{
stopMediaContentScan();
- if (const auto page = m_page.lock()) {
- page->exitNoTransition();
- }
+ util::dispose(m_page);
}
Result Instance::onCreate(IInstanceContext *const context)
@@ -324,12 +322,12 @@ namespace gallery {
{
if (isEmpty(m_gallery->getAlbum())) {
if (auto page = dynamicRefCast<ThumbnailPage>(m_page).lock()) {
- page->exitNoTransition();
+ util::dispose(page);
createNoContentPage();
}
} else {
if (auto page = dynamicRefCast<NoContentPage>(m_page).lock()) {
- page->exitNoTransition();
+ util::dispose(page);
createThumbnailPage();
}
}
diff --git a/src/presenters/Page.cpp b/src/presenters/Page.cpp
index de4b8eb..3ba8919 100644
--- a/src/presenters/Page.cpp
+++ b/src/presenters/Page.cpp
@@ -104,20 +104,27 @@ namespace gallery {
m_navi->pop();
m_item = nullptr;
} else {
- exitNoTransition();
+ dispose();
}
}
- void Page::exitNoTransition()
+ void Page::dispose()
{
- if (isAtTop()) {
- m_item.del();
- dispatchTopPageChanged();
- } else if (m_item) {
- m_item.del();
+ if (m_item) {
+ if (isAtTop()) {
+ m_item.del();
+ dispatchTopPageChanged();
+ } else {
+ m_item.del();
+ }
}
}
+ bool Page::isDisposed() const
+ {
+ return m_item;
+ }
+
void Page::popTo()
{
if (m_item && !isAtTop()) {
diff --git a/src/presenters/PreviewPage.cpp b/src/presenters/PreviewPage.cpp
index 9071dac..cfb0412 100644
--- a/src/presenters/PreviewPage.cpp
+++ b/src/presenters/PreviewPage.cpp
@@ -224,9 +224,7 @@ namespace gallery {
PreviewPage::onAlbumChanged, asWeak(*this)));
}
closeTempViews();
- if (const auto page = m_page.lock()) {
- page->exitNoTransition();
- }
+ util::dispose(m_page);
if (m_imageGrid) {
m_imageGrid->setListener(nullptr);
}
@@ -635,9 +633,7 @@ namespace gallery {
void PreviewPage::closeTempViews()
{
- if (const auto alert = m_alert.lock()) {
- alert->dispose();
- }
+ util::dispose(m_alert);
if (m_more) {
m_more->setOpened(false);
}
diff --git a/src/presenters/ThumbnailPage.cpp b/src/presenters/ThumbnailPage.cpp
index 398d7d6..abd1ce2 100644
--- a/src/presenters/ThumbnailPage.cpp
+++ b/src/presenters/ThumbnailPage.cpp
@@ -153,9 +153,7 @@ namespace gallery {
if (m_more) {
m_more->setOpened(false);
}
- if (const auto page = m_page.lock()) {
- page->exitNoTransition();
- }
+ util::dispose(m_page);
if (m_imageGrid) {
m_imageGrid->setListener(nullptr);
}
diff --git a/src/presenters/VideoPlayerPage.cpp b/src/presenters/VideoPlayerPage.cpp
index 19858a0..ebeb3f7 100644
--- a/src/presenters/VideoPlayerPage.cpp
+++ b/src/presenters/VideoPlayerPage.cpp
@@ -158,9 +158,7 @@ namespace gallery {
VideoPlayerPage::~VideoPlayerPage()
{
- if (const auto alert = m_alert.lock()) {
- alert->dispose();
- }
+ util::dispose(m_alert);
if (m_soundMgr) {
m_soundMgr->delMediaDeviceStateChangeHandler(WEAK_DELEGATE(
diff --git a/ucl/inc/ucl/util/helpers.h b/ucl/inc/ucl/util/helpers.h
index 87485b0..117d3de 100644
--- a/ucl/inc/ucl/util/helpers.h
+++ b/ucl/inc/ucl/util/helpers.h
@@ -18,6 +18,7 @@
#define __UCL_UTIL_HELPERS_H__
#include "types/baseTypes.h"
+#include "types/classTypes.h"
namespace ucl {
@@ -108,6 +109,16 @@ namespace ucl { namespace util {
template <class T>
std::unique_ptr<T> makeUnique(T *p);
+
+ template <class T, class = typename std::enable_if<
+ std::is_convertible<T *, IDisposable *>::value>::type>
+ inline void dispose(T *&p) noexcept
+ {
+ if (p) {
+ p->dispose();
+ p = nullptr;
+ }
+ }
}}
#include "helpers.hpp"
diff --git a/ucl/inc/ucl/util/memory/helpers.h b/ucl/inc/ucl/util/memory/helpers.h
index bef907b..5ce25a3 100644
--- a/ucl/inc/ucl/util/memory/helpers.h
+++ b/ucl/inc/ucl/util/memory/helpers.h
@@ -19,6 +19,31 @@
namespace ucl {
+ // Misc //
+
+ namespace util {
+
+ template <class T, class = typename std::enable_if<
+ std::is_convertible<T *, IDisposable *>::value>::type>
+ inline void dispose(SharedRef<T> &r) noexcept
+ {
+ if (r) {
+ r->dispose();
+ r.reset();
+ }
+ }
+
+ template <class T, class = typename std::enable_if<
+ std::is_convertible<T *, IDisposable *>::value>::type>
+ inline void dispose(WeakRef<T> &r) noexcept
+ {
+ if (const auto shared = r.lock()) {
+ shared->dispose();
+ r.reset();
+ }
+ }
+ }
+
// Generic casting functions //
template <class T, class U>