TizenRefApp-6328 Implement Reorder View 40/72340/1
authorNataliia Sydorchuk <n.sydorchuk@samsung.com>
Tue, 31 May 2016 11:49:52 +0000 (14:49 +0300)
committerNataliia Sydorchuk <n.sydorchuk@samsung.com>
Tue, 31 May 2016 12:06:42 +0000 (15:06 +0300)
Change-Id: Ief0a71892456bf0341f82a35ec3c450c6ed8a7a1
Signed-off-by: Nataliia Sydorchuk <n.sydorchuk@samsung.com>
lib-contacts/inc/Contacts/List/ListSection.h
lib-contacts/inc/Contacts/List/ListView.h
lib-contacts/inc/Contacts/List/ReorderView.h [new file with mode: 0644]
lib-contacts/src/Contacts/List/ListSection.cpp
lib-contacts/src/Contacts/List/ListView.cpp
lib-contacts/src/Contacts/List/ManageFavoritesPopup.cpp
lib-contacts/src/Contacts/List/ReorderView.cpp [new file with mode: 0644]

index 92662bf..f19716c 100644 (file)
@@ -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<void(PersonItem *item, Common::ChangeType changeType)> UpdateCallback;
+                       typedef std::function<void(ContactItem *item, Common::ChangeType changeType)> 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;
                };
        }
 }
index 1907b31..6476852 100644 (file)
@@ -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 (file)
index 0000000..bcc7f90
--- /dev/null
@@ -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 <vector>
+
+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<ReorderData> m_ReorderDatas;
+               };
+       }
+}
+
+
+
+#endif /* CONTACTS_LIST_REORDER_VIEW_H */
index 0c18dd2..754be7d 100644 (file)
@@ -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 &>(person));
+       ContactItem *item = createItem(static_cast<Person &>(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;
 }
index 8d0e551..d08afc5 100644 (file)
@@ -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);
index 8f3668a..00501ee 100644 (file)
@@ -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 (file)
index 0000000..b6a4724
--- /dev/null
@@ -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();
+}