TizenRefApp-6088 Implement Search Item 06/65606/4
authorIryna Ferenchak <i.ferenchak@samsung.com>
Tue, 12 Apr 2016 13:19:44 +0000 (16:19 +0300)
committerIryna Ferenchak <i.ferenchak@samsung.com>
Tue, 12 Apr 2016 13:19:44 +0000 (16:19 +0300)
Change-Id: I3a60e54d539b575147ced0d517c6e21c2691e4f0
Signed-off-by: Iryna Ferenchak <i.ferenchak@samsung.com>
lib-contacts/inc/Contacts/List/ListView.h
lib-contacts/inc/Contacts/List/SearchItem.h [new file with mode: 0644]
lib-contacts/src/Contacts/List/ListView.cpp
lib-contacts/src/Contacts/List/SearchItem.cpp [new file with mode: 0644]

index 6aaedc9..f2300ad 100644 (file)
@@ -24,6 +24,7 @@
 #include "Ux/SelectView.h"
 #include "Utils/UniString.h"
 
+
 #include <map>
 
 namespace Ui
@@ -36,8 +37,11 @@ namespace Contacts
 {
        namespace List
        {
-               class PersonItem;
+               class GroupItem;
+               class SearchItem;
+               class SelectAllItem;
                class PersonGroupItem;
+               class PersonItem;
 
                /**
                 * @brief Contacts list view
@@ -96,6 +100,8 @@ namespace Contacts
                        void updatePageMode();
                        void updateSectionsMode();
 
+                       void createSearchItem();
+
                        void createAddButton();
                        void deleteAddButton();
 
@@ -133,6 +139,8 @@ namespace Contacts
                        Evas_Object *m_Index;
                        Evas_Object *m_AddButton;
 
+                       SearchItem *m_SearchItem;
+
                        Ui::GenlistGroupItem *m_Sections[SectionMax];
 
                        std::map<Utils::UniString, PersonGroupItem *> m_PersonGroups;
diff --git a/lib-contacts/inc/Contacts/List/SearchItem.h b/lib-contacts/inc/Contacts/List/SearchItem.h
new file mode 100644 (file)
index 0000000..f34a6bf
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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_LIST_CONTACT_SEARCH_ITEM_H
+#define CONTACTS_LIST_CONTACT_SEARCH_ITEM_H
+
+#include "Ui/GenlistItem.h"
+
+namespace Contacts
+{
+       namespace List
+       {
+               /**
+                * @brief Contact search item
+                */
+               class SearchItem : public Ui::GenlistItem
+               {
+               public:
+                       /**
+                        * @brief Entry change callback.
+                        */
+                       typedef std::function<void()> ChangeCallback;
+
+                       /**
+                        * @brief Set entry changed callback
+                        */
+                       void setChangeCallback(ChangeCallback callback);
+
+               private:
+                       virtual Elm_Genlist_Item_Class *getItemClass() const override;
+                       virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
+
+                       void onDonePressed(Evas_Object *entry, void *eventInfo);
+                       void onChanged(Evas_Object *entry, void *eventInfo);
+
+                       ChangeCallback m_OnChanged;
+               };
+       }
+}
+
+#endif /* CONTACTS_LIST_CONTACT_SEARCH_ITEM_H */
index 6b1d5f8..d6bdb53 100644 (file)
@@ -15,6 +15,7 @@
  *
  */
 
+#include "Contacts/List/SearchItem.h"
 #include "Contacts/List/ListView.h"
 #include "Contacts/List/GroupItem.h"
 #include "Contacts/List/ManageFavoritesPopup.h"
@@ -50,6 +51,7 @@ using namespace std::placeholders;
 ListView::ListView(int filterType)
        : m_Box(nullptr), m_NoContent(nullptr), m_Genlist(nullptr),
          m_Index(nullptr), m_AddButton(nullptr),
+         m_SearchItem(nullptr),
          m_Sections{ nullptr }, m_Provider(filterType)
 {
        auto strings = Common::getSelectViewStrings();
@@ -74,6 +76,8 @@ Evas_Object *ListView::onCreate(Evas_Object *parent)
        m_Genlist = createGenlist(m_Box);
        elm_box_pack_end(m_Box, m_Genlist->getEvasObject());
 
+       createSearchItem();
+
        elm_object_part_content_set(layout, "elm.swallow.content", m_Box);
        elm_object_part_content_set(layout, "elm.swallow.fastscroll", createIndex(layout));
 
@@ -168,7 +172,7 @@ void ListView::onShareSelected()
 
 void ListView::onSelectAllInsert(Ui::GenlistItem *item)
 {
-       m_Genlist->insert(item, nullptr, nullptr, Ui::Genlist::After);
+       m_Genlist->insert(item, nullptr, m_SearchItem, Ui::Genlist::After);
 }
 
 void ListView::onSelectModeChanged(SelectMode selectMode)
@@ -390,6 +394,13 @@ void ListView::updateSectionsMode()
        }
 }
 
+void ListView::createSearchItem()
+{
+       m_SearchItem = new SearchItem();
+       m_Genlist->insert(m_SearchItem, nullptr, nullptr, Ui::Genlist::After);
+       elm_genlist_item_select_mode_set(m_SearchItem->getObjectItem(), ELM_OBJECT_SELECT_MODE_NONE);
+}
+
 void ListView::createAddButton()
 {
        m_AddButton = elm_button_add(getEvasObject());
diff --git a/lib-contacts/src/Contacts/List/SearchItem.cpp b/lib-contacts/src/Contacts/List/SearchItem.cpp
new file mode 100644 (file)
index 0000000..9c59ddb
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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/List/SearchItem.h"
+#include "Ui/Editfield.h"
+#include "Utils/Callback.h"
+#include "Utils/Logger.h"
+
+using namespace Contacts::List;
+
+Evas_Object *SearchItem::getContent(Evas_Object *parent, const char *part)
+{
+       Ui::Editfield *searchField = Ui::Editfield::create(parent, "IDS_PB_NPBODY_SEARCH");
+
+       Evas_Object *entry = searchField->getEntry();
+       elm_entry_input_panel_return_key_autoenabled_set(entry, EINA_TRUE);
+       elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
+       evas_object_smart_callback_add(entry, "changed",
+                       makeCallback(&SearchItem::onChanged), this);
+       evas_object_smart_callback_add(entry, "activated",
+                       makeCallback(&SearchItem::onDonePressed), this);
+       return searchField->getEvasObject();
+}
+
+Elm_Genlist_Item_Class *SearchItem::getItemClass() const
+{
+       static Elm_Genlist_Item_Class itc = createItemClass("full");
+       return &itc;
+}
+
+void SearchItem::setChangeCallback(ChangeCallback callback)
+{
+       m_OnChanged = std::move(callback);
+}
+
+void SearchItem::onDonePressed(Evas_Object *entry, void *eventInfo)
+{
+       elm_object_focus_set(entry, EINA_FALSE);
+}
+
+void SearchItem::onChanged(Evas_Object *entry, void *eventInfo)
+{
+       if (m_OnChanged) {
+               m_OnChanged();
+       }
+}