Replaced box with custom layout in ListView. 18/94318/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Fri, 28 Oct 2016 07:21:27 +0000 (10:21 +0300)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Fri, 28 Oct 2016 12:07:27 +0000 (15:07 +0300)
Refactored layout creation and empty state.

Change-Id: I369c07978d23509e7240912d766aeb9df0cebed2
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-contacts/inc/Contacts/List/ListView.h
lib-contacts/project_def.prop
lib-contacts/res/list/CMakeLists.txt
lib-contacts/res/list/edje/ListLayout.h [new file with mode: 0644]
lib-contacts/res/list/edje/ListPath.h
lib-contacts/res/list/edje/list-layout.edc [new file with mode: 0644]
lib-contacts/src/Contacts/Groups/MembersListView.cpp
lib-contacts/src/Contacts/List/ListView.cpp

index 99ca999..22dc789 100644 (file)
@@ -128,9 +128,9 @@ namespace Contacts
                        virtual void onUpdateFinished();
 
                        /**
-                        * @return True if list is empty, false - otherwise
+                        * @return Whether list is empty due to no contacts or empty search result.
                         */
-                       bool isListEmpty();
+                       bool isEmpty();
 
                private:
                        struct Section
@@ -171,9 +171,7 @@ namespace Contacts
                        bool getSectionVisibility(SectionId sectionId);
 
                        void fillLayout();
-                       Evas_Object *createListLayout(Evas_Object *parent);
-                       Ui::Genlist *createGenlist(Evas_Object *parent);
-                       Evas_Object *createEmptyLayout(Evas_Object *parent);
+                       Evas_Object *createContent(Evas_Object *parent);
                        SearchField *createSearchField(Evas_Object *parent);
                        Evas_Object *createAddButton(Evas_Object *parent);
 
@@ -204,7 +202,7 @@ namespace Contacts
                        void onSectionUpdated(ContactItem *item, ::Model2::ChangeType change, SectionId sectionId);
                        void onSearchChanged(const char *str);
 
-                       Evas_Object *m_ListLayout;
+                       Evas_Object *m_Content;
                        Evas_Object *m_NoContent;
                        Ui::Genlist *m_Genlist;
                        ListIndex   *m_Index;
@@ -214,7 +212,6 @@ namespace Contacts
                        std::string m_NoContentHelpText;
 
                        bool m_IsSearching;
-                       bool m_IsEmpty;
                        bool m_HasAddButton;
                        std::vector<State> m_StateHistory;
 
index 6a75eef..1ffffe4 100644 (file)
@@ -60,7 +60,7 @@ USER_EDCS_FONT_DIRS_ABS =
 # EDC Flags
 USER_EXT_EDC_KEYS = EDC0
 
-USER_EXT_EDC0_EDCS = res/groups/edje/group-item-layout.edc res/input/edje/input-item-layout.edc res/list/edje/chooser-title-layout.edc
+USER_EXT_EDC0_EDCS = res/groups/edje/group-item-layout.edc res/input/edje/input-item-layout.edc res/list/edje/chooser-title-layout.edc res/list/edje/list-layout.edc
 USER_EXT_EDC0_EDCS_IMAGE_DIRS = edje
 USER_EXT_EDC0_EDCS_IMAGE_DIRS_ABS =
 USER_EXT_EDC0_EDCS_SOUND_DIRS = edje
index c4d32d2..c77a585 100644 (file)
@@ -1,4 +1,4 @@
-set(EDC_FILES chooser-title-layout.edc)
+set(EDC_FILES chooser-title-layout.edc list-layout.edc)
 set(EDJ_DIR "${RES_DIR}/list/edje")
 set(IMG_DIR "${RES_DIR}/list/images")
 
diff --git a/lib-contacts/res/list/edje/ListLayout.h b/lib-contacts/res/list/edje/ListLayout.h
new file mode 100644 (file)
index 0000000..d4fc359
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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 LIST_LAYOUT_H
+#define LIST_LAYOUT_H
+
+#include "ListPath.h"
+
+#define LAYOUT_LIST             "list"
+#define PART_SEARCH             "swallow.search"
+#define PART_CONTENT            "swallow.content"
+#define PART_NO_CONTENTS        "swallow.no_contents"
+
+#define SIGNAL_CONTENT_COMPRESS "state,swallow.content,default"
+#define SIGNAL_CONTENT_EXPAND   "state,swallow.content,expanded"
+
+#endif /* LIST_LAYOUT_H */
index eef4144..15b35b0 100644 (file)
@@ -21,7 +21,8 @@
 #define LIST_IMG_DIR "list/images/"
 #define LIST_EDJ_DIR "list/edje/"
 
