--- /dev/null
+/*
+ * 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__
#include "model/MediaItem.h"
#include "presentation/ImageGrid.h"
+#include "presentation/ViewerPage.h"
#include "common.h"
// ThumbnailPage::RealizedItem //
- class ThumbnailPage::RealizedItem : NonCopyable {
+ class ThumbnailPage::RealizedItem : public NonCopyable {
public:
RealizedItem(ThumbnailPage &parent, const int index) :
m_parent(parent),
"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()
m_imageGrid = ImageGrid::Builder().
setListener(this).
+ setType(ImageGrid::Type::HCOMB_3X3).
build(getNaviframe());
if (!m_imageGrid) {
LOG_RETURN(RES_FAIL, "ImageGrid::build() failed!");
return RES_OK;
}
- bool ThumbnailPage::onEachMedia(MediaItemUPtr media)
+ bool ThumbnailPage::onEachMedia(MediaItemUPtr &&media)
{
m_mediaItems.emplace_back(std::move(media));
return true;
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();
}
}
--- /dev/null
+/*
+ * 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);
+ }
+}