summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Kobec <s.kobec@samsung.com>2017-09-11 14:05:29 +0300
committerSergei Kobec <s.kobec@samsung.com>2017-09-12 12:09:00 +0300
commit9fa6c29e865c099e358385d0c02ca13c6e72ad74 (patch)
treeb48538ed49bfb57ce9708df79dce46a6d810cda2
parent5314fc243e0fa9fafc1bd3bab0899a1dc3e0cca7 (diff)
downloadphone-contacts-9fa6c29e865c099e358385d0c02ca13c6e72ad74.tar.gz
phone-contacts-9fa6c29e865c099e358385d0c02ca13c6e72ad74.tar.bz2
phone-contacts-9fa6c29e865c099e358385d0c02ca13c6e72ad74.zip
Change WidgetItem creation logic in ContactWidgetItemsView
Optimized items creation count for different widget layout type. Change-Id: I38bb3075635c5cb7fbcbc7f9bc56f5f27db8c9ea Signed-off-by: Sergei Kobec <s.kobec@samsung.com>
-rw-r--r--contacts-widget-edit-app/inc/WidgetEditView.h7
-rw-r--r--contacts-widget-edit-app/src/WidgetEditView.cpp18
-rw-r--r--lib-common/inc/Common/ContactWidgetItemsView.h11
-rw-r--r--lib-common/src/Common/ContactWidgetItemsView.cpp55
4 files changed, 53 insertions, 38 deletions
diff --git a/contacts-widget-edit-app/inc/WidgetEditView.h b/contacts-widget-edit-app/inc/WidgetEditView.h
index f054bbc..34bff0a 100644
--- a/contacts-widget-edit-app/inc/WidgetEditView.h
+++ b/contacts-widget-edit-app/inc/WidgetEditView.h
@@ -19,11 +19,6 @@
#include "Common/ContactWidgetItemsView.h"
-namespace Common
-{
- class WidgetItem;
-}
-
class WidgetEditView : public Common::ContactWidgetItemsView
{
public:
@@ -35,7 +30,7 @@ public:
private:
virtual Evas_Object *onCreate(Evas_Object *parent) override;
- virtual void onCreated() override;
+ virtual Common::WidgetItem *createItem(int id) override;
void move(Common::WidgetItem *item);
diff --git a/contacts-widget-edit-app/src/WidgetEditView.cpp b/contacts-widget-edit-app/src/WidgetEditView.cpp
index 0de5477..9ea72cd 100644
--- a/contacts-widget-edit-app/src/WidgetEditView.cpp
+++ b/contacts-widget-edit-app/src/WidgetEditView.cpp
@@ -41,15 +41,14 @@ Evas_Object *WidgetEditView::onCreate(Evas_Object *parent)
return layout;
}
-void WidgetEditView::onCreated()
+WidgetItem *WidgetEditView::createItem(int id)
{
- ContactWidgetItemsView::onCreated();
+ auto item = ContactWidgetItemsView::createItem(id);
+ item->setItemGrabCallback(std::bind(&WidgetEditView::onItemGrabbed, this, item));
+ item->setItemReleaseCallback(std::bind(&WidgetEditView::onItemReleased, this));
+ item->setItemMoveCallback(std::bind(&WidgetEditView::onItemMove, this, _1));
- for (auto &&item : getWidgetItems()) {
- item->setItemGrabCallback(std::bind(&WidgetEditView::onItemGrabbed, this, item));
- item->setItemReleaseCallback(std::bind(&WidgetEditView::onItemReleased, this));
- item->setItemMoveCallback(std::bind(&WidgetEditView::onItemMove, this, _1));
- }
+ return item;
}
void WidgetEditView::move(WidgetItem *item)
@@ -94,7 +93,7 @@ void WidgetEditView::onItemMove(Evas_Point itemPos)
if (item == m_ReleasedItem) {
continue;
}
- if (item->hits(itemPos)) {
+ if (item && item->hits(itemPos)) {
move(item);
size_t newReleasedIndex = item->getIndex();
@@ -111,7 +110,8 @@ void WidgetEditView::onReorderingFinished()
{
ContactWidgetItems::ContactIds ids = { 0 };
for (auto &&item : getWidgetItems()) {
- if (auto contact = item->getContactData()) {
+ const ContactData *contact = nullptr;
+ if (item && (contact = item->getContactData())) {
ids[item->getIndex()] = contact->getId();
}
}
diff --git a/lib-common/inc/Common/ContactWidgetItemsView.h b/lib-common/inc/Common/ContactWidgetItemsView.h
index 4aea011..ddfe184 100644
--- a/lib-common/inc/Common/ContactWidgetItemsView.h
+++ b/lib-common/inc/Common/ContactWidgetItemsView.h
@@ -50,6 +50,13 @@ namespace Common
virtual void onCreated() override;
/**
+ * @brief Create widget item.
+ * @param[in] id Contact ID
+ * @return @ref WidgetItem.
+ */
+ virtual WidgetItem *createItem(int id);
+
+ /**
* @return Contact widget items.
*/
Model::ContactWidgetItems &getContactWidgetItems();
@@ -69,8 +76,8 @@ namespace Common
private:
virtual Evas_Object *onCreate(Evas_Object *parent) override;
- void onContactAdded(int id, size_t index);
- void onContactDeleted(size_t index);
+ void onContactAdded(int id, const WidgetItem *item);
+ void onContactDeleted(const WidgetItem *item);
Model::ContactWidgetItems &m_ContactWidgetItems;
WidgetItems m_WidgetItems;
diff --git a/lib-common/src/Common/ContactWidgetItemsView.cpp b/lib-common/src/Common/ContactWidgetItemsView.cpp
index b31485c..69664f1 100644
--- a/lib-common/src/Common/ContactWidgetItemsView.cpp
+++ b/lib-common/src/Common/ContactWidgetItemsView.cpp
@@ -31,6 +31,12 @@ using namespace std::placeholders;
namespace
{
const char *parts[] = { PART_ITEM1, PART_ITEM2, PART_ITEM3, PART_ITEM4 };
+
+ struct
+ {
+ size_t begin;
+ size_t end;
+ } itemIndexes[] = { { 0, 0 }, { 0, 1 }, { 1, 3 }, { 0, 3 }, { 0, MAX_ITEMS_COUNT } };
}
ContactWidgetItemsView::ContactWidgetItemsView(ContactWidgetItems &contactItems, bool isEditable)
@@ -42,29 +48,36 @@ ContactWidgetItemsView::ContactWidgetItemsView(ContactWidgetItems &contactItems,
void ContactWidgetItemsView::onCreated()
{
- if (!m_IsEditable && m_ContactWidgetItems.getItemCount() == 1) {
+ size_t itemCount = m_ContactWidgetItems.getItemCount();
+ if (!m_IsEditable && itemCount == 1) {
auto item = new SingleWidgetView(new Number(m_ContactWidgetItems.getIds()[0]));
item->create(getEvasObject());
elm_object_part_content_set(getEvasObject(), parts[0], item->getEvasObject());
- item->setDeleteCallback(std::bind(&ContactWidgetItemsView::onContactDeleted, this, 0));
- } else {
- for (size_t i = 0; i < MAX_ITEMS_COUNT; ++i) {
- int id = m_ContactWidgetItems.getIds()[i];
-
- auto item = new WidgetItem(id ? new Number(id) : nullptr);
- item->create(getEvasObject());
- item->setIndex(i);
- item->setEditable(m_IsEditable);
- elm_object_part_content_set(getEvasObject(), parts[i], item->getEvasObject());
-
- item->setContactDeletedCallback(std::bind(&ContactWidgetItemsView::onContactDeleted, this, i));
- item->setContactAddedCallback(std::bind(&ContactWidgetItemsView::onContactAdded, this, _1, i));
-
- m_WidgetItems[i] = item;
- }
+ item->setDeleteCallback([this] { m_ContactWidgetItems.deleteItem(0); });
+ return;
+ }
+
+ auto indexRange = m_IsEditable ? itemIndexes[MAX_ITEMS_COUNT] : itemIndexes[itemCount];
+ for (size_t i = indexRange.begin; i < indexRange.end; ++i) {
+ auto item = createItem(m_ContactWidgetItems.getIds()[i]);
+ item->setIndex(i);
+ elm_object_part_content_set(getEvasObject(), parts[i], item->getEvasObject());
+ m_WidgetItems[i] = item;
}
}
+WidgetItem *ContactWidgetItemsView::createItem(int id)
+{
+ auto item = new WidgetItem(id ? new Number(id) : nullptr);
+ item->create(getEvasObject());
+ item->setEditable(m_IsEditable);
+
+ item->setContactDeletedCallback(std::bind(&ContactWidgetItemsView::onContactDeleted, this, item));
+ item->setContactAddedCallback(std::bind(&ContactWidgetItemsView::onContactAdded, this, _1, item));
+
+ return item;
+}
+
ContactWidgetItems &ContactWidgetItemsView::getContactWidgetItems()
{
return m_ContactWidgetItems;
@@ -100,12 +113,12 @@ Evas_Object *ContactWidgetItemsView::onCreate(Evas_Object *parent)
return layout;
}
-void ContactWidgetItemsView::onContactAdded(int id, size_t index)
+void ContactWidgetItemsView::onContactAdded(int id, const WidgetItem *item)
{
- m_ContactWidgetItems.addItem(id, index);
+ m_ContactWidgetItems.addItem(id, item->getIndex());
}
-void ContactWidgetItemsView::onContactDeleted(size_t index)
+void ContactWidgetItemsView::onContactDeleted(const WidgetItem *item)
{
- m_ContactWidgetItems.deleteItem(index);
+ m_ContactWidgetItems.deleteItem(item->getIndex());
}