-#define LIST_ADD_BUTTON_ICON    LIST_IMG_DIR"core_floating_icon_01.png"
+#define LIST_LAYOUT_EDJ         LIST_EDJ_DIR"list-layout.edj"
 #define CHOOSER_TITLE_EDJ       LIST_EDJ_DIR"chooser-title-layout.edj"
+#define LIST_ADD_BUTTON_ICON    LIST_IMG_DIR"core_floating_icon_01.png"
 
 #endif /* LIST_PATH_H */
diff --git a/lib-contacts/res/list/edje/list-layout.edc b/lib-contacts/res/list/edje/list-layout.edc
new file mode 100644 (file)
index 0000000..95df9fe
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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 "ListLayout.h"
+
+#define SEARCH_DIVIDER_H 2
+
+color_classes {
+       color_class {
+               name: "search_divider";
+               color: 61 185 204 38;
+       }
+}
+
+collections {
+       base_scale: 2.6;
+
+       group { LAYOUT_LIST;
+               parts {
+                       swallow { PART_SEARCH;
+                               desc { "default";
+                                       align: 0.5 0.0;
+                                       rel2.relative: 1.0 0.0;
+                               }
+                       }
+                       rect { "rect.search_divider"; scale;
+                               after: PART_CONTENT;
+                               desc { "default";
+                                       align: 0.5 0.0;
+                                       min: 0 SEARCH_DIVIDER_H;
+                                       rel1 { relative: 0.0 1.0; to_y: PART_SEARCH; }
+                                       rel2 { relative: 1.0 1.0; to_y: PART_SEARCH; }
+                                       color_class: "search_divider";
+                               }
+                       }
+                       swallow { PART_CONTENT;
+                               desc { "default";
+                                       align: 0.5 0.0;
+                                       rel1 { relative: 0.0 1.0; to_y: PART_SEARCH; }
+                                       rel2 { relative: 1.0 1.0; to_y: PART_SEARCH; }
+                               }
+                               desc { "expanded";
+                                       inherit: "default";
+                                       rel2.to_y: "";
+                               }
+                       }
+                       swallow { PART_NO_CONTENTS;
+                               desc { "default";
+                                       align: 0.5 0.0;
+                                       rel1 { relative: 0.0 1.0; to_y: PART_CONTENT; }
+                               }
+                               desc { "hidden";
+                                       inherit: "default";
+                                       visible: 0;
+                               }
+                       }
+               }
+               programs {
+                       program {
+                               signal: SIGNAL_CONTENT_COMPRESS;
+                               source: "*";
+                               script {
+                                       set_state(PART:PART_CONTENT, "default", 0.0);
+                                       set_state(PART:PART_NO_CONTENTS, "default", 0.0);
+                               }
+                       }
+                       program {
+                               signal: SIGNAL_CONTENT_EXPAND;
+                               source: "*";
+                               script {
+                                       set_state(PART:PART_CONTENT, "expanded", 0.0);
+                                       set_state(PART:PART_NO_CONTENTS, "hidden", 0.0);
+                               }
+                       }
+               }
+       }
+}
index 849aa4f..24dcc72 100644 (file)
@@ -103,7 +103,7 @@ void MembersListView::onMenuPressed()
 
        menu->addItem("IDS_PB_OPT_ADD", std::bind(&MembersListView::onAddSelected, this));
 
-       if (!isListEmpty()) {
+       if (!isEmpty()) {
                menu->addItem("IDS_PB_OPT_REMOVE",
                                std::bind(&MembersListView::onRemoveSelected, this));
                menu->addItem("IDS_PB_OPT_SEND_MESSAGE_ABB2",
index fd9cdb0..229e9e6 100644 (file)
@@ -48,7 +48,7 @@
 #include "Utils/Range.h"
 #include "Utils/Thread.h"
 
-#include "ListPath.h"
+#include "ListLayout.h"
 #include <algorithm>
 #include <efl_extension.h>
 
@@ -64,10 +64,10 @@ using namespace std::placeholders;
 #define SYMBOL_STAR "\uf896"
 
 ListView::ListView(Model::PersonProvider *provider)
-       : m_ListLayout(nullptr), m_NoContent(nullptr), m_Genlist(nullptr),
+       : m_Content(nullptr), m_NoContent(nullptr), m_Genlist(nullptr),
          m_Index(nullptr), m_SearchField(nullptr), m_AddButton(nullptr),
          m_NoContentHelpText("IDS_PB_BODY_AFTER_YOU_CREATE_CONTACTS_THEY_WILL_BE_SHOWN_HERE"),
-         m_IsSearching(false), m_IsEmpty(true), m_HasAddButton(true),
+         m_IsSearching(false), m_HasAddButton(true),
          m_PersonProvider(provider),
          m_SearchProvider(new SearchProvider(*m_PersonProvider, PersonComparator()))
 {
@@ -154,14 +154,14 @@ void ListView::onUpdateFinished()
        }
 }
 
-bool ListView::isListEmpty()
+bool ListView::isEmpty()
 {
-       return m_IsEmpty;
+       return m_IsSearching ? m_SearchProvider->empty() : m_PersonGroups.empty();;
 }
 
 Evas_Object *ListView::onCreate(Evas_Object *parent)
 {
-       return elm_box_add(parent);
+       return elm_layout_add(parent);
 }
 
 void ListView::onCreated()
@@ -188,7 +188,7 @@ void ListView::onNavigation(bool isCurrent)
        updateAddButton();
        setUpdateEnabled(isCurrent);
 
-       elm_object_focus_set(m_ListLayout, EINA_TRUE);
+       elm_object_focus_set(m_Content, EINA_TRUE);
 }
 
 bool ListView::onBackPressed()
@@ -208,7 +208,7 @@ bool ListView::onBackPressed()
 
 void ListView::onMenuPressed()
 {
-       if (getSelectMode() != SelectNone || (m_IsSearching && m_IsEmpty)) {
+       if (getSelectMode() != SelectNone || (m_IsSearching && isEmpty())) {
                return;
        }
 
@@ -221,7 +221,7 @@ void ListView::onMenuPressed()
                });
        }
 
-       if (!m_IsEmpty) {
+       if (!isEmpty()) {
                menu->addItem("IDS_PB_OPT_DELETE", std::bind(&ListView::onDeleteSelected, this));
                menu->addItem("IDS_PB_OPT_SHARE", std::bind(&ListView::onShareSelected, this));
 
@@ -466,59 +466,37 @@ bool ListView::getSectionVisibility(SectionId sectionId)
 
 void ListView::fillLayout()
 {
-       Evas_Object *box = getEvasObject();
-       evas_object_smart_callback_add(box, "language,changed",
+       Evas_Object *layout = getEvasObject();
+       elm_layout_file_set(layout, App::getResourcePath(LIST_LAYOUT_EDJ).c_str(), LAYOUT_LIST);
+       evas_object_smart_callback_add(layout, "language,changed",
                        makeCallback(&ListView::onLanguageChanged), this);
 
-       m_ListLayout = createListLayout(box);
-       elm_box_pack_end(box, m_ListLayout);
+       elm_object_part_content_set(layout, PART_CONTENT, createContent(layout));
 
-       m_Index = new ListIndex();
-       m_Index->setUpdateCallback(std::bind(&ListView::onIndexUpdated, this));
-       elm_object_part_content_set(m_ListLayout, "elm.swallow.fastscroll", m_Index->create(m_ListLayout));
-
-       m_Genlist = createGenlist(m_ListLayout);
-       elm_object_part_content_set(m_ListLayout, "elm.swallow.content", m_Genlist->getEvasObject());
+       m_NoContent =  elm_layout_add(layout);
+       elm_layout_theme_set(m_NoContent, "layout", "nocontents", "default");
+       elm_object_part_content_set(layout, PART_NO_CONTENTS, m_NoContent);
 
-       m_NoContent = createEmptyLayout(box);
-       elm_box_pack_end(box, m_NoContent);
+       m_SearchField = createSearchField(layout);
+       m_AddButton = createAddButton(layout);
 
-       m_SearchField = createSearchField(box);
-       m_AddButton = createAddButton(box);
-
-       elm_object_focus_custom_chain_set(box, eina_list_append(nullptr, m_ListLayout));
+       elm_object_focus_custom_chain_set(layout, eina_list_append(nullptr, m_Content));
 }
 
-Evas_Object *ListView::createListLayout(Evas_Object *parent)
+Evas_Object *ListView::createContent(Evas_Object *parent)
 {
-       Evas_Object *layout = elm_layout_add(parent);
-       elm_layout_theme_set(layout, "layout", "application", "fastscroll");
-       elm_layout_signal_emit(layout, "elm,state,fastscroll,hide", "");
-
-       evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0.0);
-       evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 0.0);
-       evas_object_show(layout);
-       return layout;
-}
+       m_Content = elm_layout_add(parent);
+       elm_layout_theme_set(m_Content, "layout", "application", "fastscroll");
+       elm_layout_signal_emit(m_Content, "elm,state,fastscroll,hide", "");
 
-Ui::Genlist *ListView::createGenlist(Evas_Object *parent)
-{
-       auto genlist = new Ui::Genlist();
-       genlist->create(parent);
-       elm_scroller_content_min_limit(genlist->getEvasObject(), EINA_FALSE, EINA_TRUE);
-       return genlist;
-}
-
-Evas_Object *ListView::createEmptyLayout(Evas_Object *parent)
-{
-       Evas_Object *layout = elm_layout_add(parent);
-       elm_layout_theme_set(layout, "layout", "nocontents", "default");
+       m_Index = new ListIndex();
+       m_Index->setUpdateCallback(std::bind(&ListView::onIndexUpdated, this));
+       elm_object_part_content_set(m_Content, "elm.swallow.fastscroll", m_Index->create(m_Content));
 
-       evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-       evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
-       evas_object_show(layout);
+       m_Genlist = new Ui::Genlist();
+       elm_object_part_content_set(m_Content, "elm.swallow.content", m_Genlist->create(m_Content));
 
-       return layout;
+       return m_Content;
 }
 
 SearchField *ListView::createSearchField(Evas_Object *parent)
@@ -526,9 +504,6 @@ SearchField *ListView::createSearchField(Evas_Object *parent)
        auto control = new SearchField();
        control->setChangeCallback(std::bind(&ListView::onSearchChanged, this, _1));
        control->create(parent);
-
-       evas_object_size_hint_weight_set(control->getEvasObject(), EVAS_HINT_EXPAND, 0.0);
-       evas_object_size_hint_align_set(control->getEvasObject(), EVAS_HINT_FILL, 0.0);
        return control;
 }
 
@@ -565,32 +540,11 @@ void ListView::setState(State state, bool isEnabled)
 
 void ListView::updateEmptyState()
 {
-       bool isEmpty = m_IsSearching ? m_SearchProvider->empty() : m_PersonGroups.empty();
-
        updateIndex();
        updateSearchField();
 
-       if (isEmpty == m_IsEmpty) {
-               return;
-       }
-
-       Evas_Object *genlist = m_Genlist->getEvasObject();
-       if (isEmpty) {
-               elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
-               evas_object_size_hint_weight_set(m_ListLayout, EVAS_HINT_EXPAND, 0.0);
-               evas_object_size_hint_align_set(m_ListLayout, EVAS_HINT_FILL, 0.0);
-
-               evas_object_show(m_NoContent);
-               elm_box_pack_end(getEvasObject(), m_NoContent);
-       } else {
-               elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_FALSE);
-               evas_object_size_hint_weight_set(m_ListLayout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-               evas_object_size_hint_align_set(m_ListLayout, EVAS_HINT_FILL, EVAS_HINT_FILL);
-
-               evas_object_hide(m_NoContent);
-               elm_box_unpack(getEvasObject(), m_NoContent);
-       }
-       m_IsEmpty = isEmpty;
+       elm_scroller_content_min_limit(m_Genlist->getEvasObject(), EINA_FALSE, isEmpty());
+       elm_layout_signal_emit(getEvasObject(), isEmpty() ? SIGNAL_CONTENT_COMPRESS : SIGNAL_CONTENT_EXPAND, "");
 }
 
 void ListView::updateEmptyLayout()
@@ -614,7 +568,7 @@ void ListView::updateIndex()
        }
 
        const char *signal = isVisible ? "elm,state,fastscroll,show" : "elm,state,fastscroll,hide";
-       elm_layout_signal_emit(m_ListLayout, signal, "");
+       elm_layout_signal_emit(m_Content, signal, "");
        if (isVisible) {
                elm_index_level_go(m_Index->getEvasObject(), 0);
        }
@@ -641,12 +595,10 @@ void ListView::updateSearchField()
                return;
        }
 
-       if (isEmpty) {
-               elm_box_unpack(getEvasObject(), searchField);
-               evas_object_hide(searchField);
+       if (!isEmpty) {
+               elm_object_part_content_set(getEvasObject(), PART_SEARCH, searchField);
        } else {
-               elm_box_pack_start(getEvasObject(), searchField);
-               evas_object_show(searchField);
+               evas_object_hide(elm_object_part_content_unset(getEvasObject(), PART_SEARCH));
        }
 }