Fixed and simplified "Manage Favorites" popup. 58/84258/4
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Wed, 17 Aug 2016 14:19:46 +0000 (17:19 +0300)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Wed, 17 Aug 2016 14:19:46 +0000 (17:19 +0300)
Change-Id: I45048de32e6917300a5283f73847302e5e2cf5c2
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-contacts/inc/Contacts/List/ListView.h
lib-contacts/inc/Contacts/List/ManageFavoritesPopup.h
lib-contacts/src/Contacts/List/ListView.cpp
lib-contacts/src/Contacts/List/ManageFavoritesPopup.cpp

index 2bae303..40dd00a 100644 (file)
@@ -130,7 +130,6 @@ namespace Contacts
                        void onDeleteSelected();
                        void onShareSelected();
                        bool onSelectFinished();
-                       void onManageFavoritesSelected();
 
                        virtual void onSelectAllInsert(Ui::GenItem *item) override;
                        virtual void onSelectModeChanged(Ux::SelectMode selectMode) override;
index ca4d1cb..b2cd8fd 100644 (file)
@@ -19,6 +19,7 @@
 #define CONTACTS_LIST_MANAGE_FAVORITES_POPUP_H
 
 #include "Ui/ListPopup.h"
+#include "Ux/SelectTypes.h"
 
 namespace Ui
 {
@@ -29,42 +30,23 @@ namespace Contacts
 {
        namespace List
        {
+               class ListSection;
+
                /**
-                * @brief The popup provides ability to add/reorder favorites and
-                * remove most frequent and favorites contacts
+                * @brief The popup provides ability to add/remove/reorder favorites and
+                *        most frequent contacts.
                 */
                class ManageFavoritesPopup : public Ui::ListPopup
                {
                public:
                        /**
-                        * @brief Notifies that Mfc contacts were updated
-                        */
-                       typedef std::function<void()> MfcUpdateCallback;
-
-                       /**
-                        * @brief Notifies that Favorites contact was reordered
-                        * @param[in]   Id of the favorite contact that was reordered
-                        * @param[in]   Id of the previous contact
-                        */
-                       typedef std::function<void(int, int)> ReorderCallback;
-
-                       /**
-                        * @brief Creates new popup
+                        * @brief Creates popup.
                         * @param[in]   navigator   Current navigator. Is needed to move to the next view.
+                        * @param[in]   favSection  Favorites list section
+                        * @param[in]   mfcSection  Most frequent contacts list section
                         */
-                       ManageFavoritesPopup(Ui::Navigator *navigator);
-
-                       /**
-                        * @brief Set Mfc update callback
-                        * @param[in]   callback    Mfc update callback
-                        */
-                       void setMfcUpdateCallback(MfcUpdateCallback callback);
-
-                       /**
-                        * @brief Set favorites reorder callback
-                        * @param[in]   callback    Favorites reorder callback
-                        */
-                       void setReorderCallback(ReorderCallback callback);
+                       ManageFavoritesPopup(Ui::Navigator *navigator,
+                                       ListSection *favSection, ListSection *mfcSection);
 
                protected:
                        /**
@@ -73,19 +55,16 @@ namespace Contacts
                        virtual void onCreated() override;
 
                private:
-                       ManageFavoritesPopup(const ManageFavoritesPopup &that) = delete;
-                       ManageFavoritesPopup & operator=(const ManageFavoritesPopup &that) = delete;
-
                        void onAddSelected();
                        void onReorderSelected();
                        void onRemoveSelected();
 
                        static void addFavorites(Ux::SelectResults results);
-                       static void removeFavorites(Ux::SelectResults results, MfcUpdateCallback callback);
+                       static void removeFavorites(Ux::SelectResults results);
 
                        Ui::Navigator *m_Navigator;
-                       MfcUpdateCallback m_OnMfcUpdated;
-                       ReorderCallback m_OnFavoritesReordered;
+                       ListSection *m_FavSection;
+                       ListSection *m_MfcSection;
                };
        }
 }
index e815455..377040e 100644 (file)
@@ -197,8 +197,12 @@ void ListView::onMenuPressed()
                menu->addItem("IDS_PB_OPT_SHARE", std::bind(&ListView::onShareSelected, this));
 
                if (!m_IsSearching) {
-                       menu->addItem("IDS_PB_OPT_MANAGE_FAVOURITES_ABB",
-                                       std::bind(&ListView::onManageFavoritesSelected, this));
+                       menu->addItem("IDS_PB_OPT_MANAGE_FAVOURITES_ABB", [this] {
+                               auto popup = new ManageFavoritesPopup(getNavigator(),
+                                               static_cast<ListSection *>(m_Sections[SectionFavorites].m_Item),
+                                               static_cast<ListSection *>(m_Sections[SectionMfc].m_Item));
+                               popup->create(getEvasObject());
+                       });
                }
        }
 
@@ -279,22 +283,6 @@ bool ListView::onSelectFinished()
        return false;
 }
 
-void ListView::onManageFavoritesSelected()
-{
-       auto manageFavPopup = new ManageFavoritesPopup(getNavigator());
-
-       manageFavPopup->setMfcUpdateCallback([this] {
-               if (m_Sections[SectionMfc].m_Item) {
-                       static_cast<ListSection *>(m_Sections[SectionMfc].m_Item)->update();
-               } else {
-                       createSection(SectionMfc);
-               }
-       });
-       manageFavPopup->setReorderCallback( std::bind(&ListSection::reorderItem,
-                       static_cast<ListSection *>(m_Sections[SectionFavorites].m_Item), _1, _2));
-       manageFavPopup->create(getEvasObject());
-}
-
 void ListView::onSelectAllInsert(Ui::GenItem *item)
 {
        m_Genlist->insert(item, nullptr, m_SearchItem, Ui::Genlist::After);
index bccfe48..3427b05 100644 (file)
  *
  */
 
-#include "Common/Database/RecordIterator.h"
-#include "Common/Database/RecordUtils.h"
-#include "Contacts/List/ListView.h"
 #include "Contacts/List/ManageFavoritesPopup.h"
+#include "Contacts/List/ListSection.h"
+#include "Contacts/List/ListView.h"
 #include "Contacts/List/Model/FavoritesProvider.h"
 #include "Contacts/List/RemoveFavView.h"
 #include "Contacts/List/ReorderView.h"
 
+#include "Common/Database/RecordIterator.h"
+#include "Common/Database/RecordUtils.h"
+
 #include "Ui/Navigator.h"
 #include "Ui/ProcessPopup.h"
 #include "Utils/Thread.h"
 using namespace Common::Database;
 using namespace Contacts::List;
 using namespace Contacts::List::Model;
+using namespace std::placeholders;
 
-ManageFavoritesPopup::ManageFavoritesPopup(Ui::Navigator *navigator)
-       : m_Navigator(navigator)
+ManageFavoritesPopup::ManageFavoritesPopup(Ui::Navigator *navigator,
+               ListSection *favSection, ListSection *mfcSection)
+       : m_Navigator(navigator), m_FavSection(favSection), m_MfcSection(mfcSection)
 {
 }
 
-void ManageFavoritesPopup::setMfcUpdateCallback(MfcUpdateCallback callback)
-{
-       m_OnMfcUpdated = std::move(callback);
-}
-
-void ManageFavoritesPopup::setReorderCallback(ReorderCallback callback)
-{
-       m_OnFavoritesReordered = std::move(callback);
-}
-
 void ManageFavoritesPopup::onCreated()
 {
        ListPopup::onCreated();
-
        setTitle("IDS_PB_HEADER_MANAGE_FAVOURITES_ABB");
-
-       // todo Implement get list's size without retrieve of all fav persons from database
-       FavoritesProvider provider;
-       int count = provider.getDataList().size();
-
        addItem("IDS_PB_OPT_ADD", std::bind(&ManageFavoritesPopup::onAddSelected, this));
 
-       if (count > 0) {
+       size_t favCount = m_FavSection->getItemCount();
+       size_t mfcCount = m_MfcSection->getItemCount();
+       if (favCount > 0 || mfcCount > 0) {
                addItem("IDS_PB_OPT_REMOVE", std::bind(&ManageFavoritesPopup::onRemoveSelected, this));
+       }
 
-               if (count > 1) {
-                       addItem("IDS_PB_OPT_REORDER", std::bind(&ManageFavoritesPopup::onReorderSelected, this));
-               }
+       if (favCount > 1) {
+               addItem("IDS_PB_OPT_REORDER", std::bind(&ManageFavoritesPopup::onReorderSelected, this));
        }
 }
 
@@ -86,19 +76,18 @@ void ManageFavoritesPopup::onAddSelected()
 void ManageFavoritesPopup::onReorderSelected()
 {
        ReorderView *view = new ReorderView();
-       view->setItemReorderCallback(std::move(m_OnFavoritesReordered));
+       view->setItemReorderCallback(std::bind(&ListSection::reorderItem, m_FavSection, _1, _2));
        m_Navigator->navigateTo(view);
 }
 
 void ManageFavoritesPopup::onRemoveSelected()
 {
        RemoveFavView *view = new RemoveFavView();
-
-       //todo Implement separate controller to handle callback, because object is destroyed after popup close.
-       auto &onMfcUpdated = m_OnMfcUpdated;
-       view->setSelectCallback([view, onMfcUpdated](Ux::SelectResults results) {
+       ListSection *mfcSection = m_MfcSection;
+       view->setSelectCallback([view, mfcSection](Ux::SelectResults results) {
                auto popup = Ui::ProcessPopup::create(view->getEvasObject(), "IDS_PB_TPOP_PROCESSING_ING");
-               new Utils::Thread(std::bind(removeFavorites, std::move(results), std::move(onMfcUpdated)), [view, popup] {
+               new Utils::Thread(std::bind(removeFavorites, std::move(results)), [view, popup, mfcSection] {
+                       mfcSection->update();
                        popup->close();
                        view->getPage()->close();
                });
@@ -125,9 +114,8 @@ void ManageFavoritesPopup::addFavorites(Ux::SelectResults results)
        contacts_disconnect_on_thread();
 }
 
-void ManageFavoritesPopup::removeFavorites(Ux::SelectResults results, MfcUpdateCallback callback)
+void ManageFavoritesPopup::removeFavorites(Ux::SelectResults results)
 {
-       bool isMfcUpdated = false;
        contacts_list_h list = nullptr;
        contacts_connect_on_thread();
        contacts_list_create(&list);
@@ -141,7 +129,6 @@ void ManageFavoritesPopup::removeFavorites(Ux::SelectResults results, MfcUpdateC
                        contacts_record_set_bool(record, _contacts_person.is_favorite, false);
                        contacts_list_add(list, record);
                } else {
-                       isMfcUpdated = true;
                        contacts_person_reset_usage(recordId, CONTACTS_USAGE_STAT_TYPE_OUTGOING_CALL);
                        contacts_person_reset_usage(recordId, CONTACTS_USAGE_STAT_TYPE_INCOMING_CALL);
                        contacts_record_destroy(record, true);
@@ -151,8 +138,4 @@ void ManageFavoritesPopup::removeFavorites(Ux::SelectResults results, MfcUpdateC
        contacts_db_update_records(list);
        contacts_list_destroy(list, true);
        contacts_disconnect_on_thread();
-
-       if (isMfcUpdated && callback) {
-               callback();
-       }
 }