TizenRefApp-6910 Integrate Contacts-Groups navigator into Chooser 87/83987/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Tue, 16 Aug 2016 06:51:19 +0000 (09:51 +0300)
committerAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Wed, 17 Aug 2016 06:50:32 +0000 (23:50 -0700)
Change-Id: Ia94b58a3dd7d72408188dbbbf024eb93556e15ba
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
contacts-app/src/OperationPickController.cpp
lib-contacts/inc/Contacts/Chooser/ChooserView.h [moved from lib-contacts/inc/Contacts/Common/Chooser.h with 86% similarity]
lib-contacts/src/Contacts/Chooser/ChooserView.cpp [moved from lib-contacts/src/Contacts/Common/Chooser.cpp with 72% similarity]

index fff4c25..4951c64 100644 (file)
@@ -18,7 +18,7 @@
 #include "OperationPickController.h"
 
 #include "MainApp.h"
-#include "Contacts/Common/Chooser.h"
+#include "Contacts/Chooser/ChooserView.h"
 
 #include "App/AppControlRequest.h"
 #include "Ui/Navigator.h"
@@ -29,7 +29,7 @@
 
 using namespace Common;
 using namespace Contacts;
-using namespace Contacts::Common;
+using namespace Contacts::Chooser;
 using namespace Ux;
 using namespace std::placeholders;
 
@@ -45,7 +45,7 @@ void OperationPickController::onRequest(Operation operation, app_control_h reque
        m_ResultType = getResultType(request);
 
        int limit = App::getIntExtraData(request, APP_CONTROL_DATA_TOTAL_COUNT);
-       Chooser *chooser = new Chooser(m_SelectMode, m_ResultType, limit);
+       ChooserView *chooser = new ChooserView(m_SelectMode, m_ResultType, limit);
        chooser->setSelectCallback(std::bind(&OperationPickController::onSelected, this, _1));
        getNavigator()->navigateTo(chooser);
 }
similarity index 86%
rename from lib-contacts/inc/Contacts/Common/Chooser.h
rename to lib-contacts/inc/Contacts/Chooser/ChooserView.h
index 1db80ed..24922cc 100644 (file)
@@ -15,8 +15,8 @@
  *
  */
 
-#ifndef CONTACTS_COMMON_CHOOSER_H
-#define CONTACTS_COMMON_CHOOSER_H
+#ifndef CONTACTS_CHOOSER_CHOOSER_VIEW_H
+#define CONTACTS_CHOOSER_CHOOSER_VIEW_H
 
 #include "Contacts/Common/ContactSelectTypes.h"
 #include "Ui/Naviframe.h"
