From: Igor Nazarov Date: Mon, 3 Apr 2017 09:47:07 +0000 (+0300) Subject: TizenRefApp-8314 [Gallery] Rename ViewerPage into PreviewPage X-Git-Tag: submit/tizen/20170531.142232~39 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3ef18e2d7cf5f789d7983cde2eced6bc4bf57dee;p=profile%2Fwearable%2Fapps%2Fnative%2Fgallery.git TizenRefApp-8314 [Gallery] Rename ViewerPage into PreviewPage - ViewerPage was renamed to PreviewPage. Change-Id: Ia2e61a072ba54f0ecab0742309c43d2db5399f07 --- diff --git a/inc/presentation/PreviewPage.h b/inc/presentation/PreviewPage.h new file mode 100644 index 0000000..d47f05d --- /dev/null +++ b/inc/presentation/PreviewPage.h @@ -0,0 +1,81 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __GALLERY_PRESENTATION_PREVIEW_PAGE_H__ +#define __GALLERY_PRESENTATION_PREVIEW_PAGE_H__ + +#include "Page.h" + +#include "IImageGridListener.h" + +#include "model/types.h" + +namespace gallery { + + class PreviewPage final : public Page, + private IImageGridListener { + public: + class Builder { + public: + Builder(); + ~Builder(); + Builder &setNaviframe(const ucl::NaviframeSRef &navi); + Builder &setAlbum(const IMediaAlbumSRef &album); + Builder &setStartItemIndex(int index); + PreviewPageSRef build(ExitRequestHandler onExitRequest) const; + private: + ucl::NaviframeSRef m_navi; + IMediaAlbumSRef m_album; + int m_startItemIndex; + }; + + public: + void reload(); + + private: + friend class ucl::RefCountObj; + PreviewPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi, + ExitRequestHandler onExitRequest, const IMediaAlbumSRef &album); + virtual ~PreviewPage(); + + ucl::Result prepare(); + void showItem(int itemIndex); + + bool onEachMedia(MediaItemUPtr &&media); + + // Page // + + virtual void onActivate() final override; + virtual void onDeactivate() final override; + + // IImageGridListener // + + virtual void onItemRealized(int itemIndex) final override; + virtual void onItemUnrealized(int itemIndex) final override; + virtual void onItemClicked(int itemIndex) final override; + + private: + class Item; + using ItemUPtr = std::unique_ptr; + + private: + const IMediaAlbumSRef m_album; + ImageGridSRef m_imageGrid; + std::vector m_items; + }; +} + +#endif // __GALLERY_PRESENTATION_PREVIEW_PAGE_H__ diff --git a/inc/presentation/ViewerPage.h b/inc/presentation/ViewerPage.h deleted file mode 100644 index 4f89dc8..0000000 --- a/inc/presentation/ViewerPage.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __GALLERY_PRESENTATION_VIEWER_PAGE_H__ -#define __GALLERY_PRESENTATION_VIEWER_PAGE_H__ - -#include "Page.h" - -#include "IImageGridListener.h" - -#include "model/types.h" - -namespace gallery { - - class ViewerPage final : public Page, - private IImageGridListener { - public: - class Builder { - public: - Builder(); - ~Builder(); - Builder &setNaviframe(const ucl::NaviframeSRef &navi); - Builder &setAlbum(const IMediaAlbumSRef &album); - Builder &setStartItemIndex(int index); - ViewerPageSRef build(ExitRequestHandler onExitRequest) const; - private: - ucl::NaviframeSRef m_navi; - IMediaAlbumSRef m_album; - int m_startItemIndex; - }; - - public: - void reload(); - - private: - friend class ucl::RefCountObj; - ViewerPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi, - ExitRequestHandler onExitRequest, const IMediaAlbumSRef &album); - virtual ~ViewerPage(); - - ucl::Result prepare(); - void showItem(int itemIndex); - - bool onEachMedia(MediaItemUPtr &&media); - - // Page // - - virtual void onActivate() final override; - virtual void onDeactivate() final override; - - // IImageGridListener // - - virtual void onItemRealized(int itemIndex) final override; - virtual void onItemUnrealized(int itemIndex) final override; - virtual void onItemClicked(int itemIndex) final override; - - private: - class Item; - using ItemUPtr = std::unique_ptr; - - private: - const IMediaAlbumSRef m_album; - ImageGridSRef m_imageGrid; - std::vector m_items; - }; -} - -#endif // __GALLERY_PRESENTATION_VIEWER_PAGE_H__ diff --git a/inc/presentation/types.h b/inc/presentation/types.h index f07d417..25837fb 100644 --- a/inc/presentation/types.h +++ b/inc/presentation/types.h @@ -30,7 +30,7 @@ namespace gallery { UCL_DECLARE_REF_ALIASES(Page); UCL_DECLARE_REF_ALIASES(ThumbnailPage); - UCL_DECLARE_REF_ALIASES(ViewerPage); + UCL_DECLARE_REF_ALIASES(PreviewPage); UCL_DECLARE_REF_ALIASES(NoContentPage); } diff --git a/src/presentation/PreviewPage.cpp b/src/presentation/PreviewPage.cpp new file mode 100644 index 0000000..3666cf3 --- /dev/null +++ b/src/presentation/PreviewPage.cpp @@ -0,0 +1,221 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "presentation/PreviewPage.h" + +#include "model/IMediaAlbum.h" +#include "model/MediaItem.h" + +#include "presentation/ImageGrid.h" + +#include "common.h" + +namespace gallery { + + using namespace ucl; + + // PreviewPage::Builder // + + PreviewPage::Builder::Builder() : + m_startItemIndex(0) + { + } + + PreviewPage::Builder::~Builder() + { + } + + PreviewPage::Builder &PreviewPage::Builder::setNaviframe( + const NaviframeSRef &navi) + { + m_navi = navi; + return *this; + } + + PreviewPage::Builder &PreviewPage::Builder::setAlbum( + const IMediaAlbumSRef &album) + { + m_album = album; + return *this; + } + + PreviewPage::Builder &PreviewPage::Builder::setStartItemIndex( + const int index) + { + m_startItemIndex = index; + return *this; + } + + PreviewPageSRef PreviewPage::Builder::build( + const ExitRequestHandler onExitRequest) const + { + if (!onExitRequest) { + LOG_RETURN_VALUE(RES_INVALID_ARGUMENTS, {}, + "onExitRequest is NULL"); + } + if (!m_navi) { + LOG_RETURN_VALUE(RES_INVALID_ARGUMENTS, {}, "m_navi is NULL"); + } + if (!m_album) { + LOG_RETURN_VALUE(RES_INVALID_ARGUMENTS, {}, "m_album is NULL"); + } + + auto result = makeShared( + m_navi, onExitRequest, m_album); + + FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); + + if (m_startItemIndex > 0) { + result->showItem(m_startItemIndex); + } + + return result; + } + + // PreviewPage::Item // + + class PreviewPage::Item : public NonCopyable { + public: + Item(MediaItemUPtr &&media, ImageGrid &imageGrid, const int itemIndex) : + m_media(std::move(media)), + m_imageGrid(imageGrid), + m_index(itemIndex) + { + } + + void realize() + { + FAIL_LOG(m_media->getThumbnailPath( + DELEGATE(Item::onThumbnail, this)), + "getThumbnailPath() failed!"); + } + + void unrealize() + { + m_media->cancelThumbnailPathGet(); + } + + private: + void onThumbnail(const Result result, const std::string &path) + { + FAIL_LOG(result, "Failed to get thumbnail!"); + + ImageGrid::ItemParams params = {}; + m_media->getResolution(params.aspectX, params.aspectY); + params.imagePath = m_media->getFilePath(); + params.bgImagePath = path; + + m_imageGrid.updateItem(m_index, params); + } + + private: + const MediaItemUPtr m_media; + ImageGrid &m_imageGrid; + const int m_index; + }; + + // PreviewPage // + + PreviewPage::PreviewPage(RefCountObjBase &rc, + const NaviframeSRef &navi, + const ExitRequestHandler onExitRequest, + const IMediaAlbumSRef &album) : + Page(rc, navi, onExitRequest), + m_album(album) + { + } + + PreviewPage::~PreviewPage() + { + m_imageGrid->setListener(nullptr); + } + + void PreviewPage::reload() + { + ImageGrid::Unrealizer u(*m_imageGrid); + + m_items.clear(); + + FAIL_LOG(m_album->forEachMedia( + DELEGATE(PreviewPage::onEachMedia, this)), + "m_album->forEachMedia() failed!"); + + m_imageGrid->setItemCount(m_items.size()); + } + + Result PreviewPage::prepare() + { + m_imageGrid = ImageGrid::Builder(). + setListener(this). + setType(ImageGrid::Type::LINEAR). + build(getNaviframe()); + if (!m_imageGrid) { + LOG_RETURN(RES_FAIL, "ImageGrid::build() failed!"); + } + + FAIL_RETURN(m_album->forEachMedia( + DELEGATE(PreviewPage::onEachMedia, this)), + "m_album->forEachMedia() failed!"); + + FAIL_RETURN(Page::prepare( + [this]() + { + return getNaviframe().push(*m_imageGrid); + }), + "Page::prepare() failed!"); + + m_imageGrid->setItemCount(m_items.size()); + + return RES_OK; + } + + void PreviewPage::showItem(const int itemIndex) + { + m_imageGrid->scrollToItem(itemIndex); + } + + bool PreviewPage::onEachMedia(MediaItemUPtr &&media) + { + m_items.emplace_back( + new Item(std::move(media), *m_imageGrid, m_items.size())); + return true; + } + + void PreviewPage::onActivate() + { + m_imageGrid->activateRotary(); + } + + void PreviewPage::onDeactivate() + { + m_imageGrid->deactivateRotary(); + } + + void PreviewPage::onItemRealized(const int itemIndex) + { + m_items[itemIndex]->realize(); + } + + void PreviewPage::onItemUnrealized(const int itemIndex) + { + m_items[itemIndex]->unrealize(); + } + + void PreviewPage::onItemClicked(const int itemIndex) + { + ILOG("TODO Not implemented. Item: %d;", itemIndex); + } +} diff --git a/src/presentation/ThumbnailPage.cpp b/src/presentation/ThumbnailPage.cpp index ee15ea9..bff4a29 100644 --- a/src/presentation/ThumbnailPage.cpp +++ b/src/presentation/ThumbnailPage.cpp @@ -20,7 +20,7 @@ #include "model/MediaItem.h" #include "presentation/ImageGrid.h" -#include "presentation/ViewerPage.h" +#include "presentation/PreviewPage.h" #include "common.h" @@ -144,7 +144,7 @@ namespace gallery { m_imageGrid->setItemCount(m_mediaItems.size()); - if (const auto vp = dynamic_cast(m_page.get())) { + if (const auto vp = dynamic_cast(m_page.get())) { vp->reload(); } } @@ -213,7 +213,7 @@ namespace gallery { void ThumbnailPage::onItemClicked(const int itemIndex) { - m_page = ViewerPage::Builder(). + m_page = PreviewPage::Builder(). setNaviframe(asShared(getNaviframe())). setAlbum(m_album). setStartItemIndex(itemIndex). diff --git a/src/presentation/ViewerPage.cpp b/src/presentation/ViewerPage.cpp deleted file mode 100644 index c1e8b4e..0000000 --- a/src/presentation/ViewerPage.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "presentation/ViewerPage.h" - -#include "model/IMediaAlbum.h" -#include "model/MediaItem.h" - -#include "presentation/ImageGrid.h" - -#include "common.h" - -namespace gallery { - - using namespace ucl; - - // ViewerPage::Builder // - - ViewerPage::Builder::Builder() : - m_startItemIndex(0) - { - } - - ViewerPage::Builder::~Builder() - { - } - - ViewerPage::Builder &ViewerPage::Builder::setNaviframe( - const NaviframeSRef &navi) - { - m_navi = navi; - return *this; - } - - ViewerPage::Builder &ViewerPage::Builder::setAlbum( - const IMediaAlbumSRef &album) - { - m_album = album; - return *this; - } - - ViewerPage::Builder &ViewerPage::Builder::setStartItemIndex( - const int index) - { - m_startItemIndex = index; - return *this; - } - - ViewerPageSRef ViewerPage::Builder::build( - const ExitRequestHandler onExitRequest) const - { - if (!onExitRequest) { - LOG_RETURN_VALUE(RES_INVALID_ARGUMENTS, {}, - "onExitRequest is NULL"); - } - if (!m_navi) { - LOG_RETURN_VALUE(RES_INVALID_ARGUMENTS, {}, "m_navi is NULL"); - } - if (!m_album) { - LOG_RETURN_VALUE(RES_INVALID_ARGUMENTS, {}, "m_album is NULL"); - } - - auto result = makeShared( - m_navi, onExitRequest, m_album); - - FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); - - if (m_startItemIndex > 0) { - result->showItem(m_startItemIndex); - } - - return result; - } - - // ViewerPage::Item // - - class ViewerPage::Item : public NonCopyable { - public: - Item(MediaItemUPtr &&media, ImageGrid &imageGrid, const int itemIndex) : - m_media(std::move(media)), - m_imageGrid(imageGrid), - m_index(itemIndex) - { - } - - void realize() - { - FAIL_LOG(m_media->getThumbnailPath( - DELEGATE(Item::onThumbnail, this)), - "getThumbnailPath() failed!"); - } - - void unrealize() - { - m_media->cancelThumbnailPathGet(); - } - - private: - void onThumbnail(const Result result, const std::string &path) - { - FAIL_LOG(result, "Failed to get thumbnail!"); - - ImageGrid::ItemParams params = {}; - m_media->getResolution(params.aspectX, params.aspectY); - params.imagePath = m_media->getFilePath(); - params.bgImagePath = path; - - m_imageGrid.updateItem(m_index, params); - } - - private: - const MediaItemUPtr m_media; - ImageGrid &m_imageGrid; - const int m_index; - }; - - // ViewerPage // - - ViewerPage::ViewerPage(RefCountObjBase &rc, - const NaviframeSRef &navi, - const ExitRequestHandler onExitRequest, - const IMediaAlbumSRef &album) : - Page(rc, navi, onExitRequest), - m_album(album) - { - } - - ViewerPage::~ViewerPage() - { - m_imageGrid->setListener(nullptr); - } - - void ViewerPage::reload() - { - ImageGrid::Unrealizer u(*m_imageGrid); - - m_items.clear(); - - FAIL_LOG(m_album->forEachMedia( - DELEGATE(ViewerPage::onEachMedia, this)), - "m_album->forEachMedia() failed!"); - - m_imageGrid->setItemCount(m_items.size()); - } - - Result ViewerPage::prepare() - { - m_imageGrid = ImageGrid::Builder(). - setListener(this). - setType(ImageGrid::Type::LINEAR). - build(getNaviframe()); - if (!m_imageGrid) { - LOG_RETURN(RES_FAIL, "ImageGrid::build() failed!"); - } - - FAIL_RETURN(m_album->forEachMedia( - DELEGATE(ViewerPage::onEachMedia, this)), - "m_album->forEachMedia() failed!"); - - FAIL_RETURN(Page::prepare( - [this]() - { - return getNaviframe().push(*m_imageGrid); - }), - "Page::prepare() failed!"); - - m_imageGrid->setItemCount(m_items.size()); - - return RES_OK; - } - - void ViewerPage::showItem(const int itemIndex) - { - m_imageGrid->scrollToItem(itemIndex); - } - - bool ViewerPage::onEachMedia(MediaItemUPtr &&media) - { - m_items.emplace_back( - new Item(std::move(media), *m_imageGrid, m_items.size())); - return true; - } - - void ViewerPage::onActivate() - { - m_imageGrid->activateRotary(); - } - - void ViewerPage::onDeactivate() - { - m_imageGrid->deactivateRotary(); - } - - void ViewerPage::onItemRealized(const int itemIndex) - { - m_items[itemIndex]->realize(); - } - - void ViewerPage::onItemUnrealized(const int itemIndex) - { - m_items[itemIndex]->unrealize(); - } - - void ViewerPage::onItemClicked(const int itemIndex) - { - ILOG("TODO Not implemented. Item: %d;", itemIndex); - } -}