TizenRefApp-6971 Implement chooser popup to select number or email for Multi Chooser... 28/85628/3
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Fri, 26 Aug 2016 09:58:00 +0000 (12:58 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 26 Aug 2016 13:18:00 +0000 (06:18 -0700)
Change-Id: Ie901a8b82cc42978ea6fa9606ffb254b435c9838
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-contacts/inc/Contacts/Chooser/ChooserPopup.h [new file with mode: 0644]
lib-contacts/inc/Contacts/Chooser/ChooserView.h
lib-contacts/src/Contacts/Chooser/ChooserPopup.cpp [new file with mode: 0644]
lib-contacts/src/Contacts/Chooser/ChooserView.cpp

diff --git a/lib-contacts/inc/Contacts/Chooser/ChooserPopup.h b/lib-contacts/inc/Contacts/Chooser/ChooserPopup.h
new file mode 100644 (file)
index 0000000..0aa20ea
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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_CHOOSER_CHOOSER_POPUP_H
+#define CONTACTS_CHOOSER_CHOOSER_POPUP_H
+
+#include "Ui/ListPopup.h"
+#include "Ux/SelectTypes.h"
+#include "Contacts/Model/ContactObject.h"
+
+namespace Contacts
+{
+       namespace Chooser
+       {
+               /**
+                * @brief Provides ability to choose data from contact.
+                */
+               class ChooserPopup : public Ui::ListPopup
+               {
+               public:
+                       /**
+                        * @brief Create popup.
+                        * @param[in]   contactId   _contacts_contact record ID
+                        * @param[in]   filterType  Bitmask filter for contact fields
+                        * @see FilterType
+                        */
+                       explicit ChooserPopup(int contactId, int filterType);
+                       virtual ~ChooserPopup() override;
+
+                       /**
+                        * @brief Set selection callback.
+                        * @param[in]   callback    Item selection callback
+                        */
+                       void setSelectCallback(Ux::SelectCallback callback);
+
+               protected:
+                       virtual void onCreated() override;
+                       virtual char *getItemText(void *data, const char *part) override;
+                       virtual void onItemSelected(void *data) override;
+
+               private:
+                       Model::ContactObject m_Contact;
+                       contacts_record_h m_Record;
+                       int m_FilterType;
+                       Ux::SelectCallback m_OnSelected;
+               };
+       }
+}
+
+#endif /* CONTACTS_CHOOSER_CHOOSER_POPUP_H */
index cd278e4..1054e7e 100644 (file)
@@ -35,7 +35,7 @@ namespace Contacts
 
                /**
                 * @brief Controller and navigator for selecting different types of results
-                *        via ListView and DetailsView.
+                *        via ListView and GroupsView.
                 */
                class EXPORT_API ChooserView : public Ui::Naviframe
                {
diff --git a/lib-contacts/src/Contacts/Chooser/ChooserPopup.cpp b/lib-contacts/src/Contacts/Chooser/ChooserPopup.cpp
new file mode 100644 (file)
index 0000000..4cb1c13
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * 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/Chooser/ChooserPopup.h"
+#include "Contacts/Model/ContactArray.h"
+#include "Contacts/Model/ContactFieldMetadata.h"
+#include "Contacts/Model/ContactObject.h"
+#include "Contacts/Model/ContactTextField.h"
+#include "Contacts/Model/ContactTypedObject.h"
+#include "Contacts/Common/Strings.h"
+#include "Common/Strings.h"
+
+#include <app_i18n.h>
+
+using namespace Common;
+using namespace Contacts::Model;
+using namespace Contacts::Chooser;
+
+ChooserPopup::ChooserPopup(int contactId, int filterType)
+       : ListPopup("type2"),
+         m_Contact(nullptr, *getContactMetadata(ObjectTypeContact)),
+         m_FilterType(filterType)
+{
+       contacts_db_get_record(_contacts_contact._uri, contactId, &m_Record);
+       m_Contact.initialize(m_Record);
+}
+
+ChooserPopup::~ChooserPopup()
+{
+       contacts_record_destroy(m_Record, true);
+}
+
+void ChooserPopup::setSelectCallback(Ux::SelectCallback callback)
+{
+       m_OnSelected = std::move(callback);
+}
+
+void ChooserPopup::onCreated()
+{
+       setTitle(m_Contact.getFieldById<ContactTextField>(FieldDisplayName)->getValue());
+
+       for (auto &&field : m_Contact) {
+               if (!(m_FilterType & (1 << field.getSubType()))) {
+                       continue;
+               }
+
+               switch (field.getType()) {
+                       case TypeArray:
+                               for (auto &&element : field.cast<ContactArray>()) {
+                                       addItem(&element.cast<ContactObject>());
+                               }
+                               break;
+                       case TypeObject:
+                               if (!field.isEmpty()) {
+                                       addItem(&field.cast<ContactObject>());
+                               }
+                               break;
+                       default:
+                               break;
+               }
+       }
+}
+
+char *ChooserPopup::getItemText(void *data, const char *part)
+{
+       ContactObject &object = *(ContactObject *) data;
+       ContactField &field = *object.getField(0);
+       if (strcmp(part, "elm.text") == 0) {
+               if (field.getType() == TypeText) {
+                       return Utils::safeDup(field.cast<ContactTextField>().getValue());
+               }
+       } else if (strcmp(part, "elm.text.sub") == 0) {
+               const char *name = nullptr;
+               if (object.getInterfaces() & InterfaceTypedObject) {
+                       auto &typedObject = object.cast<ContactTypedObject>();
+                       auto &typeField = typedObject.getTypeField();
+                       auto &labelField = typedObject.getLabelField();
+
+                       if (typeField.hasCustomValue()) {
+                               name = labelField.getValue();
+                       } else {
+                               EnumType type = EnumType(typeField.getSubType());
+                               name = _(getEnumValueName(type, typeField.getValue()));
+                       }
+               } else {
+                       name = _(Common::getContactFieldName(ContactFieldId(object.getId())));
+               }
+
+               return Utils::safeDup(name);
+       }
+
+       return nullptr;
+}
+
+void ChooserPopup::onItemSelected(void *data)
+{
+       ContactObject &object = *(ContactObject *) data;
+       Ux::SelectResult result = { object.getSubType(), object.getRecordId() };
+       if (m_OnSelected) {
+               m_OnSelected({ result });
+       }
+}
index afbfabf..c6c7112 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include "Contacts/Chooser/ChooserView.h"
+#include "Contacts/Chooser/ChooserPopup.h"
 #include "Contacts/Chooser/ContactsGroupsNavigator.h"
 
 #include "Contacts/Groups/GroupsView.h"
@@ -25,8 +26,6 @@
 #include "Contacts/List/ListView.h"
 #include "Contacts/List/PersonItem.h"
 #include "Contacts/List/Model/Person.h"
-
-#include "Contacts/Details/DetailsView.h"
 #include "Contacts/Settings/ExportController.h"
 
 #include "Common/Actions.h"
@@ -47,7 +46,6 @@ using namespace Common::Database;
 using namespace Contacts;
 using namespace Contacts::Chooser;
 using namespace Contacts::List;
-using namespace Contacts::Details;
 using namespace Contacts::Groups;
 using namespace Contacts::Groups::Model;
 using namespace Ux;
@@ -331,11 +329,10 @@ bool ChooserView::selectSingleResult(SelectResult person, bool useDefault, Selec
                return callback({ result });
        }
 
-       DetailsView *view = new DetailsView(getDisplayContactId(person.value.id),
-                       DetailsView::Type(person.type), m_FilterType);
-       view->setSelectMode(SelectSingle);
-       view->setSelectCallback(callback);
-       getNavigator()->navigateTo(view);
+       auto popup = new ChooserPopup(getDisplayContactId(person.value.id), m_FilterType);
+       popup->create(getEvasObject());
+       popup->setSelectCallback(callback);
+       popup->show();
 
        return false;
 }