From 763d0a44ed6f68868a3a6e3c01ceebfe0e689c8b Mon Sep 17 00:00:00 2001 From: Igor Nazarov Date: Tue, 10 Oct 2017 19:48:55 +0300 Subject: [PATCH] TizenRefApp-9559 [Gallery] Fix issue with invalid thumbnails when adding new images Change-Id: I1d218ebac51946abc4b98d6d439dba10dac83db3 --- gallery/model/MediaItem.cpp | 24 ++++++++++++++++------ gallery/model/MediaItem.h | 6 ++++-- gallery/presenters/pages/PreviewPage.cpp | 3 ++- gallery/presenters/pages/ThumbnailPage.cpp | 3 ++- gallery/view/ImageGrid.cpp | 4 ++++ 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/gallery/model/MediaItem.cpp b/gallery/model/MediaItem.cpp index aec6b5d..fd21ffc 100644 --- a/gallery/model/MediaItem.cpp +++ b/gallery/model/MediaItem.cpp @@ -233,7 +233,9 @@ namespace gallery { MediaItem::~MediaItem() { - cancelThumbnailPathGet(); + if (m_thumbCbProxy) { + cancelThumbnailPathGet(); + } } MediaItemSRef MediaItem::newInstance(const media_info_h media) @@ -459,11 +461,12 @@ namespace gallery { } if (m_thumbCbProxy) { - m_thumbCbProxy->callback = cb; + m_thumbCbProxy->callbacks += cb; return RES_FALSE; } - auto cbProxy = util::makeUnique(new ThumbCbProxy{this, cb}); + auto cbProxy = util::makeUnique(new ThumbCbProxy{this}); + cbProxy->callbacks += cb; { MutexLock lock(getMediaMutex()); @@ -478,12 +481,21 @@ namespace gallery { return RES_FALSE; } - void MediaItem::cancelThumbnailPathGet() const + void MediaItem::cancelThumbnailPathGet(const ThumbnailPathGetCb &cb) const { if (!m_thumbCbProxy) { return; } + m_thumbCbProxy->callbacks -= cb; + + if (isEmpty(m_thumbCbProxy->callbacks)) { + cancelThumbnailPathGet(); + } + } + + void MediaItem::cancelThumbnailPathGet() const + { MutexLock lock(getMediaMutex()); const int ret = media_info_cancel_thumbnail(m_media); @@ -528,10 +540,10 @@ namespace gallery { item->m_media = nullptr; } - const auto proxy = std::move(*item->m_thumbCbProxy); + auto proxy = std::move(*item->m_thumbCbProxy); item->m_thumbCbProxy.reset(); - proxy.callback(result, proxy.item->m_thumbPath); + proxy.callbacks.dispatch(result, proxy.item->m_thumbPath); } } diff --git a/gallery/model/MediaItem.h b/gallery/model/MediaItem.h index 439de36..0aa8a01 100644 --- a/gallery/model/MediaItem.h +++ b/gallery/model/MediaItem.h @@ -22,6 +22,7 @@ #include #include "ucl/misc/AutoHandle.h" +#include "ucl/misc/Event.h" #include "IJob.h" @@ -81,7 +82,7 @@ namespace gallery { const std::string &getFilePath() const; ucl::Result getThumbnailPath(const ThumbnailPathGetCb &cb) const; - void cancelThumbnailPathGet() const; + void cancelThumbnailPathGet(const ThumbnailPathGetCb &cb) const; ucl::Result removeFile(); ucl::Result saveToDevice(); @@ -97,13 +98,14 @@ namespace gallery { private: ucl::Result initThumbPath(media_info_h media) const; + void cancelThumbnailPathGet() const; private: // XXX This proxy is needed to deal with cases when // media_thumbnail_completed_cb can't be cancelled struct ThumbCbProxy final { const MediaItem *item; - ThumbnailPathGetCb callback; + ucl::Event callbacks; void completeCb(media_content_error_e error, const char *path); }; diff --git a/gallery/presenters/pages/PreviewPage.cpp b/gallery/presenters/pages/PreviewPage.cpp index f38a7c8..19c00da 100644 --- a/gallery/presenters/pages/PreviewPage.cpp +++ b/gallery/presenters/pages/PreviewPage.cpp @@ -150,7 +150,8 @@ namespace gallery { void unrealize() { - m_media->cancelThumbnailPathGet(); + m_media->cancelThumbnailPathGet( + WEAK_DELEGATE(Item::onThumbnail, asWeak(*this))); } MediaItemSRef getMedia() diff --git a/gallery/presenters/pages/ThumbnailPage.cpp b/gallery/presenters/pages/ThumbnailPage.cpp index 38845cc..d8b1afb 100644 --- a/gallery/presenters/pages/ThumbnailPage.cpp +++ b/gallery/presenters/pages/ThumbnailPage.cpp @@ -107,7 +107,8 @@ namespace gallery { virtual ~RealizedItem() { - m_parent.m_mediaItems[m_index]->cancelThumbnailPathGet(); + m_parent.m_mediaItems[m_index]->cancelThumbnailPathGet( + WEAK_DELEGATE(RealizedItem::onThumbnail, asWeak(this))); } int getIndex() const diff --git a/gallery/view/ImageGrid.cpp b/gallery/view/ImageGrid.cpp index 9c14976..a456e0a 100644 --- a/gallery/view/ImageGrid.cpp +++ b/gallery/view/ImageGrid.cpp @@ -334,6 +334,10 @@ namespace gallery { listener->onItemRealized(itemIndex); } + if (!m_wasUpdated) { + update({"", "", 0, 0, 0}); + } + makeWhite(m_btn); } else { makeTransparent(m_btn); -- 2.34.1