diff options
author | Igor Nazarov <i.nazarov@samsung.com> | 2017-04-11 21:30:53 +0300 |
---|---|---|
committer | Igor Nazarov <i.nazarov@samsung.com> | 2017-04-11 21:30:53 +0300 |
commit | ff044cd8ec4264edea237d4cb5892deed961b89b (patch) | |
tree | 66f197da737852d3c7dd9ce4bc4a4b57ad8eae00 | |
parent | 4fd0cbdc289bbb30c7432f544445444deecfd4f0 (diff) | |
download | gallery-ff044cd8ec4264edea237d4cb5892deed961b89b.tar.gz gallery-ff044cd8ec4264edea237d4cb5892deed961b89b.tar.bz2 gallery-ff044cd8ec4264edea237d4cb5892deed961b89b.zip |
TizenRefApp-8360 [Gallery] Implement select logic in PreviewPage
- Implemented select mode logic in PreviewPage;
- Fixed bug in ImageGrid;
- Tweaked scroll friction.
Change-Id: I574069dd2d5e76fd834e267661403f5ab58a9b78
-rw-r--r-- | inc/presenters/PreviewPage.h | 13 | ||||
-rw-r--r-- | src/presenters/PreviewPage.cpp | 147 | ||||
-rw-r--r-- | src/presenters/ThumbnailPage.cpp | 11 | ||||
-rw-r--r-- | src/view/ImageGrid.cpp | 1 |
4 files changed, 163 insertions, 9 deletions
diff --git a/inc/presenters/PreviewPage.h b/inc/presenters/PreviewPage.h index 86fcedc..7bae7c3 100644 --- a/inc/presenters/PreviewPage.h +++ b/inc/presenters/PreviewPage.h @@ -33,11 +33,13 @@ namespace gallery { Builder &setNaviframe(const ucl::NaviframeSRef &navi); Builder &setAlbum(const IMediaAlbumSRef &album); Builder &setStartItemIndex(int index); + Builder &setSelectModeStartup(bool value); PreviewPageSRef build(ExitRequestHandler onExitRequest) const; private: ucl::NaviframeSRef m_navi; IMediaAlbumSRef m_album; int m_startItemIndex; + bool m_selectModeStartup; }; public: @@ -49,17 +51,25 @@ namespace gallery { ExitRequestHandler onExitRequest, const IMediaAlbumSRef &album); virtual ~PreviewPage(); - ucl::Result prepare(); + ucl::Result prepare(bool enableSelectMode); void showItem(int itemIndex); + void selectItem(int itemIndex); + int getSafeItemIndex(int itemIndex) const; bool onEachMedia(MediaItemSRef &&media); + void switchToSelectMode(int itemIndex); + void switchToNormalMode(); + void toggleItemSelected(int itemIndex); + void openViewer(int itemIndex, int x, int y); + void onPageExitRequest(Page &page); // Page // virtual void onActivate() final override; virtual void onDeactivate() final override; + virtual void onBackKey() final override; // IImageGridListener // @@ -67,6 +77,7 @@ namespace gallery { virtual void onItemUnrealized(int itemIndex) final override; virtual void onItemEvent(int itemIndex, int event, int x, int y) final override; + virtual void onTransitionFinished() final override; private: class Item; diff --git a/src/presenters/PreviewPage.cpp b/src/presenters/PreviewPage.cpp index 6b36bba..143243f 100644 --- a/src/presenters/PreviewPage.cpp +++ b/src/presenters/PreviewPage.cpp @@ -25,6 +25,12 @@ #include "common.h" +namespace gallery { namespace { namespace impl { + + constexpr auto BRING_IN_SCROLL_FRICTION = 0.25; + constexpr auto PAGE_SCROLL_IN_FRICTION = 0.25; +}}} + namespace gallery { using namespace ucl; @@ -32,7 +38,8 @@ namespace gallery { // PreviewPage::Builder // PreviewPage::Builder::Builder() : - m_startItemIndex(0) + m_startItemIndex(0), + m_selectModeStartup(false) { } @@ -61,6 +68,13 @@ namespace gallery { return *this; } + PreviewPage::Builder &PreviewPage::Builder::setSelectModeStartup( + const bool value) + { + m_selectModeStartup = value; + return *this; + } + PreviewPageSRef PreviewPage::Builder::build( const ExitRequestHandler onExitRequest) const { @@ -78,10 +92,14 @@ namespace gallery { auto result = makeShared<PreviewPage>( m_navi, onExitRequest, m_album); - FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); + FAIL_RETURN_VALUE(result->prepare(m_selectModeStartup), {}, + "result->prepare() failed!"); if (m_startItemIndex > 0) { result->showItem(m_startItemIndex); + if (m_selectModeStartup) { + result->selectItem(m_startItemIndex); + } } return result; @@ -94,7 +112,8 @@ namespace gallery { Item(MediaItemSRef &&media, ImageGrid &imageGrid, const int itemIndex) : m_media(std::move(media)), m_imageGrid(imageGrid), - m_index(itemIndex) + m_index(itemIndex), + m_isSelected(false) { } @@ -115,6 +134,30 @@ namespace gallery { return m_media; } + void setSelected(const bool selected) + { + if (selected == m_isSelected) { + return; + } + m_isSelected = selected; + + if (m_imageGrid.isInSelectMode()) { + ImageGrid::ItemParams params = {}; + addFlags(params); + m_imageGrid.updateItem(m_index, params); + } + } + + bool isSelected() const + { + return m_isSelected; + } + + void toggleSelected() + { + setSelected(!m_isSelected); + } + private: void onThumbnail(const Result result, const std::string &path) { @@ -124,15 +167,23 @@ namespace gallery { m_media->getResolution(params.aspectX, params.aspectY); params.imagePath = m_media->getFilePath(); params.bgImagePath = path; - params.flags = ImageGrid::UF_BLOCK_CLICKS; + addFlags(params); m_imageGrid.updateItem(m_index, params); } + void addFlags(ImageGrid::ItemParams ¶ms) const + { + params.flags |= (m_imageGrid.isInSelectMode() ? + 0 : ImageGrid::UF_BLOCK_CLICKS); + params.flags |= (m_isSelected ? ImageGrid::UF_SELECTED : 0); + } + private: const MediaItemSRef m_media; ImageGrid &m_imageGrid; const int m_index; + bool m_isSelected; }; // PreviewPage // @@ -183,11 +234,12 @@ namespace gallery { } } - Result PreviewPage::prepare() + Result PreviewPage::prepare(const bool enableSelectMode) { m_imageGrid = ImageGrid::Builder(). setListener(this). setType(ImageGrid::Type::LINEAR). + setSelectModeStartup(enableSelectMode). build(getNaviframe()); if (!m_imageGrid) { LOG_RETURN(RES_FAIL, "ImageGrid::build() failed!"); @@ -211,7 +263,26 @@ namespace gallery { void PreviewPage::showItem(const int itemIndex) { - m_imageGrid->scrollToItem(itemIndex); + m_imageGrid->scrollToItem(getSafeItemIndex(itemIndex)); + } + + void PreviewPage::selectItem(const int itemIndex) + { + if (getSafeItemIndex(itemIndex) != itemIndex) { + LOG_RETURN_VOID(RES_INVALID_ARGUMENTS, "itemIndex out of range!"); + } + m_items[itemIndex]->setSelected(true); + } + + int PreviewPage::getSafeItemIndex(const int itemIndex) const + { + if (itemIndex < 0) { + return 0; + } + if (itemIndex >= static_cast<int>(m_items.size())) { + return (m_items.size() - 1); + } + return itemIndex; } bool PreviewPage::onEachMedia(MediaItemSRef &&media) @@ -223,6 +294,11 @@ namespace gallery { void PreviewPage::onActivate() { + elm_config_scroll_page_scroll_friction_set( + impl::PAGE_SCROLL_IN_FRICTION); + elm_config_scroll_bring_in_scroll_friction_set( + impl::BRING_IN_SCROLL_FRICTION); + m_imageGrid->activateRotary(); } @@ -231,6 +307,18 @@ namespace gallery { m_imageGrid->deactivateRotary(); } + void PreviewPage::onBackKey() + { + if (m_imageGrid->isInTransition()) { + return; + } + if (m_imageGrid->isInSelectMode()) { + switchToNormalMode(); + return; + } + requestExit(); + } + void PreviewPage::onItemRealized(const int itemIndex) { m_items[itemIndex]->realize(); @@ -244,10 +332,55 @@ namespace gallery { void PreviewPage::onItemEvent(const int itemIndex, const int event, const int x, const int y) { - if (!isActive() || (event != ImageGrid::ITEM_EVENT_DOUBLE_TAP)) { + if (!isActive()) { return; } + if (m_imageGrid->isInSelectMode()) { + if (event == ImageGrid::ITEM_EVENT_CLICK) { + toggleItemSelected(itemIndex); + } + return; + } + + switch (event) { + case ImageGrid::ITEM_EVENT_TAP_AND_HOLD: + switchToSelectMode(itemIndex); + break; + case ImageGrid::ITEM_EVENT_DOUBLE_TAP: + openViewer(itemIndex, x, y); + break; + } + } + + void PreviewPage::onTransitionFinished() + { + m_imageGrid->update(); + } + + void PreviewPage::switchToSelectMode(const int itemIndex) + { + for (auto &item: m_items) { + item->setSelected(false); + } + + m_items[itemIndex]->setSelected(true); + + m_imageGrid->setSelectModeEnabled(true); + } + + void PreviewPage::switchToNormalMode() + { + m_imageGrid->setSelectModeEnabled(false); + } + + void PreviewPage::toggleItemSelected(const int itemIndex) + { + m_items[itemIndex]->toggleSelected(); + } + + void PreviewPage::openViewer(const int itemIndex, const int x, const int y) + { m_page = ViewerPage::Builder(). setNaviframe(asShared(getNaviframe())). setZoomIn(x, y). diff --git a/src/presenters/ThumbnailPage.cpp b/src/presenters/ThumbnailPage.cpp index f28f58f..d07a340 100644 --- a/src/presenters/ThumbnailPage.cpp +++ b/src/presenters/ThumbnailPage.cpp @@ -25,6 +25,12 @@ #include "common.h" +namespace gallery { namespace { namespace impl { + + constexpr auto BRING_IN_SCROLL_FRICTION = 0.5; + constexpr auto PAGE_SCROLL_IN_FRICTION = 0.5; +}}} + namespace gallery { using namespace ucl; @@ -184,6 +190,11 @@ namespace gallery { void ThumbnailPage::onActivate() { + elm_config_scroll_page_scroll_friction_set( + impl::PAGE_SCROLL_IN_FRICTION); + elm_config_scroll_bring_in_scroll_friction_set( + impl::BRING_IN_SCROLL_FRICTION); + m_imageGrid->activateRotary(); } diff --git a/src/view/ImageGrid.cpp b/src/view/ImageGrid.cpp index adb8791..690c1bc 100644 --- a/src/view/ImageGrid.cpp +++ b/src/view/ImageGrid.cpp @@ -634,7 +634,6 @@ namespace gallery { makeTransparent(m_rect2); show(m_rect2); - expandAndFill(m_box); m_scroller->setContent(m_box); elm_box_horizontal_set(m_box, toEina(m_info.isHorizontal)); show(m_box); |