TizenRefApp-5583 Implement Details view basic functionality (Fill, Edit, Delete,... 28/58228/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Thu, 28 Jan 2016 11:21:17 +0000 (13:21 +0200)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Thu, 28 Jan 2016 11:56:32 +0000 (13:56 +0200)
Change-Id: Ic60ec37cf5c4fac40b8d1eeb99abe87a06050bfb
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-common/inc/App/AppControlRequest.h
lib-common/src/App/AppControlRequest.cpp
lib-contact/inc/Contacts/Details/DetailsView.h [new file with mode: 0644]
lib-contact/src/Contacts/Details/DetailsView.cpp [new file with mode: 0644]
lib-contact/src/Contacts/List/ListView.cpp

index 38ea47b..ba83f80 100644 (file)
@@ -102,6 +102,20 @@ namespace App
        AppControl EXPORT_API requestGalleryImage();
 
        /**
+        * @brief Request share contact via other application
+        * @param[in]   personId    Contact's person ID
+        * @return AppControl wrapper
+        */
+       AppControl EXPORT_API requestShareContact(int personId);
+
+       /**
+        * @brief Request share "My Profile" via other application
+        * @param[in]   recordId    "My Profile" record ID
+        * @return AppControl wrapper
+        */
+       AppControl EXPORT_API requestShareMyProfile(int recordId);
+
+       /**
         * @brief Get single first string from App Control array extra data.
         * @param[in]   appControl  App Control handle
         * @param[in]   key         Extra data array key
index 931a677..51cd3ea 100644 (file)
@@ -84,6 +84,20 @@ AppControl App::requestGalleryImage()
        return AppControl(APP_CONTROL_OPERATION_PICK, "image/*");
 }
 
+AppControl App::requestShareContact(int personId)
+{
+       AppControl request(APP_CONTROL_OPERATION_SHARE, APP_CONTROL_MIME_CONTACT);
+       request.addExtra(APP_CONTROL_DATA_ID, std::to_string(personId).c_str());
+       return request;
+}
+
+AppControl App::requestShareMyProfile(int recordId)
+{
+       AppControl request = requestShareContact(recordId);
+       request.addExtra(APP_CONTROL_DATA_TYPE, "my_profile");
+       return request;
+}
+
 std::string App::getSingleExtraData(app_control_h appControl, const char *key)
 {
        std::string result;
diff --git a/lib-contact/inc/Contacts/Details/DetailsView.h b/lib-contact/inc/Contacts/Details/DetailsView.h
new file mode 100644 (file)
index 0000000..eb39a60
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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_DETAILS_VIEW_H
+#define CONTACTS_DETAILS_DETAILS_VIEW_H
+
+#include "App/AppControl.h"
+#include "Contacts/Model/Contact.h"
+#include "Ui/View.h"
+
+namespace Ui
+{
+       class Genlist;
+       class GenlistItem;
+}
+
+namespace Contacts
+{
+       namespace Details
+       {
+               /**
+                * @brief Contact/My profile details view.
+                */
+               class DetailsView : public Ui::View
+               {
+               public:
+                       /**
+                        * @brief Type of object to view.
+                        */
+                       enum Type
+                       {
+                               TypeContact = Model::ObjectTypeContact,
+                               TypeMyProfile = Model::ObjectTypeMyProfile
+                       };
+
+                       /**
+                        * @brief Create details view.
+                        * @param[in]   recordId    Contact or My Profile record ID
+                        * @param[in]   type        Type of viewed object
+                        */
+                       DetailsView(int recordId, Type type = TypeContact);
+
+               private:
+                       virtual Evas_Object *onCreate(Evas_Object *parent) override;
+                       virtual void onCreated() override;
+                       virtual void onPageAttached() override;
+                       virtual void onMenuPressed() override;
+
+                       Ui::GenlistItem *createFieldItem(Model::ContactObject &field);
+                       Ui::GenlistItem *addFieldItem(Model::ContactObject &field);
+
+                       int m_RecordId;
+                       Model::Contact m_Contact;
+                       Ui::Genlist *m_Genlist;
+                       App::AppControl m_AppControl;
+               };
+       }
+}
+
+#endif /* CONTACTS_DETAILS_DETAILS_VIEW_H */
diff --git a/lib-contact/src/Contacts/Details/DetailsView.cpp b/lib-contact/src/Contacts/Details/DetailsView.cpp
new file mode 100644 (file)
index 0000000..16f76d1
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * 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/DetailsView.h"
+#include "Contacts/Details/ActionFieldItem.h"
+#include "Contacts/Details/BasicInfoItem.h"
+#include "Contacts/Details/MultilineFieldItem.h"
+#include "Contacts/Input/InputView.h"
+#include "Contacts/Model/ContactArray.h"
+
+#include "App/AppControlRequest.h"
+#include "App/Path.h"
+#include "Ui/Genlist.h"
+#include "Ui/Menu.h"
+#include "Ui/Navigator.h"
+#include "Ui/Popup.h"
+#include "Utils/Logger.h"
+
+#include "DetailsItemLayout.h"
+
+using namespace Contacts::Details;
+using namespace Contacts::Model;
+
+namespace
+{
+       bool isFieldVisible[] = {
+               /* [FieldFavorite]     = */ false,
+               /* [FieldImage]        = */ false,
+               /* [FieldName]         = */ false,
+               /* [FieldPhoneticName] = */ false,
+               /* [FieldCompany]      = */ false,
+               /* [FieldNumber]       = */ true,
+               /* [FieldEmail]        = */ true,
+               /* [FieldAddress]      = */ true,
+               /* [FieldUrl]          = */ true,
+               /* [FieldMessenger]    = */ true,
+               /* [FieldEvent]        = */ true,
+               /* [FieldNote]         = */ true,
+               /* [FieldNickname]     = */ true,
+               /* [FieldRelationship] = */ true
+       };
+}
+
+DetailsView::DetailsView(int recordId, Type type)
+       : m_RecordId(recordId), m_Contact(ContactObjectType(type)),
+         m_Genlist(nullptr)
+{
+}
+
+Evas_Object *DetailsView::onCreate(Evas_Object *parent)
+{
+       elm_theme_extension_add(nullptr, App::getResourcePath(DETAILS_ITEM_LAYOUT_EDJ).c_str());
+
+       m_Genlist = new Ui::Genlist();
+       return m_Genlist->create(parent);
+}
+
+void DetailsView::onCreated()
+{
+       int err = m_Contact.initialize(m_RecordId);
+       RETM_IF_ERR(err, "Contact::initialize() failed.");
+
+       BasicInfoItem *item = new BasicInfoItem(m_Contact);
+       m_Genlist->insert(item);
+
+       for (auto &&field : m_Contact) {
+               ContactFieldId fieldId = ContactFieldId(field.getId());
+               if (!isFieldVisible[fieldId]) {
+                       continue;
+               }
+
+               switch (field.getType()) {
+                       case TypeArray:
+                               for (auto &&element : field.cast<ContactArray>()) {
+                                       addFieldItem(element.cast<ContactObject>());
+                               }
+                               break;
+                       case TypeObject:
+                               if (!field.isEmpty()) {
+                                       addFieldItem(field.cast<ContactObject>());
+                               }
+                               break;
+                       default:
+                               break;
+               }
+       }
+}
+
+void DetailsView::onPageAttached()
+{
+       /* FIXME: Disable naviframe item title by default */
+       getPage()->setTitle(nullptr);
+}
+
+void DetailsView::onMenuPressed()
+{
+       Ui::Menu *menu = new Ui::Menu();
+       menu->create(getEvasObject());
+
+       menu->addItem("IDS_PB_OPT_EDIT", [this] {
+               auto type = (Input::InputView::Type) m_Contact.getSubType();
+               getNavigator()->navigateTo(new Input::InputView(m_RecordId, type));
+       });
+       menu->addItem("IDS_PB_BUTTON_DELETE_ABB4", [this] {
+               Ui::Popup *popup = new Ui::Popup();
+               popup->create(getEvasObject());
+               popup->setTitle("IDS_PB_BUTTON_DELETE_ABB4");
+               popup->setText("IDS_PB_POP_THIS_CONTACT_WILL_BE_DELETED");
+               popup->addButton("IDS_PB_BUTTON_CANCEL");
+               popup->addButton("IDS_PB_BUTTON_DELETE_ABB4", [this] {
+                       m_Contact.remove();
+                       delete this;
+                       return true;
+               });
+       });
+       menu->addItem("IDS_PB_OPT_SHARE", [this] {
+               if (m_Contact.getSubType() == ObjectTypeContact) {
+                       int personId = 0;
+                       contacts_record_get_int(m_Contact.getRecord(), _contacts_contact.person_id, &personId);
+                       m_AppControl = App::requestShareContact(personId);
+               } else {
+                       m_AppControl = App::requestShareMyProfile(m_Contact.getRecordId());
+               }
+
+               m_AppControl.launch();
+       });
+
+       menu->show();
+}
+
+Ui::GenlistItem *DetailsView::createFieldItem(ContactObject &field)
+{
+       Ui::GenlistItem *item = nullptr;
+       ContactFieldId fieldId = ContactFieldId(field.getId());
+
+       if (fieldId == FieldNumber) {
+               item = new ActionFieldItem(field, ActionFieldItem::ActionCall);
+       } else if (fieldId == FieldEmail) {
+               item = new ActionFieldItem(field, ActionFieldItem::ActionComposeEmail);
+       } else if (fieldId == FieldUrl) {
+               item = new ActionFieldItem(field, ActionFieldItem::ActionOpenWebpage);
+       } else if (fieldId == FieldNote) {
+               item = new MultilineFieldItem(field);
+       } else if (field.getSubType() & ObjectTyped) {
+               item = new TypedFieldItem(field);
+       } else {
+               item = new FieldItem(field);
+       }
+
+       return item;
+}
+
+Ui::GenlistItem *DetailsView::addFieldItem(ContactObject &field)
+{
+       Ui::GenlistItem *item = createFieldItem(field);
+       m_Genlist->insert(item);
+       return item;
+}
index 17289f0..d257dc4 100644 (file)
@@ -20,6 +20,7 @@
 #include "Contacts/List/MyProfileItem.h"
 #include "Contacts/List/PersonGroupItem.h"
 #include "Contacts/Input/InputView.h"
+#include "Contacts/Details/DetailsView.h"
 #include "Contacts/Settings/MainView.h"
 
 #include "Ui/Genlist.h"
@@ -312,7 +313,11 @@ void ListView::updateMyProfileItem(const char *view_uri)
 
        item->setSelectedCallback([this, item]() {
                int id = item->getMyProfile().getId();
-               getNavigator()->navigateTo(new Input::InputView(id, Input::InputView::TypeMyProfile));
+               if (id > 0) {
+                       getNavigator()->navigateTo(new Details::DetailsView(id, Details::DetailsView::TypeMyProfile));
+               } else {
+                       getNavigator()->navigateTo(new Input::InputView(id, Input::InputView::TypeMyProfile));
+               }
        });
 }
 
@@ -477,8 +482,7 @@ void ListView::launchPersonDetail(PersonItem *item)
 {
        int id = 0;
        contacts_record_get_int(item->getPerson().getRecord(), _contacts_person.display_contact_id, &id);
-
-       getNavigator()->navigateTo(new Input::InputView(id));
+       getNavigator()->navigateTo(new Details::DetailsView(id));
 }
 
 void ListView::onIndexChanged(Evas_Object *index, Elm_Object_Item *indexItem)