--- /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_I_IMAGE_GRID_LISTENER_H__
+#define __GALLERY_PRESENTATION_I_IMAGE_GRID_LISTENER_H__
+
+#include "types.h"
+
+namespace gallery {
+
+ class IImageGridListener : public ucl::Polymorphic {
+ public:
+ virtual void onItemRealized(int itemIndex) = 0;
+ virtual void onItemUnrealized(int itemIndex) = 0;
+ };
+}
+
+#endif // __GALLERY_PRESENTATION_I_IMAGE_GRID_LISTENER_H__
* limitations under the License.
*/
-#ifndef __GALLERY_VIEW_IMAGE_GRID_H__
-#define __GALLERY_VIEW_IMAGE_GRID_H__
+#ifndef __GALLERY_PRESENTATION_IMAGE_GRID_H__
+#define __GALLERY_PRESENTATION_IMAGE_GRID_H__
#include <deque>
#include "ucl/gui/StyledWidget.h"
-namespace gallery {
+#include "types.h"
- UCL_DECLARE_REF_ALIASES(ImageGrid);
+namespace gallery {
class ImageGrid : public ucl::Widget {
public:
HCOMB_3X3
};
- class IListener : public ucl::Polymorphic {
- public:
- virtual void onItemRealized(int itemIndex) = 0;
- virtual void onItemUnrealized(int itemIndex) = 0;
- };
-
class Builder {
public:
Builder();
Builder &setType(Type value);
- Builder &setListener(IListener *value);
+ Builder &setListener(IImageGridListener *value);
ImageGridSRef build(Widget &parent) const;
private:
Type m_type;
- IListener *m_listener;
+ IImageGridListener *m_listener;
};
struct ItemParams {
std::string imagePath;
};
+ class Unrealizer : ucl::NonCopyable {
+ public:
+ Unrealizer(ImageGrid &imageGrid);
+ ~Unrealizer();
+ private:
+ ImageGrid &m_imageGrid;
+ };
+
public:
- void setListener(IListener *listener);
+ void setListener(IImageGridListener *listener);
void setItemCount(int count);
template <class FUNC>
ucl::Result doWithItem(int itemIndex, FUNC &&func);
+ void addUnrealizeLock();
+ void removeUnrealizeLock();
+
// Initialization
void prepare();
private:
const Info &m_info;
- ucl::StyledWidget m_scroller;
+ ucl::StyledWidgetWRef m_scroller;
ucl::ElmWidget m_box;
ucl::Widget m_rect1;
ucl::Widget m_rect2;
- IListener *m_listener;
+ IImageGridListener *m_listener;
int m_itemCount;
std::deque<SlotUPtr> m_slots;
int m_slotSize;
int m_scrollerSize;
int m_scrollOffset;
+
+ int m_unrealizeLock;
};
}
-#endif // __GALLERY_VIEW_IMAGE_GRID_H__
+#endif // __GALLERY_PRESENTATION_IMAGE_GRID_H__
namespace gallery {
- UCL_DECLARE_REF_ALIASES(Page);
-
class Page : public ucl::RefCountAware {
public:
using ExitRequestHandler = ucl::Delegate<void(Page &page)>;
--- /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_THUMBNAIL_PAGE_H__
+#define __GALLERY_PRESENTATION_THUMBNAIL_PAGE_H__
+
+#include "Page.h"
+
+#include "IImageGridListener.h"
+
+#include "model/types.h"
+
+namespace gallery {
+
+ class ThumbnailPage final : public Page,
+ IImageGridListener {
+ public:
+ class Builder {
+ public:
+ Builder();
+ ~Builder();
+ Builder &setNaviframe(const ucl::NaviframeSRef &navi);
+ Builder &setAlbum(const IMediaAlbumSRef &album);
+ ThumbnailPageSRef build(ExitRequestHandler onExitRequest) const;
+ private:
+ ucl::NaviframeSRef m_navi;
+ IMediaAlbumSRef m_album;
+ };
+
+ private:
+ friend class ucl::RefCountObj<ThumbnailPage>;
+ ThumbnailPage(ucl::RefCountObjBase &rc, const ucl::NaviframeSRef &navi,
+ ExitRequestHandler onExitRequest, const IMediaAlbumSRef &album);
+ virtual ~ThumbnailPage();
+
+ Result prepare();
+
+ bool onEachMedia(MediaItemUPtr media);
+
+ // IImageGridListener //
+
+ virtual void onItemRealized(int itemIndex) final override;
+ virtual void onItemUnrealized(int itemIndex) final override;
+
+ private:
+ class RealizedItem;
+ using RealizedItemUPtr = std::unique_ptr<RealizedItem>;
+
+ private:
+ const IMediaAlbumSRef m_album;
+ std::vector<MediaItemUPtr> m_mediaItems;
+
+ std::vector<RealizedItemUPtr> m_realizedItems;
+
+ ImageGridSRef m_imageGrid;
+ };
+}
+
+#endif // __GALLERY_PRESENTATION_THUMBNAIL_PAGE_H__
--- /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_TYPES_H__
+#define __GALLERY_PRESENTATION_TYPES_H__
+
+#include "../types.h"
+
+namespace gallery {
+
+ class IImageGridListener;
+
+ UCL_DECLARE_REF_ALIASES(ImageGrid);
+
+ UCL_DECLARE_REF_ALIASES(Page);
+
+ UCL_DECLARE_REF_ALIASES(ThumbnailPage);
+}
+
+#endif // __GALLERY_PRESENTATION_TYPES_H__
#include "ucl/gui/Layout.h"
-#include "../common.h"
+#include "presentation/IImageGridListener.h"
+
+#include "common.h"
namespace gallery { namespace { namespace impl {
return *this;
}
- ImageGrid::Builder &ImageGrid::Builder::setListener(IListener *const value)
+ ImageGrid::Builder &ImageGrid::Builder::setListener(
+ IImageGridListener *const value)
{
m_listener = value;
return *this;
bool m_isRealized;
};
+ // ImageGrid::Unrealizer //
+
+ ImageGrid::Unrealizer::Unrealizer(ImageGrid &imageGrid) :
+ m_imageGrid(imageGrid)
+ {
+ m_imageGrid.addUnrealizeLock();
+ }
+
+ ImageGrid::Unrealizer::~Unrealizer()
+ {
+ m_imageGrid.removeUnrealizeLock();
+ }
+
// ImageGrid //
ImageGrid::ImageGrid(RefCountObjBase *const rc, const Type type,
Widget(rc, scroller, true),
m_info(getInfo(type)),
- m_scroller(scroller),
- m_box(elm_box_add(m_scroller)),
+ m_scroller(makeShared<StyledWidget>(scroller)),
+ m_box(elm_box_add(*m_scroller)),
m_rect1(evas_object_rectangle_add(m_box.getEvas())),
m_rect2(evas_object_rectangle_add(m_box.getEvas())),
m_slotSize(0), // Must not be 0
m_scrollerSize(1), // Must not be 0
- m_scrollOffset(0)
+ m_scrollOffset(0),
+
+ m_unrealizeLock(0)
{
prepare();
show(m_rect2);
expandAndFill(m_box);
- m_scroller.setContent(m_box);
+ m_scroller->setContent(m_box);
elm_box_horizontal_set(m_box, toEina(m_info.isHorizontal));
show(m_box);
- expandAndFill(m_scroller);
+ expandAndFill(*m_scroller);
if (m_info.isHorizontal) {
elm_scroller_page_scroll_limit_set(
- m_scroller, m_info.scrollLimit, 0);
+ *m_scroller, m_info.scrollLimit, 0);
} else {
elm_scroller_page_scroll_limit_set(
- m_scroller, 0, m_info.scrollLimit);
+ *m_scroller, 0, m_info.scrollLimit);
}
- show(m_scroller);
+ show(*m_scroller);
- m_scroller.addEventHandler(WidgetEvent::RESIZE,
+ m_scroller->addEventHandler(WidgetEvent::RESIZE,
WEAK_DELEGATE(ImageGrid::onScrollerResize, asWeak(this)));
- m_scroller.addEventHandler(WidgetEvent::MOVE,
+ m_scroller->addEventHandler(WidgetEvent::MOVE,
WEAK_DELEGATE(ImageGrid::onScrollerMove, asWeak(this)));
m_box.addEventHandler(WidgetEvent::MOVE,
WEAK_DELEGATE(ImageGrid::onBoxMove, asWeak(this)));
}
- void ImageGrid::setListener(IListener *const listener)
+ void ImageGrid::setListener(IImageGridListener *const listener)
{
m_listener = listener;
}
void ImageGrid::update()
{
- unrealizeSlots(0, m_slotCount);
- realizeSlots();
+ Unrealizer(*this);
}
Result ImageGrid::updateItem(const int itemIndex, const ItemParams ¶ms)
return func(*m_slots[slotOffset], itemOffset);
}
+ void ImageGrid::addUnrealizeLock()
+ {
+ unrealizeSlots(0, m_slotCount);
+ ++m_unrealizeLock;
+ }
+
+ void ImageGrid::removeUnrealizeLock()
+ {
+ if (m_unrealizeLock > 0) {
+ --m_unrealizeLock;
+ realizeSlots();
+ } else {
+ WLOG("m_unrealizeLock = 0!");
+ }
+ }
+
bool ImageGrid::updateSlotCount()
{
const int newSlotCount = calcSlotCount();
UCL_ASSERT(!isOdd, "Must be even!");
m_slotSize = std::max(slot->calcSize(), 1);
if (m_info.isHorizontal) {
- elm_scroller_page_size_set(m_scroller, m_slotSize, 0);
+ elm_scroller_page_size_set(*m_scroller, m_slotSize, 0);
} else {
- elm_scroller_page_size_set(m_scroller, 0, m_slotSize);
+ elm_scroller_page_size_set(*m_scroller, 0, m_slotSize);
}
}
{
int scrollerW = 0;
int scrollerH = 0;
- getSize(m_scroller, &scrollerW, &scrollerH);
+ getSize(*m_scroller, &scrollerW, &scrollerH);
return std::max((m_info.isHorizontal ? scrollerW : scrollerH), 1);
}
{
int scrollerX = 0;
int scrollerY = 0;
- getPosition(m_scroller, &scrollerX, &scrollerY);
+ getPosition(*m_scroller, &scrollerX, &scrollerY);
int boxX = 0;
int boxY = 0;
void ImageGrid::realizeSlots()
{
- for (int i = 0; i < m_slotCount; ++i) {
- m_slots[i]->realize(m_beginSlotIndex + i);
+ if (m_unrealizeLock == 0) {
+ for (int i = 0; i < m_slotCount; ++i) {
+ m_slots[i]->realize(m_beginSlotIndex + i);
+ }
}
}
void ImageGrid::unrealizeSlots(
const int beginSlotOffset, const int endSlotOffset)
{
- for (int i = beginSlotOffset; i < endSlotOffset; ++i) {
- m_slots[i]->unrealize();
+ if (m_unrealizeLock == 0) {
+ for (int i = beginSlotOffset; i < endSlotOffset; ++i) {
+ m_slots[i]->unrealize();
+ }
}
}
#include <efl_extension.h>
-#include "../common.h"
+#include "common.h"
namespace gallery { namespace { namespace impl {
using namespace ucl;
Page::Page(RefCountObjBase &rc, const NaviframeSRef &navi,
- ExitRequestHandler onExitRequest) :
+ const ExitRequestHandler onExitRequest) :
RefCountAware(&rc),
m_navi(navi),
m_onExitRequest(onExitRequest),
m_rc->ref();
- if (!m_navi->isInTransition()) {
+ if (!m_navi->isInTransition() && isAtTop()) {
dispatchTopPageChanged();
}
void Page::exitNoTransition()
{
- if (isValid(m_item)) {
+ if (isAtTop()) {
m_item.del();
dispatchTopPageChanged();
+ } else if (isValid(m_item)) {
+ m_item.del();
}
}
--- /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/ThumbnailPage.h"
+
+#include "model/IMediaAlbum.h"
+#include "model/MediaItem.h"
+
+#include "presentation/ImageGrid.h"
+
+#include "common.h"
+
+namespace gallery {
+
+ using namespace ucl;
+
+ // ThumbnailPage::Builder //
+
+ ThumbnailPage::Builder::Builder()
+ {
+ }
+
+ ThumbnailPage::Builder::~Builder()
+ {
+ }
+
+ ThumbnailPage::Builder &ThumbnailPage::Builder::setNaviframe(
+ const NaviframeSRef &navi)
+ {
+ m_navi = navi;
+ return *this;
+ }
+
+ ThumbnailPage::Builder &ThumbnailPage::Builder::setAlbum(
+ const IMediaAlbumSRef &album)
+ {
+ m_album = album;
+ return *this;
+ }
+
+ ThumbnailPageSRef ThumbnailPage::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<ThumbnailPage>(
+ m_navi, onExitRequest, m_album);
+
+ FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!");
+
+ return result;
+ }
+
+ // ThumbnailPage::RealizedItem //
+
+ class ThumbnailPage::RealizedItem : NonCopyable {
+ public:
+ RealizedItem(ThumbnailPage &parent, const int index) :
+ m_parent(parent),
+ m_index(index)
+ {
+ FAIL_LOG(m_parent.m_mediaItems[m_index]->getThumbnailPath(
+ DELEGATE(RealizedItem::onThumbnail, this)),
+ "getThumbnailPath() failed!");
+ }
+
+ ~RealizedItem()
+ {
+ m_parent.m_mediaItems[m_index]->cancelThumbnailPathGet();
+ }
+
+ int getIndex() const
+ {
+ return m_index;
+ }
+
+ private:
+ void onThumbnail(const Result result, const std::string &path)
+ {
+ FAIL_RETURN_VOID(result, "Failed to get thumbnail!");
+ m_parent.m_imageGrid->updateItem(m_index, {path});
+ }
+
+ private:
+ ThumbnailPage &m_parent;
+ int m_index;
+ };
+
+ // ThumbnailPage //
+
+ ThumbnailPage::ThumbnailPage(RefCountObjBase &rc,
+ const NaviframeSRef &navi,
+ const ExitRequestHandler onExitRequest,
+ const IMediaAlbumSRef &album) :
+ Page(rc, navi, onExitRequest),
+ m_album(album)
+ {
+ }
+
+ ThumbnailPage::~ThumbnailPage()
+ {
+ m_imageGrid->setListener(nullptr);
+ }
+
+ Result ThumbnailPage::prepare()
+ {
+ FAIL_RETURN(m_album->forEachMedia(
+ DELEGATE(ThumbnailPage::onEachMedia, this)),
+ "m_album->forEachMedia() failed!");
+
+ m_imageGrid = ImageGrid::Builder().
+ setListener(this).
+ build(getNaviframe());
+ if (!m_imageGrid) {
+ LOG_RETURN(RES_FAIL, "ImageGrid::build() failed!");
+ }
+
+ FAIL_RETURN(Page::prepare(
+ [this]()
+ {
+ return getNaviframe().push(*m_imageGrid);
+ }),
+ "Page::prepare() failed!");
+
+ m_imageGrid->setItemCount(m_mediaItems.size());
+
+ return RES_OK;
+ }
+
+ bool ThumbnailPage::onEachMedia(MediaItemUPtr media)
+ {
+ m_mediaItems.emplace_back(std::move(media));
+ return true;
+ }
+
+ void ThumbnailPage::onItemRealized(const int itemIndex)
+ {
+ m_realizedItems.emplace_back(new RealizedItem(*this, itemIndex));
+ }
+
+ void ThumbnailPage::onItemUnrealized(const int itemIndex)
+ {
+ const auto it = std::find_if(
+ m_realizedItems.begin(), m_realizedItems.end(),
+ [itemIndex](const RealizedItemUPtr &item)
+ {
+ return (item->getIndex() == itemIndex);
+ });
+ if (it != m_realizedItems.end()) {
+ m_realizedItems.erase(it);
+ } else {
+ WLOG("Item is not found in realized list!");
+ }
+ }
+}
--- /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_COMMON_H__
+#define __GALLERY_PRESENTATION_COMMON_H__
+
+#include "../common.h"
+
+#endif // __GALLERY_PRESENTATION_COMMON_H__
};
public:
- friend class RefCountObj<Naviframe>;
using StyledWidget::StyledWidget;
bool isInTransition() const;
private:
friend class RefCountObj<Naviframe>;
friend class NaviItem;
- Naviframe(RefCountObjBase &rc, Evas_Object *eo, bool isOwner = false);
+ Naviframe(RefCountObjBase &rc, Evas_Object *eo);
void startTransition();
// Naviframe //
- Naviframe::Naviframe(RefCountObjBase &rc, Evas_Object *eo, bool isOwner) :
- StyledWidget(&rc, eo, isOwner),
+ Naviframe::Naviframe(RefCountObjBase &rc, Evas_Object *eo) :
+ StyledWidget(&rc, eo, true),
m_isInTransition(false)
{
addEventHandler(NAVI_TRANSITION_FINISHED, WEAK_DELEGATE(