Implemented update of Mfc section after reset of person's usage statistic 30/73830/7
authorAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Thu, 9 Jun 2016 14:17:22 +0000 (17:17 +0300)
committerAndrey Klimenko <and.klimenko@samsung.com>
Fri, 10 Jun 2016 15:11:45 +0000 (08:11 -0700)
Change-Id: Ic0bafee3423660ddeb523e2c71b6c719e3b5ebcc
Signed-off-by: Aleksandr Sapozhnik <a.sapozhnik@samsung.com>
lib-contacts/inc/Contacts/List/ListSection.h
lib-contacts/inc/Contacts/List/ManageFavoritesPopup.h
lib-contacts/src/Contacts/List/ListSection.cpp
lib-contacts/src/Contacts/List/ListView.cpp
lib-contacts/src/Contacts/List/ManageFavoritesPopup.cpp

index 2717e7a..a9a3582 100644 (file)
@@ -69,6 +69,11 @@ namespace Contacts
                         */
                        void setUpdateCallback(UpdateCallback callback);
 
+                       /**
+                        * @brief Update section content manually
+                        */
+                       void update();
+
                protected:
                        void onInserted(::Model::DataItem &person);
                        ContactItem *createItem(Model::Person &person);
index 82c6648..8199d6a 100644 (file)
@@ -37,11 +37,22 @@ namespace Contacts
                {
                public:
                        /**
+                        * @brief Notifies that Mfc contacts were updated
+                        */
+                       typedef std::function<void()> MfcUpdateCallback;
+
+                       /**
                         * @brief Creates new popup
                         * @param[in]   navigator   Current navigator. Is needed to move to the next view.
                         */
                        ManageFavoritesPopup(Ui::Navigator *navigator);
 
+                       /**
+                        * @brief Set Mfc update callback
+                        * @param[in]   callback    Mfc update callback
+                        */
+                       void setMfcUpdateCallback(MfcUpdateCallback callback);
+
                protected:
                        /**
                         * @see Control::onCreated()
@@ -57,6 +68,7 @@ namespace Contacts
                        void onRemove();
 
                        Ui::Navigator *m_Navigator;
+                       MfcUpdateCallback m_OnMfcUpdated;
                };
        }
 }
index 529a802..ab62a6c 100644 (file)
@@ -20,7 +20,6 @@
 #include "Contacts/List/ReorderItem.h"
 #include "Contacts/List/Model/Person.h"
 #include "Contacts/List/Model/PersonProvider.h"
-#include "Utils/Logger.h"
 
 #include <app_i18n.h>
 
@@ -47,6 +46,11 @@ void ListSection::setUpdateCallback(UpdateCallback callback)
        m_OnUpdated = std::move(callback);
 }
 
+void ListSection::update()
+{
+       m_Provider->reload();
+}
+
 char *ListSection::getText(Evas_Object *parent, const char *part)
 {
        if (strcmp(part, "elm.text") == 0) {
index 5a61c6c..73fb3cb 100644 (file)
@@ -150,6 +150,15 @@ void ListView::onMenuPressed()
                menu->addItem("IDS_PB_OPT_SHARE", std::bind(&ListView::onShareSelected, this));
                menu->addItem("IDS_PB_OPT_MANAGE_FAVOURITES_ABB", [this] {
                        auto manageFavPopup = new ManageFavoritesPopup(getNavigator());
+                       manageFavPopup->setMfcUpdateCallback([this] {
+
+                               if (m_Sections[SectionMfc]) {
+                                       static_cast<ListSection *>(m_Sections[SectionMfc])->update();
+                               } else {
+                                       createSection(SectionMfc);
+                               }
+                       });
+
                        manageFavPopup->create(getEvasObject());
                });
        }
index fe4868c..e152f29 100644 (file)
@@ -33,6 +33,11 @@ ManageFavoritesPopup::ManageFavoritesPopup(Navigator *navigator)
 {
 }
 
+void ManageFavoritesPopup::setMfcUpdateCallback(MfcUpdateCallback callback)
+{
+       m_OnMfcUpdated = std::move(callback);
+}
+
 void ManageFavoritesPopup::onCreated()
 {
        ListPopup::onCreated();
@@ -87,8 +92,12 @@ void ManageFavoritesPopup::onRemove()
        //todo Should be created ListView with Favorites and MFC sections only
        ListView *view = new ListView();
        view->setSelectMode(Ux::SelectMulti);
-       view->setSelectCallback([](Ux::SelectResults results) {
 
+       //todo Implement separate controller to handle callback, because object is destroyed after popup close.
+       auto &onMfcUpdated = m_OnMfcUpdated;
+       view->setSelectCallback([onMfcUpdated](Ux::SelectResults results) {
+
+               bool isMfcUpdated = false;
                contacts_list_h list = nullptr;
                contacts_list_create(&list);
                for (auto &&result : results) {
@@ -100,6 +109,7 @@ void ManageFavoritesPopup::onRemove()
                                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);
@@ -109,6 +119,10 @@ void ManageFavoritesPopup::onRemove()
                contacts_db_update_records(list);
                contacts_list_destroy(list, true);
 
+               if (isMfcUpdated && onMfcUpdated) {
+                       onMfcUpdated();
+               }
+
                return true;
        });
        m_Navigator->navigateTo(view);