From: Nataliia Sydorchuk Date: Tue, 31 May 2016 11:49:52 +0000 (+0300) Subject: TizenRefApp-6328 Implement Reorder View X-Git-Tag: submit/tizen/20160606.112431^2~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F40%2F72340%2F1;p=profile%2Fmobile%2Fapps%2Fnative%2Fphone-contacts.git TizenRefApp-6328 Implement Reorder View Change-Id: Ief0a71892456bf0341f82a35ec3c450c6ed8a7a1 Signed-off-by: Nataliia Sydorchuk --- diff --git a/lib-contacts/inc/Contacts/List/ListSection.h b/lib-contacts/inc/Contacts/List/ListSection.h index 92662bf..f19716c 100644 --- a/lib-contacts/inc/Contacts/List/ListSection.h +++ b/lib-contacts/inc/Contacts/List/ListSection.h @@ -35,7 +35,7 @@ namespace Contacts class Person; class PersonProvider; } - class PersonItem; + class ContactItem; /** * @brief Represents list section containing genlist items. @@ -43,10 +43,15 @@ namespace Contacts class ListSection : public Ui::GenlistGroupItem { public: + enum SectionMode { + DefaultMode, + ReorderMode + }; + /** * @brief Update group item callback. */ - typedef std::function UpdateCallback; + typedef std::function UpdateCallback; /** * @brief Create list section @@ -54,7 +59,8 @@ namespace Contacts * @param[in] provider Section provider * */ - ListSection(std::string title, Model::PersonProvider *provider); + ListSection(std::string title, Model::PersonProvider *provider, + SectionMode mode = DefaultMode); virtual ~ListSection() override; /** @@ -65,16 +71,17 @@ namespace Contacts protected: void onInserted(Contacts::Model::ContactData &person); - PersonItem *createItem(Model::Person &person); + ContactItem *createItem(Model::Person &person); private: virtual char *getText(Evas_Object *parent, const char *part) override; - void onDeleted(PersonItem *item); + void onDeleted(ContactItem *item); std::string m_Title; UpdateCallback m_OnUpdated; Model::PersonProvider *m_Provider; + SectionMode m_Mode; }; } } diff --git a/lib-contacts/inc/Contacts/List/ListView.h b/lib-contacts/inc/Contacts/List/ListView.h index 1907b31..6476852 100644 --- a/lib-contacts/inc/Contacts/List/ListView.h +++ b/lib-contacts/inc/Contacts/List/ListView.h @@ -39,6 +39,7 @@ namespace Contacts class SearchItem; class PersonGroupItem; class PersonItem; + class ContactItem; /** * @brief Contacts list view @@ -127,7 +128,7 @@ namespace Contacts void onIndexSelected(Evas_Object *index, Elm_Object_Item *indexItem); void onPersonInserted(Contacts::Model::ContactData &person); - void onSectionUpdated(PersonItem *item, ::Common::ChangeType change, SectionId sectionId); + void onSectionUpdated(ContactItem *item, ::Common::ChangeType change, SectionId sectionId); void onSearchChanged(const char *str); Evas_Object *m_Box; diff --git a/lib-contacts/inc/Contacts/List/ReorderView.h b/lib-contacts/inc/Contacts/List/ReorderView.h new file mode 100644 index 0000000..bcc7f90 --- /dev/null +++ b/lib-contacts/inc/Contacts/List/ReorderView.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef CONTACTS_LIST_REORDER_VIEW_H +#define CONTACTS_LIST_REORDER_VIEW_H + +#include "Ui/View.h" + +#include + +namespace Ui +{ + class Genlist; +} + +namespace Contacts +{ + namespace List + { + class ReorderView : public Ui::View + { + public: + /** + * @brief Create new reorder favorites contact list view + */ + ReorderView(); + + private: + struct ReorderData + { + int personId; + int prevPersonId; + int nextPersonId; + }; + + virtual Evas_Object *onCreate(Evas_Object *parent) override; + virtual void onPageAttached(Ui::NavigatorPage *page) override; + + void createPageButtons(); + + void onReorder(Evas_Object *obj, void *event_info); + void onCancelPressed(Evas_Object *button, void *eventInfo); + void onDonePressed(Evas_Object *button, void *eventInfo); + + Evas_Object *m_CancelButton; + Evas_Object *m_DoneButton; + Ui::Genlist *m_Genlist; + Ui::GenlistItem *m_Section; + std::vector m_ReorderDatas; + }; + } +} + + + +#endif /* CONTACTS_LIST_REORDER_VIEW_H */ diff --git a/lib-contacts/src/Contacts/List/ListSection.cpp b/lib-contacts/src/Contacts/List/ListSection.cpp index 0c18dd2..754be7d 100644 --- a/lib-contacts/src/Contacts/List/ListSection.cpp +++ b/lib-contacts/src/Contacts/List/ListSection.cpp @@ -17,6 +17,7 @@ #include "Contacts/List/ListSection.h" #include "Contacts/List/PersonItem.h" +#include "Contacts/List/ReorderItem.h" #include "Contacts/List/Model/Person.h" #include "Contacts/List/Model/PersonProvider.h" #include "Utils/Logger.h" @@ -26,8 +27,8 @@ using namespace Contacts::List; using namespace Contacts::List::Model; -ListSection::ListSection(std::string title, PersonProvider *provider) - : m_Title(title), m_Provider(provider) +ListSection::ListSection(std::string title, PersonProvider *provider, SectionMode mode) + : m_Title(title), m_Provider(provider), m_Mode(mode) { m_Provider->setInsertCallback(std::bind(&ListSection::onInserted, this, std::placeholders::_1)); @@ -57,7 +58,7 @@ char *ListSection::getText(Evas_Object *parent, const char *part) void ListSection::onInserted(Contacts::Model::ContactData &person) { - PersonItem *item = createItem(static_cast(person)); + ContactItem *item = createItem(static_cast(person)); insertSubItem(item); if (m_OnUpdated) { @@ -65,7 +66,7 @@ void ListSection::onInserted(Contacts::Model::ContactData &person) } } -void ListSection::onDeleted(PersonItem *item) +void ListSection::onDeleted(ContactItem *item) { item->pop(); if (m_OnUpdated) { @@ -75,10 +76,15 @@ void ListSection::onDeleted(PersonItem *item) delete item; } -PersonItem *ListSection::createItem(Person &person) +ContactItem *ListSection::createItem(Person &person) { - PersonItem *item = new PersonItem(person); - person.setUpdateCallback(std::bind(&PersonItem::update, item, std::placeholders::_1)); + ContactItem *item = nullptr; + if (m_Mode == ReorderMode) { + item = new ReorderItem(person); + } else { + item = new PersonItem(person); + } + person.setUpdateCallback(std::bind(&ContactItem::update, item, std::placeholders::_1)); person.setDeleteCallback(std::bind(&ListSection::onDeleted, this, item)); return item; } diff --git a/lib-contacts/src/Contacts/List/ListView.cpp b/lib-contacts/src/Contacts/List/ListView.cpp index 8d0e551..d08afc5 100644 --- a/lib-contacts/src/Contacts/List/ListView.cpp +++ b/lib-contacts/src/Contacts/List/ListView.cpp @@ -643,10 +643,10 @@ void ListView::onPersonInserted(ContactData &contactData) elm_index_level_go(m_Index, 0); } -void ListView::onSectionUpdated(PersonItem *item, ::Common::ChangeType change, SectionId sectionId) +void ListView::onSectionUpdated(ContactItem *item, ::Common::ChangeType change, SectionId sectionId) { if (change == Common::ChangeInsert) { - linkPersonItems(item); + linkPersonItems((PersonItem *)item); onItemInserted(item); } else if (change == Common::ChangeDelete) { onItemRemove(item); diff --git a/lib-contacts/src/Contacts/List/ManageFavoritesPopup.cpp b/lib-contacts/src/Contacts/List/ManageFavoritesPopup.cpp index 8f3668a..00501ee 100644 --- a/lib-contacts/src/Contacts/List/ManageFavoritesPopup.cpp +++ b/lib-contacts/src/Contacts/List/ManageFavoritesPopup.cpp @@ -20,6 +20,7 @@ #include "Contacts/List/ListView.h" #include "Contacts/List/ManageFavoritesPopup.h" #include "Contacts/List/Model/FavoritesProvider.h" +#include "Contacts/List/ReorderView.h" #include "Ui/Navigator.h" using namespace Common::Database; @@ -78,7 +79,7 @@ void ManageFavoritesPopup::onAdd() void ManageFavoritesPopup::onReorder() { - //todo + m_Navigator->navigateTo(new ReorderView()); } void ManageFavoritesPopup::onRemove() diff --git a/lib-contacts/src/Contacts/List/ReorderView.cpp b/lib-contacts/src/Contacts/List/ReorderView.cpp new file mode 100644 index 0000000..b6a4724 --- /dev/null +++ b/lib-contacts/src/Contacts/List/ReorderView.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "Contacts/List/Model/FavoritesProvider.h" +#include "Contacts/List/ListSection.h" +#include "Contacts/List/ReorderItem.h" +#include "Contacts/List/ReorderView.h" + +#include "Utils/Callback.h" +#include "Utils/Logger.h" + +using namespace Contacts::List; +using namespace Contacts::List::Model; + +ReorderView::ReorderView() + : m_CancelButton(nullptr), m_DoneButton(nullptr), m_Genlist(nullptr), m_Section(nullptr) +{} + +Evas_Object *ReorderView::onCreate(Evas_Object *parent) +{ + m_Genlist = new Ui::Genlist(); + m_Genlist->create(parent); + + m_Section = new ListSection("IDS_PB_HEADER_FAVOURITES", + new FavoritesProvider(), ListSection::ReorderMode); + + m_Genlist->insert(m_Section); + elm_genlist_item_select_mode_set(m_Section->getObjectItem(), ELM_OBJECT_SELECT_MODE_NONE); + evas_object_smart_callback_add(m_Genlist->getEvasObject(), "moved", + makeCallback(&ReorderView::onReorder), this); + + return m_Genlist->getEvasObject(); +} + +void ReorderView::onPageAttached(Ui::NavigatorPage *page) +{ + page->setTitle("IDS_PB_OPT_REORDER");; + + createPageButtons(); + page->setContent("title_right_btn", m_DoneButton); + page->setContent("title_left_btn", m_CancelButton); +} + +void ReorderView::createPageButtons() +{ + m_CancelButton = elm_button_add(getEvasObject()); + elm_object_style_set(m_CancelButton, "naviframe/title_left"); + elm_object_translatable_text_set(m_CancelButton, "IDS_TPLATFORM_ACBUTTON_CANCEL_ABB"); + evas_object_smart_callback_add(m_CancelButton, "clicked", + makeCallback(&ReorderView::onCancelPressed), this); + + m_DoneButton = elm_button_add(getEvasObject()); + elm_object_style_set(m_DoneButton, "naviframe/title_right"); + elm_object_translatable_text_set(m_DoneButton, "IDS_TPLATFORM_ACBUTTON_DONE_ABB"); + evas_object_smart_callback_add(m_DoneButton, "clicked", + makeCallback(&ReorderView::onDonePressed), this); + elm_object_disabled_set(m_DoneButton, EINA_TRUE); +} + +void ReorderView::onReorder(Evas_Object *obj, void *event_info) +{ + elm_object_disabled_set(m_DoneButton, EINA_FALSE); + elm_genlist_reorder_mode_set(obj, EINA_FALSE); + + ReorderItem *item = (ReorderItem *)elm_object_item_data_get((Elm_Object_Item *)event_info); + RETM_IF(!item, "item is invalid"); + int itemId = item->getContactData().getId(); + + ReorderItem *prevItem = (ReorderItem *)item->getPrevItem(); + int prevItemId = 0; + if (prevItem && prevItem != m_Section) { + prevItemId = prevItem->getContactData().getId(); + } + + ReorderItem *nextItem = (ReorderItem *)item->getNextItem(); + int nextItemId = 0; + if (nextItem) { + nextItemId = nextItem->getContactData().getId(); + } + + ReorderData data; + data.personId = itemId; + data.prevPersonId = prevItemId; + data.nextPersonId = nextItemId; + + m_ReorderDatas.push_back(data); +} + +void ReorderView::onCancelPressed(Evas_Object *button, void *eventInfo) +{ + Ui::NavigatorPage *page = getPage(); + page->close(); +} + +void ReorderView::onDonePressed(Evas_Object *button, void *eventInfo) +{ + for (auto &&reorderData : m_ReorderDatas) { + contacts_person_set_favorite_order(reorderData.personId, + reorderData.prevPersonId, reorderData.nextPersonId); + } + + Ui::NavigatorPage *page = getPage(); + page->close(); +}