TizenRefApp-6680 Implement "Not assigned" functionality in the Select Group View 39/86039/1
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Tue, 30 Aug 2016 08:03:21 +0000 (11:03 +0300)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Tue, 30 Aug 2016 08:03:57 +0000 (11:03 +0300)
Change-Id: I48f420cc84497e4416249e5eb3f3587508405423
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-apps-common/inc/Ux/SelectAllItem.h
lib-apps-common/inc/Ux/SelectView.h
lib-apps-common/src/Ux/SelectView.cpp
lib-contacts/inc/Contacts/Groups/GroupsView.h
lib-contacts/inc/Contacts/Input/ContactGroupsFieldItem.h
lib-contacts/src/Contacts/Groups/GroupsView.cpp
lib-contacts/src/Contacts/Input/ContactGroupsFieldItem.cpp

index 505edeb..8042b91 100644 (file)
@@ -25,7 +25,7 @@ namespace Ux
        /**
         * @brief "Select all" genlist item
         */
-       class SelectAllItem : public Ui::CheckItem
+       class EXPORT_API SelectAllItem : public Ui::CheckItem
        {
        public:
                /**
index d1e53f4..5c44151 100644 (file)
@@ -193,6 +193,12 @@ namespace Ux
                 */
                virtual void onSelectLimitChanged(size_t selectLimit) { }
 
+               /**
+                * @brief Called when selection count was changed.
+                * @param[in]   selectCount New selection count
+                */
+               virtual void onSelectCountChanged(size_t selectCount) { }
+
        private:
                friend class SelectItem;
 
index a7e66ee..26384fa 100644 (file)
@@ -291,6 +291,7 @@ void SelectView::updateSelectCount(CountChange change, SelectItem *item)
 {
        /* CURRENT count if incremented, PREVIOUS count otherwise */
        size_t checkCount = (change == CountIncrement) ? ++m_SelectCount : m_SelectCount--;
+       onSelectCountChanged(m_SelectCount);
 
        if (m_SelectLimit && m_SelectCount > m_SelectLimit) {
                item->setChecked(false);
index 9d0bc97..1b6d0d0 100644 (file)
@@ -28,6 +28,7 @@ namespace Ui
        class Genlist;
        class GenItem;
        class GenGroupItem;
+       class CheckItem;
 }
 
 namespace Contacts
@@ -60,8 +61,15 @@ namespace Contacts
                        virtual Evas_Object *onCreate(Evas_Object *parent) override;
                        virtual void onMenuPressed() override;
                        virtual void onSelectAllInsert(Ui::GenItem *item) override;
+                       virtual void onSelectModeChanged(Ux::SelectMode selectMode) override;
+                       virtual void onSelectCountChanged(size_t selectCount) override;
+
+                       void updateSelectAllItem();
+                       void updateNotAssignedItem();
                        void updateCreateItem();
 
+                       bool onNotAssignedChecked(bool isChecked);
+
                        void onInserted(::Model2::DataItem &data);
                        GroupItem *createItem(Model::Group &group);
                        void insertItem(GroupItem *item);
@@ -75,13 +83,16 @@ namespace Contacts
                        void deleteMembers(const std::vector<int> &groupIds);
 
                        Ui::Genlist *m_Genlist;
-                       CreateGroupItem *m_CreateItem;
-                       Model::GroupsProvider m_Provider;
                        Ui::GenGroupItem *m_GroupsItem;
                        std::vector<GroupItem *> m_MainItems;
 
+                       Ui::GenItemPtr m_SelectAllItem;
+                       Ui::CheckItem *m_NotAssignedItem;
+                       CreateGroupItem *m_CreateItem;
+
                        bool m_IsAssignMode;
                        int m_NewGroupId;
+                       Model::GroupsProvider m_Provider;
                };
        }
 }
index d1be23d..e63a8fa 100644 (file)
@@ -58,9 +58,11 @@ namespace Contacts
 
                        virtual void onInserted() override;
                        virtual void onSelected() override;
-                       bool onGroupsSelected(Ux::SelectResults results);
+                       virtual void onFocused() override;
 
                        std::string formatGroups() const;
+                       void pickGroups();
+                       bool onGroupsSelected(Ux::SelectResults results);
 
                        Model::ContactArray &m_GroupRels;
                };
index e1102af..91fca0c 100644 (file)
@@ -45,7 +45,8 @@ using namespace Utils;
 using namespace Ux;
 
 GroupsView::GroupsView()
-       : m_Genlist(nullptr), m_CreateItem(nullptr), m_GroupsItem(nullptr),
+       : m_Genlist(nullptr), m_GroupsItem(nullptr),
+         m_NotAssignedItem(nullptr), m_CreateItem(nullptr),
          m_IsAssignMode(false), m_NewGroupId(0)
 {
        auto strings = getSelectViewStrings();
@@ -59,6 +60,8 @@ GroupsView::GroupsView()
 void GroupsView::setAssignMode(bool isEnabled)
 {
        m_IsAssignMode = isEnabled;
+       updateSelectAllItem();
+       updateNotAssignedItem();
        updateCreateItem();
 }
 
@@ -84,6 +87,7 @@ Evas_Object *GroupsView::onCreate(Evas_Object *parent)
                }
        });
 
+       updateNotAssignedItem();
        updateCreateItem();
        return m_Genlist->getEvasObject();
 }
