class Person;
class PersonProvider;
}
- class PersonItem;
+ class ContactItem;
/**
* @brief Represents list section containing genlist items.
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
* @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;
/**
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;
};
}
}
class SearchItem;
class PersonGroupItem;
class PersonItem;
+ class ContactItem;
/**
* @brief Contacts list view
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;
--- /dev/null
+/*
+ * 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 */
#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"
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));
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) {
}
}
-void ListSection::onDeleted(PersonItem *item)
+void ListSection::onDeleted(ContactItem *item)
{
item->pop();
if (m_OnUpdated) {
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;
}
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);
#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;
void ManageFavoritesPopup::onReorder()
{
- //todo
+ m_Navigator->navigateTo(new ReorderView());
}
void ManageFavoritesPopup::onRemove()
--- /dev/null
+/*
+ * 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();
+}