TizenRefApp-6681 Implement Group field in the Contact Details 98/80198/3
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Fri, 15 Jul 2016 07:34:46 +0000 (10:34 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Mon, 18 Jul 2016 10:16:52 +0000 (03:16 -0700)
Change-Id: I1c76d62053a91654ba5d71055d102d395d09d331
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-contacts/inc/Contacts/Details/GroupsFieldItem.h [new file with mode: 0644]
lib-contacts/inc/Contacts/Model/ContactFieldContainer.h
lib-contacts/src/Contacts/Details/DetailsView.cpp
lib-contacts/src/Contacts/Details/GroupsFieldItem.cpp [new file with mode: 0644]
lib-contacts/src/Contacts/Model/ContactArray.cpp
lib-contacts/src/Contacts/Model/ContactField.cpp
lib-contacts/src/Contacts/Model/ContactFieldContainer.cpp

diff --git a/lib-contacts/inc/Contacts/Details/GroupsFieldItem.h b/lib-contacts/inc/Contacts/Details/GroupsFieldItem.h
new file mode 100644 (file)
index 0000000..bc095ed
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015 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_DETAILS_GROUPS_FIELD_ITEM_H
+#define CONTACTS_DETAILS_GROUPS_FIELD_ITEM_H
+
+#include "Contacts/Details/FieldItem.h"
+#include <string>
+
+namespace Contacts
+{
+       namespace Details
+       {
+               /**
+                * @brief Genlist item representing Groups field.
+                */
+               class GroupsFieldItem : public FieldItem
+               {
+               public:
+                       using FieldItem::FieldItem;
+
+               protected:
+                       /**
+                        * @see GenlistItem::getText()
+                        */
+                       virtual char *getText(Evas_Object *parent, const char *part) override;
+
+               private:
+                       std::string formatGroups() const;
+               };
+       }
+}
+
+#endif /* CONTACTS_DETAILS_GROUPS_FIELD_ITEM_H */
index bb42a37..f75d5f7 100644 (file)
@@ -80,7 +80,7 @@ namespace Contacts
                protected:
                        ContactField &addField(contacts_record_h record,
                                        const ContactFieldMetadata &metadata);
-                       void removeField(ContactField &field);
+                       ContactFieldPtr removeField(ContactField &field);
 
                private:
                        friend ContactField;
index 5adfcf1..56d7fcf 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "Contacts/Details/DetailsView.h"
 #include "Contacts/Details/BasicInfoItem.h"
+#include "Contacts/Details/GroupsFieldItem.h"
 #include "Contacts/Details/MultilineFieldItem.h"
 #include "Contacts/Details/RingtoneFieldItem.h"
 #include "Contacts/Details/TypedActionFieldItem.h"
@@ -63,7 +64,7 @@ namespace
                /* [FieldNickname]     = */ true,
                /* [FieldRelationship] = */ true,
                /* [FieldRingtone]     = */ true,
-               /* [FieldGroups]       = */ false
+               /* [FieldGroups]       = */ true
        };
 }
 
@@ -194,6 +195,8 @@ FieldItem *DetailsView::createFieldItem(ContactObject &field)
                item = new FieldItem(field);
        } else if (fieldId == FieldRingtone) {
                item = new RingtoneFieldItem(field);
+       } else if (fieldId == FieldGroups) {
+               item = new GroupsFieldItem(field);
        } else if (field.getInterfaces() & InterfaceTypedObject) {
                item = new TypedFieldItem(field);
        } else {
diff --git a/lib-contacts/src/Contacts/Details/GroupsFieldItem.cpp b/lib-contacts/src/Contacts/Details/GroupsFieldItem.cpp
new file mode 100644 (file)
index 0000000..a0cdf63
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015 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/Details/GroupsFieldItem.h"
+#include "Contacts/Model/ContactArray.h"
+#include "Contacts/Model/ContactObject.h"
+#include "Common/Database/RecordUtils.h"
+
+#include <app_i18n.h>
+
+using namespace Common::Database;
+using namespace Contacts::Details;
+using namespace Contacts::Model;
+
+char *GroupsFieldItem::getText(Evas_Object *parent, const char *part)
+{
+       if (strcmp(part, "elm.text") == 0) {
+               std::string groups = formatGroups();
+               return strdup(!groups.empty() ? groups.c_str() : _("IDS_PB_BODY_NOT_ASSIGNED"));
+       }
+
+       return FieldItem::getText(parent, part);
+}
+
+std::string GroupsFieldItem::formatGroups() const
+{
+       std::string groups;
+       for (auto &&field : *getObject().getField<ContactArray>(0)) {
+               const char *name = getRecordStr(field.getRecord(), _contacts_group_relation.name);
+               if (!groups.empty()) {
+                       groups.append(", ");
+               }
+               groups.append(name);
+       }
+
+       return groups;
+}
index 88fed54..3b42980 100644 (file)
@@ -95,8 +95,8 @@ void ContactArray::onUpdate(contacts_record_h record)
        }
 
        while (fieldIt != end()) {
-               fieldIt->update(nullptr);
-               ContactFieldContainer::removeField(*fieldIt);
+               auto field = ContactFieldContainer::removeField(*fieldIt);
+               field->update(nullptr);
        }
 
        while (recordIt != recordEnd) {
index a381fec..57915f4 100644 (file)
@@ -126,6 +126,9 @@ void ContactField::onUpdated(ContactField &field, contacts_changed_e change)
        }
 
        if (m_Parent) {
+               if (&field != this) {
+                       change = CONTACTS_CHANGE_UPDATED;
+               }
                m_Parent->onChildUpdated(*this, change);
        }
 }
index d5703d8..a5aa2e4 100644 (file)
@@ -81,17 +81,24 @@ ContactField &ContactFieldContainer::addField(contacts_record_h record,
        return *m_Fields.back();
 }
 
-void ContactFieldContainer::removeField(ContactField &field)
+ContactFieldPtr ContactFieldContainer::removeField(ContactField &field)
 {
-       auto comp = [&field](ContactFieldPtr &ptr) {
-               return ptr.get() == &field;
-       };
-
        if (field.isFilled()) {
                onChildFilled(field, false);
        }
 
-       m_Fields.erase(std::remove_if(m_Fields.begin(), m_Fields.end(), comp), m_Fields.end());
+       auto it = std::find_if(m_Fields.begin(), m_Fields.end(),
+               [&field](ContactFieldPtr &fieldPtr) {
+                       return fieldPtr.get() == &field;
+               });
+
+       if (it != m_Fields.end()) {
+               auto fieldPtr = std::move(*it);
+               m_Fields.erase(it);
+               return fieldPtr;
+       }
+
+       return nullptr;
 }
 
 void ContactFieldContainer::onChildUpdated(ContactField &field, contacts_changed_e change)