From: Nataliia Sydorchuk Date: Tue, 22 Mar 2016 15:26:55 +0000 (+0200) Subject: TizenRefApp-5834 Integrate vcard Provider with List View X-Git-Tag: submit/tizen/20160524.113145~103^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=387d323a25e616a36d1c2f1829191f604a346fde;p=profile%2Fmobile%2Fapps%2Fnative%2Fphone-contacts.git TizenRefApp-5834 Integrate vcard Provider with List View Change-Id: Id514b04dc24cd9b4d3e475bf598e1dafe7cfaab0 Signed-off-by: Nataliia Sydorchuk --- diff --git a/lib-common/inc/Contacts/Model/ContactData.h b/lib-common/inc/Contacts/Model/ContactData.h index 4d80513..9aa2e79 100644 --- a/lib-common/inc/Contacts/Model/ContactData.h +++ b/lib-common/inc/Contacts/Model/ContactData.h @@ -22,6 +22,11 @@ #include #include +namespace Utils +{ + class UniString; +} + namespace Contacts { namespace Model @@ -142,6 +147,11 @@ namespace Contacts */ void unsetDeleteCallback(); + /** + * @return First letter from formatted person name + */ + virtual const Utils::UniString *getIndexLetter() const; + protected: /** * @brief ContactData updated callback diff --git a/lib-common/inc/Contacts/Model/ContactRecordData.h b/lib-common/inc/Contacts/Model/ContactRecordData.h index 3f9b0b9..c34fe7b 100644 --- a/lib-common/inc/Contacts/Model/ContactRecordData.h +++ b/lib-common/inc/Contacts/Model/ContactRecordData.h @@ -72,12 +72,12 @@ namespace Contacts */ virtual bool compare(const char *str) override; - protected: /** * @return contact record */ const contacts_record_h getContactRecord() const; + protected: /** * @brief Set changed callback * @param[in] callback Change callback diff --git a/lib-common/src/Contacts/Model/ContactData.cpp b/lib-common/src/Contacts/Model/ContactData.cpp index 34ffa63..b69ee9e 100644 --- a/lib-common/src/Contacts/Model/ContactData.cpp +++ b/lib-common/src/Contacts/Model/ContactData.cpp @@ -16,6 +16,7 @@ */ #include "Contacts/Model/ContactData.h" +#include "Utils/UniString.h" using namespace Contacts::Model; @@ -49,6 +50,11 @@ void ContactData::unsetDeleteCallback() m_OnDeleted = nullptr; } +const Utils::UniString *ContactData::getIndexLetter() const +{ + return nullptr; +} + void ContactData::onUpdated(int changes) { if (m_OnUpdated) { diff --git a/lib-contact/inc/Contacts/List/ListView.h b/lib-contact/inc/Contacts/List/ListView.h index 109e71b..1a66e61 100644 --- a/lib-contact/inc/Contacts/List/ListView.h +++ b/lib-contact/inc/Contacts/List/ListView.h @@ -18,7 +18,7 @@ #ifndef CONTACTS_LIST_LIST_VIEW_H #define CONTACTS_LIST_LIST_VIEW_H -#include "Contacts/List/Model/PersonProvider.h" +#include "Contacts/Common/ContactSelectTypes.h" #include "Contacts/SelectView.h" #include "Utils/UniString.h" @@ -34,6 +34,12 @@ namespace Ui namespace Contacts { + namespace Model + { + class ContactData; + class ContactDataProvider; + } + namespace List { class GroupItem; @@ -57,6 +63,13 @@ namespace Contacts * @param]in] filterType Defines how to filter person list */ ListView(int filterType = FilterNone); + + /** + * @brief Create new vcard contact list view + * @param]in] vcardPath Path of the vcard file + */ + explicit ListView(const char *vcardPath); + virtual ~ListView() override; private: @@ -109,7 +122,7 @@ namespace Contacts void deletePersonGroupItem(PersonGroupItem *group); PersonGroupItem *getNextPersonGroupItem(const Utils::UniString &indexLetter); - PersonItem *createPersonItem(Model::Person &person); + PersonItem *createPersonItem(Contacts::Model::ContactData &person); void insertPersonItem(PersonItem *item); void updatePersonItem(PersonItem *item, int changes); void deletePersonItem(PersonItem *item); @@ -132,7 +145,9 @@ namespace Contacts Ui::GenlistGroupItem *m_Sections[SectionMax]; std::map m_PersonGroups; - Model::PersonProvider m_Provider; + Contacts::Model::ContactDataProvider *m_Provider; + + bool m_HasIndex; }; } } diff --git a/lib-contact/inc/Contacts/List/Model/Person.h b/lib-contact/inc/Contacts/List/Model/Person.h index db7ae60..d007ce1 100644 --- a/lib-contact/inc/Contacts/List/Model/Person.h +++ b/lib-contact/inc/Contacts/List/Model/Person.h @@ -71,7 +71,7 @@ namespace Contacts /** * @return First letter from formatted person name */ - const Utils::UniString &getIndexLetter() const; + virtual const Utils::UniString *getIndexLetter() const override; /** * @return _contacts_person record diff --git a/lib-contact/inc/Contacts/List/PersonItem.h b/lib-contact/inc/Contacts/List/PersonItem.h index da9c533..f5f1b27 100644 --- a/lib-contact/inc/Contacts/List/PersonItem.h +++ b/lib-contact/inc/Contacts/List/PersonItem.h @@ -26,13 +26,13 @@ namespace Contacts { - namespace List + namespace Model { - namespace Model - { - class Person; - } + class ContactData; + } + namespace List + { /** * @brief Person list item */ @@ -43,19 +43,19 @@ namespace Contacts * @brief Create person item * @param[in] person Person object */ - explicit PersonItem(Model::Person &person); + explicit PersonItem(Contacts::Model::ContactData &person); /** * @return Person object */ - Model::Person &getPerson(); + Contacts::Model::ContactData &getPerson(); private: virtual char *getText(Evas_Object *parent, const char *part) override; virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override; virtual SelectResult getDefaultResult() const override; - Model::Person &m_Person; + Contacts::Model::ContactData &m_Person; }; } } diff --git a/lib-contact/src/Contacts/List/ListView.cpp b/lib-contact/src/Contacts/List/ListView.cpp index e7dc046..585df42 100644 --- a/lib-contact/src/Contacts/List/ListView.cpp +++ b/lib-contact/src/Contacts/List/ListView.cpp @@ -18,6 +18,8 @@ #include "Contacts/List/ListView.h" #include "Contacts/List/GroupItem.h" #include "Contacts/List/Model/Person.h" +#include "Contacts/List/Model/PersonProvider.h" +#include "Contacts/List/Model/VcardProvider.h" #include "Contacts/List/MyProfileItem.h" #include "Contacts/List/PersonGroupItem.h" #include "Contacts/List/PersonItem.h" @@ -40,14 +42,22 @@ using namespace std::placeholders; ListView::ListView(int filterType) : m_Genlist(nullptr), m_Index(nullptr), m_AddButton(nullptr), - m_Sections{ nullptr }, - m_Provider(filterType) + m_Sections{ nullptr }, m_HasIndex(true) { + m_Provider = new PersonProvider(filterType); +} + +ListView::ListView(const char *vcardPath) + : m_Genlist(nullptr), m_Index(nullptr), m_AddButton(nullptr), + m_Sections{ nullptr }, m_HasIndex(false) +{ + m_Provider = new VcardProvider(vcardPath); } ListView::~ListView() { - m_Provider.unsetInsertCallback(); + m_Provider->unsetInsertCallback(); + delete m_Provider; contacts_db_remove_changed_cb(_contacts_my_profile._uri, makeCallbackWithLastParam(&ListView::updateMyProfileItem), this); } @@ -63,6 +73,9 @@ Evas_Object *ListView::onCreate(Evas_Object *parent) elm_object_part_content_set(layout, "elm.swallow.content", m_Genlist->getEvasObject()); elm_object_part_content_set(layout, "elm.swallow.fastscroll", createIndex(layout)); + const char *signal = m_HasIndex ? "elm,state,fastscroll,show" : "elm,state,fastscroll,hide"; + elm_layout_signal_emit(layout, signal, ""); + return layout; } @@ -76,7 +89,7 @@ void ListView::onCreated() { updateSectionsMode(); - m_Provider.setInsertCallback(std::bind(&ListView::onPersonInserted, this, _1)); + m_Provider->setInsertCallback(std::bind(&ListView::onPersonInserted, this, _1)); contacts_db_add_changed_cb(_contacts_my_profile._uri, makeCallbackWithLastParam(&ListView::updateMyProfileItem), this); } @@ -108,6 +121,7 @@ void ListView::onMenuPressed() menu->addItem("IDS_PB_OPT_SETTINGS", [this] { getNavigator()->navigateTo(new Settings::MainView()); }); + menu->show(); } @@ -159,18 +173,18 @@ void ListView::fillMfc() void ListView::fillPersonList() { if (m_PersonGroups.empty()) { - ContactDataList list = m_Provider.getContactDataList(); + ContactDataList list = m_Provider->getContactDataList(); PersonGroupItem *group = nullptr; for (auto &&contactData : list) { - auto person = static_cast(contactData); - const UniString &nextLetter = person->getIndexLetter(); - - if (!group || group->getTitle() != nextLetter) { - group = insertPersonGroupItem(nextLetter); + const UniString *nextLetter = contactData->getIndexLetter(); + if (nextLetter) { + if (!group || group->getTitle() != *nextLetter) { + group = insertPersonGroupItem(*nextLetter); + } } - auto item = createPersonItem(*person); + auto item = createPersonItem(*contactData); m_Genlist->insert(item, group); onItemInserted(item); } @@ -386,7 +400,7 @@ PersonGroupItem *ListView::getNextPersonGroupItem(const Utils::UniString &indexL return nullptr; } -PersonItem *ListView::createPersonItem(Person &person) +PersonItem *ListView::createPersonItem(ContactData &person) { PersonItem *item = new PersonItem(person); person.setUpdateCallback(std::bind(&ListView::onPersonUpdated, this, item, _1)); @@ -399,15 +413,17 @@ void ListView::insertPersonItem(PersonItem *item) { PersonGroupItem *group = nullptr; PersonItem *nextItem = nullptr; - const UniString &indexLetter = item->getPerson().getIndexLetter(); - auto it = m_PersonGroups.find(indexLetter); - if (it != m_PersonGroups.end()) { - group = it->second; - nextItem = getNextPersonItem(it->second, item->getPerson()); - } else { - PersonGroupItem *nextGroup = getNextPersonGroupItem(indexLetter); - group = insertPersonGroupItem(indexLetter, nextGroup); + const UniString *indexLetter = item->getPerson().getIndexLetter(); + if (indexLetter) { + auto it = m_PersonGroups.find(*indexLetter); + if (it != m_PersonGroups.end()) { + group = it->second; + nextItem = getNextPersonItem(it->second, static_cast(item->getPerson())); + } else { + PersonGroupItem *nextGroup = getNextPersonGroupItem(*indexLetter); + group = insertPersonGroupItem(*indexLetter, nextGroup); + } } m_Genlist->insert(item, group, nextItem); @@ -447,7 +463,7 @@ PersonItem *ListView::getNextPersonItem(PersonGroupItem *group, const Person &pe { for (auto &&item : *group) { PersonItem *personItem = static_cast(item); - if (person < personItem->getPerson()) { + if (person < static_cast(personItem->getPerson())) { return personItem; } } @@ -458,7 +474,7 @@ PersonItem *ListView::getNextPersonItem(PersonGroupItem *group, const Person &pe void ListView::onItemPressed(SelectItem *item) { PersonItem *personItem = static_cast(item); - int id = personItem->getPerson().getDisplayContactId(); + int id = static_cast(personItem->getPerson()).getDisplayContactId(); getNavigator()->navigateTo(new Details::DetailsView(id)); } @@ -481,7 +497,7 @@ void ListView::onIndexSelected(Evas_Object *index, Elm_Object_Item *indexItem) void ListView::onPersonInserted(ContactData &person) { - auto item = createPersonItem(static_cast(person)); + auto item = createPersonItem(person); insertPersonItem(item); onItemInserted(item); } diff --git a/lib-contact/src/Contacts/List/Model/Person.cpp b/lib-contact/src/Contacts/List/Model/Person.cpp index a0d628c..594335c 100644 --- a/lib-contact/src/Contacts/List/Model/Person.cpp +++ b/lib-contact/src/Contacts/List/Model/Person.cpp @@ -93,9 +93,9 @@ const Person::ContactIds &Person::getContactIds() const return m_ContactIds; } -const UniString &Person::getIndexLetter() const +const UniString *Person::getIndexLetter() const { - return m_IndexLetter; + return &m_IndexLetter; } const contacts_record_h Person::getRecord() const diff --git a/lib-contact/src/Contacts/List/PersonItem.cpp b/lib-contact/src/Contacts/List/PersonItem.cpp index e045f0f..47fad76 100644 --- a/lib-contact/src/Contacts/List/PersonItem.cpp +++ b/lib-contact/src/Contacts/List/PersonItem.cpp @@ -15,21 +15,22 @@ * */ +#include "Contacts/Model/ContactRecordData.h" #include "Contacts/List/PersonItem.h" #include "Contacts/Common/ContactSelectTypes.h" -#include "Contacts/List/Model/Person.h" #include "Ui/Thumbnail.h" #include using namespace Contacts; using namespace Contacts::List; -using namespace Contacts::List::Model; +using namespace Contacts::Model; -PersonItem::PersonItem(Person &person) +PersonItem::PersonItem(ContactData &person) : m_Person(person) -{ } +{ +} -Person &PersonItem::getPerson() +ContactData &PersonItem::getPerson() { return m_Person; } @@ -62,5 +63,9 @@ Evas_Object *PersonItem::getContent(Evas_Object *parent, const char *part) SelectResult PersonItem::getDefaultResult() const { - return { ResultPerson, m_Person.getId() }; + if (m_Person.getType() == ContactData::TypeContact) { + return { ResultPerson, (void *)static_cast(m_Person).getContactRecord() }; + } else { + return { ResultPerson, m_Person.getId() }; + } } diff --git a/main-app/src/OperationViewController.cpp b/main-app/src/OperationViewController.cpp index 724f3d8..dc88693 100644 --- a/main-app/src/OperationViewController.cpp +++ b/main-app/src/OperationViewController.cpp @@ -51,8 +51,14 @@ void OperationViewController::onRequest(Operation operation, app_control_h reque char *uri = NULL; app_control_get_uri(request, &uri); if (uri) { - view = new ListView(); - /* TODO: use VcardProvider */ + view = new ListView(uri); + ListView *listView = (ListView *)view; + listView->setSelectMode(SelectMulti); + listView->setSelectCallback([](SelectResults results) { + //TODO: Launch Importer for selected contacts. + return false; + }); + free(uri); } }