TizenRefApp-8276 [Gallery] Implement ViewerPage 19/122219/5
authorIgor Nazarov <i.nazarov@samsung.com>
Thu, 30 Mar 2017 13:54:52 +0000 (16:54 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Thu, 30 Mar 2017 18:35:11 +0000 (21:35 +0300)
- Added ViewerPage implementation;
- Added code to launch ViewerPage from ThumbnailPage on item click;
- ucl::Naviframe bug fix;
- Other minor changes.

Change-Id: Ieaafa58d106b8ca84c04cf787e5af2062d146354

inc/model/IMediaAlbum.h
inc/presentation/ThumbnailPage.h
inc/presentation/ViewerPage.h [new file with mode: 0644]
inc/presentation/types.h
src/model/MediaItem.cpp
src/presentation/ImageGrid.cpp
src/presentation/ThumbnailPage.cpp
src/presentation/ViewerPage.cpp [new file with mode: 0644]
ucl/inc/ucl/gui/Naviframe.h
ucl/inc/ucl/gui/Naviframe.hpp
ucl/src/gui/Naviframe.cpp

index b04771bcb6df90a560da51fba399018db31e9214..452568fa31d86c241bbfd77ec51e4f5466489757 100644 (file)
@@ -23,7 +23,7 @@ namespace gallery {
 
        class IMediaAlbum : public ucl::Polymorphic {
        public:
-               using EachCb = ucl::Delegate<bool(MediaItemUPtr media)>;
+               using EachCb = ucl::Delegate<bool(MediaItemUPtr &&media)>;
 
        public:
                virtual ucl::Result forEachMedia(EachCb cb) const = 0;
index c866439ceca6c363ffe84af865228459213545e7..7bf1589af67eac920998bfcff1909812040f0fc4 100644 (file)
@@ -26,7 +26,7 @@
 namespace gallery {
 
        class ThumbnailPage final : public Page,
-                       IImageGridListener {
+                       private IImageGridListener {
        public:
                class Builder {
                public:
@@ -51,7 +51,9 @@ namespace gallery {
 
                Result prepare();
 
-               bool onEachMedia(MediaItemUPtr media);
+               bool onEachMedia(MediaItemUPtr &&media);
+
+               void onPageExitRequest(Page &page);
 
                // Page //
 
@@ -75,6 +77,8 @@ namespace gallery {
                std::vector<RealizedItemUPtr> m_realizedItems;
 
                ImageGridSRef m_imageGrid;
+
+               PageWRef m_page;
        };
 }
 
diff --git a/inc/presentation/ViewerPage.h b/inc/presentation/ViewerPage.h
new file mode 100644 (file)
index 0000000..49a7d36
--- /dev/null
@@ -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_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>;
+               ViewerPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+                               ExitRequestHandler onExitRequest, const IMediaAlbumSRef &album);
+               virtual ~ViewerPage();
+
+               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<Item>;
+
+       private:
+               const IMediaAlbumSRef m_album;
+               ImageGridSRef m_imageGrid;
+               std::vector<ItemUPtr> m_items;
+       };
+}
+
+#endif // __GALLERY_PRESENTATION_VIEWER_PAGE_H__
index fed835777d51270eef64a14a6cdfe6d918d8fb06..a73b00d17e1777e976a0d7537ee072cddbe0bac7 100644 (file)
@@ -30,6 +30,8 @@ namespace gallery {
        UCL_DECLARE_REF_ALIASES(Page);
 
        UCL_DECLARE_REF_ALIASES(ThumbnailPage);
+
+       UCL_DECLARE_REF_ALIASES(ViewerPage);
 }
 
 #endif // __GALLERY_PRESENTATION_TYPES_H__
index 7a492f5eee446d44b016ab3880c1419c973ddf3a..725fa2d52bd346d4d1f2c1863b3da86ecdfd1567 100644 (file)
@@ -24,9 +24,9 @@ namespace gallery {
 
        MediaItem::MediaItem(const MediaType type) :
                m_type(type),
-               m_media(nullptr),
                m_resolutionX(0),
                m_resolutionY(0),
+               m_media(nullptr),
                m_isValid(false)
        {
        }
index 16ad4d7d2851f4efa9afbc1a18fcaad475bfab3a..09b4cf7d625e150e096c0258336aae16e50ffaee 100644 (file)
@@ -768,7 +768,7 @@ namespace gallery {
 
        int ImageGrid::calcOptimalSlotCount()
        {
-               return (((m_scrollerSize * 3 + m_slotSize / 2) / m_slotSize) * 2);
+               return (((m_scrollerSize / m_slotSize) + 3) * 2);
        }
 
        bool ImageGrid::updateMaxSlotCount()
@@ -897,7 +897,8 @@ namespace gallery {
 
        void ImageGrid::updateScrollBias()
        {
-               m_scrollBias = ((m_slotCount / 2 - 1) / 2 * m_slotSize + m_padSize1);
+               m_scrollBias = (((m_optimalSlotCount / 2 - 1) * m_slotSize -
+                               m_scrollerSize) / 2 + m_padSize1);
        }
 
        void ImageGrid::updateRectMins()
index 8db0a2e5903086e94b55d6bf100ac161a4f801b4..f4d4ecdc31af699cbe7a0d00643bf60066f7309f 100644 (file)
@@ -20,6 +20,7 @@
 #include "model/MediaItem.h"
 
 #include "presentation/ImageGrid.h"
+#include "presentation/ViewerPage.h"
 
 #include "common.h"
 
@@ -77,7 +78,7 @@ namespace gallery {
 
        // ThumbnailPage::RealizedItem //
 
-       class ThumbnailPage::RealizedItem : NonCopyable {
+       class ThumbnailPage::RealizedItem : public NonCopyable {
        public:
                RealizedItem(ThumbnailPage &parent, const int index) :
                        m_parent(parent),
@@ -141,6 +142,10 @@ namespace gallery {
                                "m_album->forEachMedia() failed!");
 
                m_imageGrid->setItemCount(m_mediaItems.size());
+
+               if (const auto vp = dynamic_cast<ViewerPage *>(m_page.get())) {
+                       vp->reload();
+               }
        }
 
        Result ThumbnailPage::prepare()
@@ -151,6 +156,7 @@ namespace gallery {
 
                m_imageGrid = ImageGrid::Builder().
                                setListener(this).
+                               setType(ImageGrid::Type::HCOMB_3X3).
                                build(getNaviframe());
                if (!m_imageGrid) {
                        LOG_RETURN(RES_FAIL, "ImageGrid::build() failed!");
@@ -168,7 +174,7 @@ namespace gallery {
                return RES_OK;
        }
 
-       bool ThumbnailPage::onEachMedia(MediaItemUPtr media)
+       bool ThumbnailPage::onEachMedia(MediaItemUPtr &&media)
        {
                m_mediaItems.emplace_back(std::move(media));
                return true;
@@ -206,6 +212,15 @@ namespace gallery {
 
        void ThumbnailPage::onItemClicked(const int itemIndex)
        {
-               ILOG("TODO Not implemented. Item: %d;", itemIndex);
+               m_page = ViewerPage::Builder().
+                               setNaviframe(asShared(getNaviframe())).
+                               setAlbum(m_album).
+                               setStartItemIndex(itemIndex).
+                               build(DELEGATE(ThumbnailPage::onPageExitRequest, this));
+       }
+
+       void ThumbnailPage::onPageExitRequest(Page &page)
+       {
+               popTo();
        }
 }
diff --git a/src/presentation/ViewerPage.cpp b/src/presentation/ViewerPage.cpp
new file mode 100644 (file)
index 0000000..c229205
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * 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<ViewerPage>(
+                               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);
+       }
+}
index c62c3398347fb4d07e637436392b290eab34f5b5..1e294d37492fb67b1f3cf8d8d716d46c47720368 100644 (file)
@@ -35,18 +35,14 @@ namespace ucl {
                public:
                        Builder();
                        Builder &setStyle(ElmStyle value);
-                       Builder &setIsOwner(bool value);
                        Builder &setNeedBindToEo(bool value);
                        NaviframeSRef build(Widget &parent) const;
                private:
                        ElmStyle m_style;
-                       bool m_isOwner;
                        bool m_needBindToEo;
                };
 
        public:
-               using StyledWidget::StyledWidget;
-
                bool isInTransition() const;
 
                void setAutoBackBtn(bool value);
index 5d67bc4ebca683ae84da65e4ffac2fcdb06a9553..8acde08bdefe834bb3ed91bebdbdbd6cf5dd686a 100644 (file)
@@ -19,7 +19,6 @@ namespace ucl {
        // Naviframe::Builder //
 
        inline Naviframe::Builder::Builder() :
-               m_isOwner(false),
                m_needBindToEo(true)
        {
        }
@@ -31,12 +30,6 @@ namespace ucl {
                return *this;
        }
 
-       inline Naviframe::Builder &Naviframe::Builder::setIsOwner(const bool value)
-       {
-               m_isOwner = value;
-               return *this;
-       }
-
        inline Naviframe::Builder &Naviframe::Builder::setNeedBindToEo(
                        const bool value)
        {
index 476b054f5597162abe2a4026e02c6e0ec3831955..8c296fd0c55e568631f96968d8fbff73533a4686 100644 (file)
@@ -30,7 +30,7 @@ namespace ucl {
                        return {};
                }
 
-               auto result = makeShared<Naviframe>(eo, m_isOwner);
+               auto result = makeShared<Naviframe>(eo);
 
                if (m_needBindToEo) {
                        result->bindToEo();