Fixed TSAM-5163 Includes both Favourite and non-favourite contacts in list when tryin... 12/75812/3
authorAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Tue, 21 Jun 2016 12:53:52 +0000 (15:53 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Wed, 22 Jun 2016 07:33:57 +0000 (00:33 -0700)
Change-Id: I59a17c458d03e13a638888c8181b3511fb054cb3
Signed-off-by: Aleksandr Sapozhnik <a.sapozhnik@samsung.com>
lib-contacts/inc/Contacts/List/RemoveFavView.h [new file with mode: 0644]
lib-contacts/src/Contacts/List/ManageFavoritesPopup.cpp
lib-contacts/src/Contacts/List/RemoveFavView.cpp [new file with mode: 0644]

diff --git a/lib-contacts/inc/Contacts/List/RemoveFavView.h b/lib-contacts/inc/Contacts/List/RemoveFavView.h
new file mode 100644 (file)
index 0000000..c6c03ea
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 CONTACTS_LIST_REMOVE_FAV_VIEW_H
+#define CONTACTS_LIST_REMOVE_FAV_VIEW_H
+
+#include "Common/DataTypes.h"
+#include "Ux/SelectView.h"
+
+namespace Ui
+{
+       class Genlist;
+       class GenlistGroupItem;
+}
+
+namespace Contacts
+{
+       namespace List
+       {
+               class ContactItem;
+
+               /**
+                * @brief The Remove Favorites View
+                */
+               class EXPORT_API RemoveFavView : public Ux::SelectView
+               {
+               public:
+                       /**
+                        * @brief Create the view
+                        */
+                       RemoveFavView();
+
+               private:
+                       enum SectionId
+                       {
+                               SectionFirst,
+                               SectionFavorites = SectionFirst,
+                               SectionMfc,
+                               SectionMax
+                       };
+
+                       virtual Evas_Object *onCreate(Evas_Object *parent) override;
+                       virtual void onDestroy() override;
+
+                       virtual void onSelectAllInsert(Ui::GenlistItem *item) override;
+
+                       Ui::GenlistGroupItem *createListSection(SectionId sectionId);
+                       void createSections();
+                       void insertSection(Ui::GenlistGroupItem *section, SectionId sectionId);
+                       void updateSection(SectionId sectionId);
+                       void updateSections();
+
+                       Ui::GenlistItem *getNextSectionItem(SectionId sectionId);
+
+                       void onSectionUpdated(ContactItem *item, ::Common::ChangeType change, SectionId sectionId);
+
+                       Ui::Genlist *m_Genlist;
+                       Ui::GenlistGroupItem *m_Sections[SectionMax];
+               };
+       }
+}
+
+#endif /* CONTACTS_LIST_REMOVE_FAV_VIEW_H */
index 368cb82..88c4b0d 100644 (file)
@@ -20,6 +20,7 @@
 #include "Contacts/List/ListView.h"
 #include "Contacts/List/ManageFavoritesPopup.h"
 #include "Contacts/List/Model/FavoritesProvider.h"
+#include "Contacts/List/RemoveFavView.h"
 #include "Contacts/List/ReorderView.h"
 
 #include "Ui/Navigator.h"
@@ -83,9 +84,7 @@ void ManageFavoritesPopup::onReorderSelected()
 
 void ManageFavoritesPopup::onRemoveSelected()
 {
-       //todo Should be created ListView with Favorites and MFC sections only
-       ListView *view = new ListView();
-       view->setSelectMode(Ux::SelectMulti);
+       RemoveFavView *view = new RemoveFavView();
 
        //todo Implement separate controller to handle callback, because object is destroyed after popup close.
        auto &onMfcUpdated = m_OnMfcUpdated;
diff --git a/lib-contacts/src/Contacts/List/RemoveFavView.cpp b/lib-contacts/src/Contacts/List/RemoveFavView.cpp
new file mode 100644 (file)
index 0000000..bf371e4
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "Contacts/List/RemoveFavView.h"
+#include "Contacts/List/ListSection.h"
+
+#include "Contacts/List/Model/FavoritesProvider.h"
+#include "Contacts/List/Model/MfcProvider.h"
+#include "Contacts/List/PersonItem.h"
+
+#include "Common/Strings.h"
+
+#include "Ui/Genlist.h"
+#include "Utils/Logger.h"
+
+using namespace Contacts::List;
+using namespace Contacts::List::Model;
+
+using namespace std::placeholders;
+
+RemoveFavView::RemoveFavView()
+       : m_Genlist(nullptr), m_Sections{ nullptr }
+{
+       auto strings = Common::getSelectViewStrings();
+       strings.titleMulti = "IDS_PB_HEADER_SELECT_CONTACT_ABB2";
+       setStrings(strings);
+}
+
+Evas_Object *RemoveFavView::onCreate(Evas_Object *parent)
+{
+       m_Genlist = new Ui::Genlist();
+       m_Genlist->create(parent);
+
+       createSections();
+       setSelectMode(Ux::SelectMulti);
+
+       return m_Genlist->getEvasObject();
+}
+
+void RemoveFavView::onDestroy()
+{
+       for (auto &&section : m_Sections) {
+               if (section && !section->isInserted()) {
+                       delete section;
+               }
+       }
+}
+
+void RemoveFavView::onSelectAllInsert(Ui::GenlistItem *item)
+{
+       m_Genlist->insert(item, nullptr, nullptr, Ui::Genlist::After);
+}
+
+Ui::GenlistGroupItem *RemoveFavView::createListSection(SectionId sectionId)
+{
+       const char *title = nullptr;
+       PersonProvider *provider = nullptr;
+       switch (sectionId) {
+               case SectionFavorites:
+                       title = "IDS_PB_HEADER_FAVOURITES";
+                       provider = new FavoritesProvider(FavoritesProvider::ModeOnly);
+                       break;
+               case SectionMfc:
+                       title = "IDS_PB_HEADER_MOST_FREQUENT_CONTACTS_ABB2";
+                       provider = new MfcProvider();
+                       break;
+               default:
+                       return nullptr;
+       }
+
+       ListSection *section = new ListSection(title, provider);
+       section->setUpdateCallback(std::bind(&RemoveFavView::onSectionUpdated, this, _1, _2, sectionId));
+
+       if (!section->isEmpty()) {
+               insertSection(section, sectionId);
+               for (auto &&item : *section) {
+                       addSelectItem(static_cast<PersonItem *>(item));
+               }
+       }
+
+       return section;
+}
+
+void RemoveFavView::createSections()
+{
+       for (size_t i = SectionFirst; i < SectionMax; ++i) {
+               m_Sections[i] = createListSection(static_cast<SectionId>(i));;
+       }
+}
+
+void RemoveFavView::insertSection(Ui::GenlistGroupItem *section, SectionId sectionId)
+{
+       m_Genlist->insert(section, nullptr, getNextSectionItem(sectionId));
+       elm_genlist_item_select_mode_set(section->getObjectItem(), ELM_OBJECT_SELECT_MODE_NONE);
+}
+
+void RemoveFavView::updateSection(SectionId sectionId)
+{
+       Ui::GenlistGroupItem *section = m_Sections[sectionId];
+
+       if (!section->isEmpty()) {
+               if (!section->isInserted()) {
+                       insertSection(section, sectionId);
+               }
+       } else {
+               if (section->isInserted()) {
+                       section->pop();
+               }
+       }
+}
+
+void RemoveFavView::updateSections()
+{
+       for (size_t i = SectionFirst; i < SectionMax; ++i) {
+               updateSection(static_cast<SectionId>(i));
+       }
+}
+
+Ui::GenlistItem *RemoveFavView::getNextSectionItem(SectionId sectionId)
+{
+       for (unsigned section = sectionId + 1; section < SectionMax; ++section) {
+               if (m_Sections[section] && m_Sections[section]->isInserted()) {
+                       return m_Sections[section];
+               }
+       }
+
+       return nullptr;
+}
+
+void RemoveFavView::onSectionUpdated(ContactItem *item, ::Common::ChangeType change, SectionId sectionId)
+{
+       if (change == Common::ChangeInsert) {
+               addSelectItem(item);
+       } else if (change == Common::ChangeDelete) {
+               removeSelectItem(item);
+       }
+
+       updateSection(sectionId);
+}