@@ -131,7 +135,59 @@ void GroupsView::onMenuPressed()
 
 void GroupsView::onSelectAllInsert(GenItem *item)
 {
-       m_Genlist->insert(item, nullptr, nullptr, Genlist::After);
+       m_SelectAllItem = item->getWeakPtr();
+       updateSelectAllItem();
+}
+
+void GroupsView::onSelectModeChanged(SelectMode selectMode)
+{
+       updateNotAssignedItem();
+}
+
+void GroupsView::onSelectCountChanged(size_t selectCount)
+{
+       if (m_NotAssignedItem) {
+               m_NotAssignedItem->setChecked(selectCount == 0);
+       }
+}
+
+void GroupsView::updateSelectAllItem()
+{
+       Ui::GenItem *item = m_SelectAllItem.lock().get();
+       if (!item) {
+               return;
+       }
+       if (m_IsAssignMode == !item->isInserted()) {
+               return;
+       }
+
+       if (m_IsAssignMode) {
+               item->pop();
+       } else {
+               m_Genlist->insert(item, nullptr, nullptr, Genlist::After);
+       }
+}
+
+void GroupsView::updateNotAssignedItem()
+{
+       if (!m_Genlist) {
+               return;
+       }
+
+       bool shouldExist = m_IsAssignMode && (getSelectMode() == SelectMulti);
+       if (shouldExist == (m_NotAssignedItem != nullptr)) {
+               return;
+       }
+
+       if (shouldExist) {
+               m_NotAssignedItem = new Ux::SelectAllItem("IDS_PB_BODY_NOT_ASSIGNED");
+               m_NotAssignedItem->setChecked(getSelectCount() == 0);
+               m_NotAssignedItem->setCheckCallback(std::bind(&GroupsView::onNotAssignedChecked, this, _1));
+               m_Genlist->insert(m_NotAssignedItem, nullptr, nullptr, Genlist::After);
+       } else {
+               delete m_NotAssignedItem;
+               m_NotAssignedItem = nullptr;
+       }
 }
 
 void GroupsView::updateCreateItem()
@@ -139,22 +195,37 @@ void GroupsView::updateCreateItem()
        if (!m_Genlist) {
                return;
        }
+       if (m_IsAssignMode == (m_CreateItem != nullptr)) {
+               return;
+       }
 
        if (m_IsAssignMode) {
-               if (!m_CreateItem) {
-                       m_CreateItem = new CreateGroupItem();
-                       m_CreateItem->setResultCallback([this](int groupId) {
-                               m_NewGroupId = groupId;
-                       });
-                       m_Genlist->insert(m_CreateItem);
-                       elm_genlist_item_select_mode_set(m_CreateItem->getObjectItem(), ELM_OBJECT_SELECT_MODE_NONE);
-               }
+               m_CreateItem = new CreateGroupItem();
+               m_CreateItem->setResultCallback([this](int groupId) {
+                       m_NewGroupId = groupId;
+               });
+               m_Genlist->insert(m_CreateItem);
+               elm_genlist_item_select_mode_set(m_CreateItem->getObjectItem(), ELM_OBJECT_SELECT_MODE_NONE);
        } else {
-               if (m_CreateItem) {
-                       delete m_CreateItem;
-                       m_CreateItem = nullptr;
-               }
+               delete m_CreateItem;
+               m_CreateItem = nullptr;
+       }
+}
+
+bool GroupsView::onNotAssignedChecked(bool isChecked)
+{
+       if (isChecked == (getSelectCount() == 0)) {
+               return true;
+       }
+
+       if (!isChecked) {
+               return false;
+       }
+
+       for (auto &&item : getSelectItems()) {
+               item->setChecked(false);
        }
+       return true;
 }
 
 void GroupsView::onInserted(::Model2::DataItem &data)
index 9479100..09f88d4 100644 (file)
@@ -93,6 +93,32 @@ void ContactGroupsFieldItem::onInserted()
 
 void ContactGroupsFieldItem::onSelected()
 {
+       pickGroups();
+}
+
+void ContactGroupsFieldItem::onFocused()
+{
+       pickGroups();
+}
+
+std::string ContactGroupsFieldItem::formatGroups() const
+{
+       std::string groups;
+       for (auto &&field : m_GroupRels) {
+               const char *name = getRecordStr(field.getRecord(), _contacts_group_relation.name);
+               GroupType type = getGroupType(name);
+               const char *groupName = (type == GroupCustom) ? name : _(getDefaultGroupName(type));
+               if (!groups.empty()) {
+                       groups.append(", ");
+               }
+               groups.append(groupName);
+       }
+
+       return groups;
+}
+
+void ContactGroupsFieldItem::pickGroups()
+{
        Ui::Navigator *navigator = getParent()->findParent<Ui::Navigator>();
        if (!navigator) {
                return;
@@ -101,6 +127,7 @@ void ContactGroupsFieldItem::onSelected()
        auto view = new GroupsView();
        view->setAssignMode(true);
        view->setSelectMode(Ux::SelectMulti);
+       view->setEmptyResultAllowed(true);
        view->setSelectCallback(std::bind(&ContactGroupsFieldItem::onGroupsSelected, this, _1));
        navigator->navigateTo(view);
 
@@ -147,19 +174,3 @@ bool ContactGroupsFieldItem::onGroupsSelected(Ux::SelectResults results)
        update();
        return true;
 }
-
-std::string ContactGroupsFieldItem::formatGroups() const
-{
-       std::string groups;
-       for (auto &&field : m_GroupRels) {
-               const char *name = getRecordStr(field.getRecord(), _contacts_group_relation.name);
-               GroupType type = getGroupType(name);
-               const char *groupName = (type == GroupCustom) ? name : _(getDefaultGroupName(type));
-               if (!groups.empty()) {
-                       groups.append(", ");
-               }
-               groups.append(groupName);
-       }
-
-       return groups;
-}