TizenRefApp-8358 [Gallery] Implement ImageGrid item select logic 44/124544/2
authorIgor Nazarov <i.nazarov@samsung.com>
Tue, 11 Apr 2017 14:42:46 +0000 (17:42 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Tue, 11 Apr 2017 15:26:59 +0000 (18:26 +0300)
- Implemented item select logic in ImageGrid;
- Added Select Mode Startup feature into ImageGrid.

Change-Id: I638a73a2ce7bc1b19f8de5c23ba8e2e4a20f8b38

edc/image-grid.edc
inc/view/ImageGrid.h
src/view/ImageGrid.cpp

index 81ce69dc552b64d8d1f3b91464de7854a5d04986..ad03e260604c5e0841d689b12979e16f04e87e5e 100644 (file)
@@ -211,6 +211,13 @@ group { "elm/layout/gallery_image_grid/linear";
          target: "image_mask_0";
          after: "transition_finished";
       }
+      program { "gallery,force,select,mode";
+         signal: "gallery,force,select,mode";
+         source: "";
+         action: STATE_SET "select_mode";
+         target: "spacer";
+         target: "image_mask_0";
+      }
       program { "gallery,disable,select,mode";
          signal: "gallery,disable,select,mode";
          source: "";
index 712f827e462f6d275239924e1100dc9bb4822776..d251b86537665ffe417bd7c1d47b26b66124b266 100644 (file)
@@ -42,16 +42,19 @@ namespace gallery {
                        Builder();
                        Builder &setType(Type value);
                        Builder &setListener(IImageGridListener *value);
+                       Builder &setSelectModeStartup(bool value);
                        ImageGridSRef build(Widget &parent) const;
                private:
                        Type m_type;
                        IImageGridListener *m_listener;
+                       bool m_selectModeStartup;
                };
 
                enum {
                        UF_LOSE_IMAGE = 1,
                        UF_LOSE_BG = 2,
-                       UF_BLOCK_CLICKS = 4
+                       UF_BLOCK_CLICKS = 4,
+                       UF_SELECTED = 8
                };
 
                struct ItemParams {
@@ -101,7 +104,8 @@ namespace gallery {
 
        private:
                friend class ucl::RefCountObj<ImageGrid>;
-               ImageGrid(ucl::RefCountObjBase *rc, Type type, Evas_Object *scroller);
+               ImageGrid(ucl::RefCountObjBase *rc, Evas_Object *scroller,
+                               Type type, bool selectModeStartup);
                virtual ~ImageGrid();
 
                static const Info &getInfo(Type type);
index 0ef62161b86164029f3ad488e1f01b7108f3ffcc..da5b42798e2f5c52500929fad152da9f359679e7 100644 (file)
@@ -33,6 +33,11 @@ namespace gallery { namespace { namespace impl {
        // Related to ImageGrid //
        const TString SLOT_PART_FMT {"swallow.cell_%d"};
 
+       const TString SIGNAL_SELECT_ITEM_FMT {"gallery,select,%d"};
+       const TString SIGNAL_UNSELECT_ITEM_FMT {"gallery,unselect,%d"};
+
+       constexpr EdjeSignal SIGNAL_FORCE_SELECT_MODE
+                       {"gallery,force,select,mode"};
        constexpr EdjeSignal SIGNAL_ENABLE_SELECT_MODE
                        {"gallery,enable,select,mode"};
        constexpr EdjeSignal SIGNAL_DISABLE_SELECT_MODE
@@ -42,7 +47,7 @@ namespace gallery { namespace { namespace impl {
 
        // Related to Button //
        constexpr ElmStyle ITEM_BTN_STYLE {"gallery_image"};
-       constexpr EdjePart PART_BTN_BG {"swallow.bg"};
+       constexpr EdjePart BTN_PART_BG {"swallow.bg"};
        constexpr SmartEvent BTN_CLICKED {"clicked"};
        constexpr EdjeSignal BTN_BLOCK_CLICKS {"gallery,block,clicks"};
        constexpr EdjeSignal BTN_UNBLOCK_CLICKS {"gallery,unblock,clicks"};
@@ -59,7 +64,8 @@ namespace gallery {
 
        ImageGrid::Builder::Builder() :
                m_type(Type::HCOMB_3X3),
-               m_listener(nullptr)
+               m_listener(nullptr),
+               m_selectModeStartup(false)
        {
        }
 
@@ -76,6 +82,13 @@ namespace gallery {
                return *this;
        }
 
+       ImageGrid::Builder &ImageGrid::Builder::setSelectModeStartup(
+                       const bool value)
+       {
+               m_selectModeStartup = value;
+               return *this;
+       }
+
        ImageGridSRef ImageGrid::Builder::build(Widget &parent) const
        {
                Evas_Object *const scrollerEo = elm_scroller_add(parent);
@@ -84,7 +97,8 @@ namespace gallery {
                        return {};
                }
 
-               auto result = makeShared<ImageGrid>(m_type, scrollerEo);
+               auto result = makeShared<ImageGrid>(scrollerEo,
+                               m_type, m_selectModeStartup);
 
                result->bindToEo();
                result->setListener(m_listener);
@@ -211,7 +225,8 @@ namespace gallery {
                                m_realizeIndex(-1),
                                m_imageLoadSize(0),
                                m_wasUpdated(false),
-                               m_isClicksBlocked(false)
+                               m_isClicksBlocked(false),
+                               m_isSelected(false)
                        {
                                m_btn.setFocusAlowed(false);
                                m_btn.setStyle(impl::ITEM_BTN_STYLE);
@@ -282,6 +297,18 @@ namespace gallery {
                                }
                        }
 
+                       bool setSelected(const bool selected)
+                       {
+                               if (selected == m_isSelected) {
+                                       return false;
+                               }
+                               if (selected && !m_imageGrid.m_isInSelectMode) {
+                                       return false;
+                               }
+                               m_isSelected = selected;
+                               return true;
+                       }
+
                        bool update(const ItemParams &params)
                        {
                                if (!isRealized()) {
@@ -342,7 +369,7 @@ namespace gallery {
                                                        evas_object_image_filled_add(m_btn.getEvas()));
                                        evas_object_image_load_size_set(*m_bgImage,
                                                        m_imageLoadSize, m_imageLoadSize);
-                                       m_btn.setContent(impl::PART_BTN_BG, *m_bgImage);
+                                       m_btn.setContent(impl::BTN_PART_BG, *m_bgImage);
                                        show(*m_bgImage);
                                }
 
@@ -385,6 +412,7 @@ namespace gallery {
                        int m_imageLoadSize;
                        bool m_wasUpdated;
                        bool m_isClicksBlocked;
+                       bool m_isSelected;
                };
 
        public:
@@ -393,9 +421,12 @@ namespace gallery {
                        m_layout(elm_layout_add(imageGrid.m_box), true),
                        m_isRealized(false)
                {
-                       if (isValid(m_info.slotThemes[isOdd]) &&
-                                       !m_layout.setTheme(m_info.slotThemes[isOdd])) {
-                               ELOG("setTheme() failed!");
+                       if (isValid(m_info.slotThemes[isOdd])) {
+                               if (!m_layout.setTheme(m_info.slotThemes[isOdd])) {
+                                       ELOG("setTheme() failed!");
+                               } else if (imageGrid.m_isInSelectMode) {
+                                       m_layout.emitSignal(impl::SIGNAL_FORCE_SELECT_MODE);
+                               }
                        }
                        fill(m_layout);
                        show(m_layout);
@@ -455,8 +486,16 @@ namespace gallery {
                        }
                }
 
+               void unselect()
+               {
+                       for (UInt i = 0; i < m_items.size(); ++i) {
+                               setSelected(i, false);
+                       }
+               }
+
                bool updateItem(const int itemOffset, const ItemParams &params)
                {
+                       setSelected(itemOffset, (params.flags & UF_SELECTED));
                        return m_items[itemOffset]->update(params);
                }
 
@@ -465,6 +504,18 @@ namespace gallery {
                        return m_items[itemOffset]->isRealized();
                }
 
+       private:
+               void setSelected(const int itemOffset, const bool selected)
+               {
+                       if (!m_items[itemOffset]->setSelected(selected)) {
+                               return;
+                       }
+                       const auto aSignal = EdjeSignal(selected ?
+                                       impl::SIGNAL_SELECT_ITEM_FMT.format(itemOffset) :
+                                       impl::SIGNAL_UNSELECT_ITEM_FMT.format(itemOffset));
+                       m_layout.emitSignal(aSignal);
+               }
+
        private:
                const Info &m_info;
                std::vector<SharedRef<Item>> m_items;
@@ -487,8 +538,8 @@ namespace gallery {
 
        // ImageGrid //
 
-       ImageGrid::ImageGrid(RefCountObjBase *const rc, const Type type,
-                       Evas_Object *const scroller) :
+       ImageGrid::ImageGrid(RefCountObjBase *const rc, Evas_Object *const scroller,
+                       const Type type, const bool selectModeStartup) :
                Widget(rc, scroller, true),
                m_info(getInfo(type)),
 
@@ -520,7 +571,7 @@ namespace gallery {
                m_eventsLock(0),
 
                m_animator(nullptr),
-               m_isInSelectMode(false),
+               m_isInSelectMode(selectModeStartup),
                m_isRotaryActive(false)
        {
                prepare();
@@ -682,6 +733,10 @@ namespace gallery {
                evas_object_freeze_events_set(*m_scroller, EINA_TRUE);
                eext_rotary_object_event_activated_set(m_circleScroller, EINA_FALSE);
 
+               for (auto &slot: m_slots) {
+                       slot->unselect();
+               }
+
                const auto aSignal = (enabled ?
                                impl::SIGNAL_ENABLE_SELECT_MODE :
                                impl::SIGNAL_DISABLE_SELECT_MODE);
@@ -789,6 +844,9 @@ namespace gallery {
 
        Result ImageGrid::updateItem(const int itemIndex, const ItemParams &params)
        {
+               if (m_animator) {
+                       LOG_RETURN(RES_ILLEGAL_STATE, "Transition is in progress.");
+               }
                return doWithItem(itemIndex,
                        [&params](Slot &slot, const int itemOffset)
                        {
@@ -941,6 +999,8 @@ namespace gallery {
 
                        if (m_slotSize == 0) {
                                UCL_ASSERT(!isOdd, "Must be even!");
+                               edje_object_message_signal_process(
+                                               elm_layout_edje_get(slot->getLayout()));
                                slot->getLayout().calculate();
                                setSlotSize(slot->getSize());
                        }