From 8a9e512f87372dc4217369c16d3c95aca1940a52 Mon Sep 17 00:00:00 2001 From: Sergei Kobec Date: Fri, 29 Jan 2016 14:36:30 +0200 Subject: [PATCH] TizenRefApp-5538 Implement results return from contact list in the multi-pick mode Change-Id: Ifb910824d541e492978338f10ba2841e79ce5084 Signed-off-by: Sergei Kobec --- lib-contact/inc/Contacts/List/ListView.h | 32 +++++++++ .../inc/Contacts/List/Model/PersonProvider.h | 4 +- lib-contact/src/Contacts/List/ListView.cpp | 82 +++++++++++++++++++++- .../src/Contacts/List/Model/PersonProvider.cpp | 5 ++ 4 files changed, 118 insertions(+), 5 deletions(-) diff --git a/lib-contact/inc/Contacts/List/ListView.h b/lib-contact/inc/Contacts/List/ListView.h index f5ad95a..6b63895 100644 --- a/lib-contact/inc/Contacts/List/ListView.h +++ b/lib-contact/inc/Contacts/List/ListView.h @@ -56,6 +56,17 @@ namespace Contacts }; /** + * @brief Person ID list + */ + typedef std::vector PersonIds; + + /** + * @brief Callback, that invokes when all results are prepared + * @details Invokes on view close + */ + typedef std::function ResultCallback; + + /** * @brief Create new person list view * @param]in] personFilter Defines how to filter person list */ @@ -70,6 +81,18 @@ namespace Contacts */ void setMode(Mode mode); + /** + * @brief Set view result callback + * @remark Used in Singlepick/Multipick view modes + * @param[in] callback Done pressed callback + */ + void setResultCallback(ResultCallback callback); + + /** + * @brief Unset view result callback + */ + void unsetResultCallback(); + private: enum SectionId { @@ -110,6 +133,8 @@ namespace Contacts void createNewContactButton(); void deleteNewContactButton(); + void createCancelButton(); + void createDoneButton(); void insertMyProfileGroupItem(); void updateMyProfileItem(const char *view_uri); @@ -129,12 +154,15 @@ namespace Contacts void deletePersonItem(PersonItem *item); PersonItem *getNextPersonItem(PersonGroupItem *group, const Model::Person &person); + PersonIds getCheckedPersonIds(); + void launchPersonDetail(PersonItem *item); void onIndexChanged(Evas_Object *index, Elm_Object_Item *indexItem); void onIndexSelected(Evas_Object *index, Elm_Object_Item *indexItem); void onCreatePressed(); + void onDonePressed(Evas_Object *button, void *eventInfo); void onPersonInserted(Model::PersonPtr person); void onPersonChanged(Model::PersonPtr person, contacts_changed_e changeType, PersonItem *item); @@ -143,6 +171,8 @@ namespace Contacts Ui::Genlist *m_Genlist; Evas_Object *m_Index; + Evas_Object *m_CancelButton; + Evas_Object *m_DoneButton; Ui::GenlistGroupItem *m_Sections[SectionMax]; std::map m_PersonGroups; @@ -153,6 +183,8 @@ namespace Contacts size_t m_PersonCount; size_t m_CheckedCount; + + ResultCallback m_OnResult; }; } } diff --git a/lib-contact/inc/Contacts/List/Model/PersonProvider.h b/lib-contact/inc/Contacts/List/Model/PersonProvider.h index 8cbc38a..0297221 100644 --- a/lib-contact/inc/Contacts/List/Model/PersonProvider.h +++ b/lib-contact/inc/Contacts/List/Model/PersonProvider.h @@ -65,13 +65,13 @@ namespace Contacts */ explicit PersonProvider(FilterType filterType); - virtual ~PersonProvider() { }; + ~PersonProvider(); /** * @brief Get person list * @return List of contact objects */ - virtual PersonList getPersonList() const; + PersonList getPersonList() const; /** * @brief Set person change callback diff --git a/lib-contact/src/Contacts/List/ListView.cpp b/lib-contact/src/Contacts/List/ListView.cpp index d257dc4..8b009c5 100644 --- a/lib-contact/src/Contacts/List/ListView.cpp +++ b/lib-contact/src/Contacts/List/ListView.cpp @@ -32,7 +32,9 @@ #include #include -#define TITLE_SIZE 32 +#define TITLE_SIZE 32 +#define PART_TITLE_RIGHT "title_right_btn" +#define PART_TITLE_LEFT "title_left_btn" using namespace Contacts; using namespace Contacts::List; @@ -41,6 +43,7 @@ using namespace Utils; ListView::ListView(PersonProvider::FilterType personFilter) : m_Genlist(nullptr), m_Index(nullptr), + m_CancelButton(nullptr), m_DoneButton(nullptr), m_Sections{ nullptr }, m_Provider(PersonProvider(personFilter)), m_ViewMode(ModeDefault), @@ -78,6 +81,16 @@ void ListView::setMode(Mode mode) } } +void ListView::setResultCallback(ResultCallback callback) +{ + m_OnResult = std::move(callback); +} + +void ListView::unsetResultCallback() +{ + m_OnResult = nullptr; +} + Evas_Object *ListView::onCreate(Evas_Object *parent) { Evas_Object *layout = elm_layout_add(parent); @@ -114,6 +127,9 @@ void ListView::onMenuPressed() ListView *deleteView = new ListView(); getNavigator()->navigateTo(deleteView); deleteView->setMode(ModeMultipick); + deleteView->setResultCallback([](PersonIds ids) { + contacts_db_delete_records(_contacts_person._uri, ids.data(), ids.size()); + }); }); menu->addItem("IDS_PB_OPT_SETTINGS", [this] { @@ -267,12 +283,23 @@ PersonItem::Mode ListView::getItemMode(Mode viewMode) void ListView::updateTitle() { switch (m_ViewMode) { - case ModeDefault: getPage()->setTitle("IDS_PB_TAB_CONTACTS"); break; - case ModeMultipick: { + case ModeDefault: + getPage()->setTitle("IDS_PB_TAB_CONTACTS"); + + evas_object_del(m_CancelButton); + evas_object_del(m_DoneButton); + m_CancelButton = nullptr; + m_DoneButton = nullptr; + break; + case ModeMultipick: + { char title[TITLE_SIZE]; snprintf(title, TITLE_SIZE, _("IDS_PB_HEADER_PD_SELECTED_ABB"), m_CheckedCount); getPage()->setTitle(title); + + createCancelButton(); + createDoneButton(); break; } default: break; @@ -295,6 +322,31 @@ void ListView::deleteNewContactButton() //Todo } +void ListView::createCancelButton() +{ + m_CancelButton = elm_button_add(getEvasObject()); + elm_object_style_set(m_CancelButton, "naviframe/title_left"); + elm_object_translatable_text_set(m_CancelButton, "IDS_PB_BUTTON_CANCEL"); + evas_object_smart_callback_add(m_CancelButton, "clicked", + [](void *self, Evas_Object *obj, void *eventInfo) { + delete static_cast(self); + }, + this); + + getPage()->setContent(PART_TITLE_LEFT, m_CancelButton); +} + +void ListView::createDoneButton() +{ + Evas_Object *m_DoneButton = elm_button_add(getEvasObject()); + elm_object_style_set(m_DoneButton, "naviframe/title_right"); + elm_object_translatable_text_set(m_DoneButton, "IDS_PB_BUTTON_DONE_ABB3"); + evas_object_smart_callback_add(m_DoneButton, "clicked", + makeCallback(&ListView::onDonePressed), this); + + getPage()->setContent(PART_TITLE_RIGHT, m_DoneButton); +} + void ListView::insertMyProfileGroupItem() { auto group = new GroupItem("IDS_PB_HEADER_ME"); @@ -478,6 +530,21 @@ PersonItem *ListView::getNextPersonItem(PersonGroupItem *group, const Person &pe return nullptr; } +ListView::PersonIds ListView::getCheckedPersonIds() +{ + PersonIds ids; + for (auto &&group : m_PersonGroups) { + for (auto &&item : *group.second) { + PersonItem *personItem = static_cast(item); + if (personItem->isChecked()) { + ids.push_back(personItem->getPerson().getId()); + } + } + } + + return ids; +} + void ListView::launchPersonDetail(PersonItem *item) { int id = 0; @@ -502,6 +569,15 @@ void ListView::onCreatePressed() getNavigator()->navigateTo(new Input::InputView()); } +void ListView::onDonePressed(Evas_Object *button, void *eventInfo) +{ + if (m_OnResult) { + m_OnResult(getCheckedPersonIds()); + } + + delete this; +} + void ListView::onPersonInserted(PersonPtr person) { insertPersonItem(createPersonItem(std::move(person))); diff --git a/lib-contact/src/Contacts/List/Model/PersonProvider.cpp b/lib-contact/src/Contacts/List/Model/PersonProvider.cpp index 30229fd..c045142 100644 --- a/lib-contact/src/Contacts/List/Model/PersonProvider.cpp +++ b/lib-contact/src/Contacts/List/Model/PersonProvider.cpp @@ -107,6 +107,11 @@ PersonProvider::PersonProvider(PersonProvider::FilterType filterType) contacts_db_add_changed_cb(_contacts_person._uri, makeCallbackWithLastParam(&PersonProvider::onChanged), this); } +PersonProvider::~PersonProvider() +{ + contacts_db_remove_changed_cb(_contacts_person._uri, makeCallbackWithLastParam(&PersonProvider::onChanged), this); +} + PersonList PersonProvider::getPersonList() const { PersonList personList; -- 2.7.4