@@ -29,13 +29,15 @@ namespace Ux
 
 namespace Contacts
 {
-       namespace Common
+       namespace Chooser
        {
+               class ContactsGroupsNavigator;
+
                /**
                 * @brief Controller and navigator for selecting different types of results
                 *        via ListView and DetailsView.
                 */
-               class EXPORT_API Chooser : public Ui::Naviframe
+               class EXPORT_API ChooserView : public Ui::Naviframe
                {
                public:
                        /**
@@ -44,7 +46,7 @@ namespace Contacts
                         * @param[in]   resultType  Requested result type
                         * @param[in]   selectLimit Selection limit for #SelectMulti mode
                         */
-                       Chooser(Ux::SelectMode selectMode, ResultType resultType, size_t selectLimit);
+                       ChooserView(Ux::SelectMode selectMode, ResultType resultType, size_t selectLimit);
 
                        /**
                         * @brief Set selection callback
@@ -78,8 +80,9 @@ namespace Contacts
 
                        Ux::SelectCallback m_OnSelected;
                        Ux::SelectView *m_ListView;
+                       ContactsGroupsNavigator *m_ContactsGroups;
                };
        }
 }
 
-#endif /* CONTACTS_COMMON_CHOOSER_H */
+#endif /* CONTACTS_CHOOSER_CHOOSER_VIEW_H */
  *
  */
 
-#include "Contacts/Common/Chooser.h"
+#include "Contacts/Chooser/ChooserView.h"
+#include "Contacts/Chooser/ContactsGroupsNavigator.h"
+
 #include "Contacts/Details/DetailsView.h"
+#include "Contacts/Groups/GroupsView.h"
 #include "Contacts/List/ListView.h"
 #include "Contacts/Settings/ExportController.h"
+
 #include "Common/Actions.h"
 #include "Common/Database/Queries.h"
 
@@ -31,61 +35,73 @@ using namespace Common;
 using namespace Common::Database;
 
 using namespace Contacts;
-using namespace Contacts::Common;
+using namespace Contacts::Chooser;
 using namespace Contacts::List;
 using namespace Contacts::Details;
 using namespace Ux;
 using namespace std::placeholders;
 
-Chooser::Chooser(SelectMode selectMode, ResultType resultType, size_t selectLimit)
+ChooserView::ChooserView(SelectMode selectMode, ResultType resultType, size_t selectLimit)
        : m_SelectMode(selectMode), m_ResultType(resultType),
-         m_FilterType(getFilterType(m_ResultType)), m_SelectLimit(selectLimit)
+         m_FilterType(getFilterType(m_ResultType)), m_SelectLimit(selectLimit),
+         m_ListView(nullptr), m_ContactsGroups(nullptr)
 {
 }
 
-void Chooser::setSelectCallback(SelectCallback callback)
+void ChooserView::setSelectCallback(SelectCallback callback)
 {
        m_OnSelected = std::move(callback);
 }
 
-void Chooser::onCreated()
+void ChooserView::onCreated()
 {
        m_ListView = new ListView(m_FilterType);
        m_ListView->setSelectMode(m_SelectMode);
        m_ListView->setSelectLimit(m_SelectLimit);
+       m_ListView->setCancelCallback([this] {
+               getPage()->close();
+               return false;
+       });
 
        switch (m_ResultType) {
                case ResultPerson:
-                       m_ListView->setSelectCallback(std::bind(&Chooser::onSelected, this, _1));
+                       m_ListView->setSelectCallback(std::bind(&ChooserView::onSelected, this, _1));
                        break;
                case ResultNumber:
                case ResultEmail:
                        if (m_SelectMode == SelectSingle) {
-                               m_ListView->setSelectCallback(std::bind(&Chooser::onSinglePersonSelected, this, _1));
+                               m_ListView->setSelectCallback(std::bind(&ChooserView::onSinglePersonSelected, this, _1));
                        } else {
-                               m_ListView->setCheckCallback(std::bind(&Chooser::onPersonChecked, this, _1, _2, _3));
-                               m_ListView->setSelectCallback(std::bind(&Chooser::onSelected, this, _1));
+                               m_ListView->setCheckCallback(std::bind(&ChooserView::onPersonChecked, this, _1, _2, _3));
+                               m_ListView->setSelectCallback(std::bind(&ChooserView::onSelected, this, _1));
                        }
                        break;
                case ResultVcard:
-                       m_ListView->setSelectCallback(std::bind(&Chooser::onSelectedForVcard, this, _1));
+                       m_ListView->setSelectCallback(std::bind(&ChooserView::onSelectedForVcard, this, _1));
                        break;
                case ResultAction:
-                       m_ListView->setSelectCallback(std::bind(&Chooser::onSelectedForAction, this, _1));
+                       m_ListView->setSelectCallback(std::bind(&ChooserView::onSelectedForAction, this, _1));
                        break;
                default:
                        break;
        }
-
-       navigateTo(m_ListView);
 }
 
-void Chooser::onPageAttached(Ui::NavigatorPage *page)
+void ChooserView::onPageAttached(Ui::NavigatorPage *page)
 {
-       page->setTitleVisibility(false);
+       if (m_SelectMode == SelectSingle) {
+               page->setTitleVisibility(false);
+               navigateTo(m_ListView);
+       } else {
+               m_ContactsGroups = new ContactsGroupsNavigator();
+               navigateTo(m_ContactsGroups);
+
+               m_ContactsGroups->addContactsView(m_ListView);
+               m_ContactsGroups->addGroupsView(new Groups::GroupsView());
+       }
 }
 
-bool Chooser::onPersonChecked(SelectItem *item, bool isChecked, bool isSelectAll)
+bool ChooserView::onPersonChecked(SelectItem *item, bool isChecked, bool isSelectAll)
 {
        if (isChecked) {
                if (item->hasCustomResult()) {
@@ -99,26 +115,38 @@ bool Chooser::onPersonChecked(SelectItem *item, bool isChecked, bool isSelectAll
                                        : CONTACTS_PERSON_PROPERTY_EMAIL;
                        contacts_person_get_default_property(property, item->getSelectResult().value.id, &id);
                        item->setCustomResult({ m_ResultType, id });
+
+                       if (m_ContactsGroups) {
+                               m_ContactsGroups->addSelectedItem(item);
+                       }
                        return true;
                }
 
-               return selectSingleResult(item->getSelectResult(), [item](SelectResults results) {
+               return selectSingleResult(item->getSelectResult(), [this, item](SelectResults results) {
                        item->setCustomResult(results.front());
                        item->setChecked(true);
+
+                       if (m_ContactsGroups) {
+                               m_ContactsGroups->addSelectedItem(item);
+                       }
                        return true;
                });
        }
 
        item->unsetCustomResult();
+       if (m_ContactsGroups) {
+               m_ContactsGroups->removeSelectedItem(item);
+       }
+
        return true;
 }
 
-bool Chooser::onSinglePersonSelected(SelectResults results)
+bool ChooserView::onSinglePersonSelected(SelectResults results)
 {
-       return selectSingleResult(results.front(), std::bind(&Chooser::onSelected, this, _1));
+       return selectSingleResult(results.front(), std::bind(&ChooserView::onSelected, this, _1));
 }
 
-bool Chooser::onSelectedForAction(SelectResults results)
+bool ChooserView::onSelectedForAction(SelectResults results)
 {
        selectSingleResult(results.front(), [this](SelectResults results) {
                SelectResult result = results.front();
@@ -143,7 +171,7 @@ bool Chooser::onSelectedForAction(SelectResults results)
        return false;
 }
 
-bool Chooser::onSelectedForVcard(SelectResults results)
+bool ChooserView::onSelectedForVcard(SelectResults results)
 {
        using namespace Settings;
 
@@ -164,7 +192,7 @@ bool Chooser::onSelectedForVcard(SelectResults results)
        return false;
 }
 
-bool Chooser::onSelected(SelectResults results)
+bool ChooserView::onSelected(SelectResults results)
 {
        if (!m_OnSelected || m_OnSelected(std::move(results))) {
                getPage()->close();
@@ -173,7 +201,7 @@ bool Chooser::onSelected(SelectResults results)
        return false;
 }
 
-bool Chooser::selectSingleResult(SelectResult person, SelectCallback callback)
+bool ChooserView::selectSingleResult(SelectResult person, SelectCallback callback)
 {
        SelectResult result = getSingleResult(person.value.id);
        if (result.value.id > 0) {
@@ -187,12 +215,12 @@ bool Chooser::selectSingleResult(SelectResult person, SelectCallback callback)
                        DetailsView::Type(person.type), m_FilterType);
        view->setSelectMode(SelectSingle);
        view->setSelectCallback(callback);
-       navigateTo(view);
+       getNavigator()->navigateTo(view);
 
        return false;
 }
 
-SelectResult Chooser::getSingleResult(int personId)
+SelectResult ChooserView::getSingleResult(int personId)
 {
        int count = 0;
 
@@ -218,7 +246,7 @@ SelectResult Chooser::getSingleResult(int personId)
        return result;
 }
 
-int Chooser::getResultCount(int personId, ResultType resultType, int *resultId)
+int ChooserView::getResultCount(int personId, ResultType resultType, int *resultId)
 {
        const char *uri = nullptr;
        unsigned personIdProp = 0;
@@ -269,7 +297,7 @@ int Chooser::getResultCount(int personId, ResultType resultType, int *resultId)
        return count;
 }
 
-std::string Chooser::getResultValue(SelectResult result)
+std::string ChooserView::getResultValue(SelectResult result)
 {
        std::string value;
 
@@ -303,7 +331,7 @@ std::string Chooser::getResultValue(SelectResult result)
        return value;
 }
 
-int Chooser::getFilterType(ResultType resultType)
+int ChooserView::getFilterType(ResultType resultType)
 {
        switch (resultType) {
                case ResultNumber: