TizenRefApp-5056 Implement SortBy Setting genlist Item 69/52669/4
authorIryna Ferenchak <i.ferenchak@samsung.com>
Thu, 26 Nov 2015 08:58:57 +0000 (10:58 +0200)
committerIryna Ferenchak <i.ferenchak@samsung.com>
Thu, 26 Nov 2015 08:58:57 +0000 (10:58 +0200)
Change-Id: Iec4e909463088f31bd21261a7934909ca120ceff
Signed-off-by: Iryna Ferenchak <i.ferenchak@samsung.com>
lib-contact/inc/Contacts/List/MainView.h
lib-contact/inc/Contacts/Settings/MainView.h [new file with mode: 0644]
lib-contact/inc/Contacts/Settings/SortByItem.h [new file with mode: 0644]
lib-contact/inc/Contacts/Settings/SortByPopup.h [new file with mode: 0644]
lib-contact/src/Contacts/List/MainView.cpp
lib-contact/src/Contacts/Settings/MainView.cpp [new file with mode: 0644]
lib-contact/src/Contacts/Settings/SortByItem.cpp [new file with mode: 0644]
lib-contact/src/Contacts/Settings/SortByPopup.cpp [new file with mode: 0644]

index afa05a112492f489919eb60c9dd8a0f995eedd28..f187bb3aab67037fb0c3b4bbfd140ca4f507c30c 100644 (file)
@@ -53,6 +53,7 @@ namespace Contacts
                        void onIndexSelected(Evas_Object *index, Elm_Object_Item *indexItem);
                        void onCreatePressed();
                        void onDatabaseChanged(const char *uri);
+                       virtual Evas_Object *onMenuPressed() override;
 
                        Ui::Genlist *m_Genlist;
                        Evas_Object *m_Index;
diff --git a/lib-contact/inc/Contacts/Settings/MainView.h b/lib-contact/inc/Contacts/Settings/MainView.h
new file mode 100644 (file)
index 0000000..65bf82a
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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_SETTINGS_MAIN_VIEW_H
+#define CONTACTS_SETTINGS_MAIN_VIEW_H
+
+#include "Ui/View.h"
+
+namespace Ui
+{
+       class Genlist;
+}
+
+namespace Contacts
+{
+       namespace Settings
+       {
+               /**
+                * @brief Settings main view
+                */
+               class MainView : public Ui::View
+               {
+               public:
+                       MainView();
+
+               private:
+                       virtual Evas_Object *onCreate(Evas_Object *parent) override;
+                       virtual void onPageAttached() override;
+
+                       Ui::Genlist *m_Genlist;
+               };
+       }
+}
+
+#endif /* CONTACTS_SETTINGS_MAIN_VIEW_H */
diff --git a/lib-contact/inc/Contacts/Settings/SortByItem.h b/lib-contact/inc/Contacts/Settings/SortByItem.h
new file mode 100644 (file)
index 0000000..10178ab
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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_SETTINGS_SORT_BY_ITEM_H
+#define CONTACTS_SETTINGS_SORT_BY_ITEM_H
+
+#include "Ui/GenlistItem.h"
+#include <contacts_setting.h>
+
+namespace Contacts
+{
+       namespace Settings
+       {
+               /**
+                * @brief SortBy item
+                */
+               class SortByItem : public Ui::GenlistItem
+               {
+               public:
+                       SortByItem();
+                       virtual ~SortByItem() override;
+
+               private:
+                       virtual char *getText(Evas_Object *parent, const char *part) override;
+                       virtual void onSelected() override;
+                       static void onSortingOrderChanged(contacts_name_sorting_order_e name_sorting_order, void *user_data);
+               };
+       }
+}
+
+#endif /* CONTACTS_SETTINGS_SORT_BY_ITEM_H */
diff --git a/lib-contact/inc/Contacts/Settings/SortByPopup.h b/lib-contact/inc/Contacts/Settings/SortByPopup.h
new file mode 100644 (file)
index 0000000..b1d519a
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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_SETTINGS_SORT_BY_POPUP_H
+#define CONTACTS_SETTINGS_SORT_BY_POPUP_H
+
+#include "Ui/Popup.h"
+
+namespace Contacts
+{
+       namespace Settings
+       {
+               /**
+                * @brief SortBy popup
+                */
+               class SortByPopup : public Ui::Popup
+               {
+               public:
+                       /**
+                        * @brief Create sortby popup.
+                        */
+                       SortByPopup();
+
+               private:
+                       virtual void onCreated() override;
+                       Evas_Object *createGenlist(Evas_Object *parent);
+                       static void onSelect(void *data, Evas_Object *obj, void *event_info);
+                       static char *getItemText(void *data, Evas_Object *obj, const char *part);
+                       Elm_Genlist_Item_Class *createItemClass();
+                       static Evas_Object *getItemContent(void *data, Evas_Object *obj, const char *part);
+
+                       Evas_Object *m_RadioGroup;
+               };
+       }
+}
+#endif /* CONTACTS_SETTINGS_SORT_BY_POPUP_H */
index 962eb598716a274806669de2a3a2534dc976985d..de3463d219dcb37d4437b222c941e64c6c6b08e3 100644 (file)
 #include "Ui/GenlistItem.h"
 #include "Utils/Callback.h"
 #include "Utils/Logger.h"
-
+#include "Ui/Menu.h"
+#include "Ui/Navigator.h"
+#include "Contacts/Settings/MainView.h"
 #include <contacts.h>
 
+using namespace Contacts;
 using namespace Contacts::List;
 
 MainView::MainView()
@@ -138,3 +141,14 @@ void MainView::onDatabaseChanged(const char *uri)
        elm_genlist_clear(m_Genlist->getEvasObject());
        fillList();
 }
+
+Evas_Object *MainView::onMenuPressed()
+{
+       Ui::Menu *menu = new Ui::Menu();
+       menu->create(getEvasObject());
+
+       menu->addItem("IDS_PB_OPT_SETTINGS", [this] {
+               getNavigator()->navigateTo(new Settings::MainView());
+       });
+       return menu->getEvasObject();
+}
diff --git a/lib-contact/src/Contacts/Settings/MainView.cpp b/lib-contact/src/Contacts/Settings/MainView.cpp
new file mode 100644 (file)
index 0000000..3842000
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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/Settings/MainView.h"
+#include "Contacts/Settings/SortByItem.h"
+#include "Ui/Genlist.h"
+
+using namespace Contacts::Settings;
+
+MainView::MainView()
+       : m_Genlist(nullptr)
+{
+}
+
+Evas_Object *MainView::onCreate(Evas_Object *parent)
+{
+       m_Genlist = new Ui::Genlist();
+       m_Genlist->create(parent);
+       m_Genlist->insert(new SortByItem());
+
+       return m_Genlist->getEvasObject();
+}
+
+void MainView::onPageAttached()
+{
+       getPage()->setTitle("IDS_PB_HEADER_SETTINGS");
+}
diff --git a/lib-contact/src/Contacts/Settings/SortByItem.cpp b/lib-contact/src/Contacts/Settings/SortByItem.cpp
new file mode 100644 (file)
index 0000000..c8fa3c9
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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/Settings/SortByItem.h"
+#include "Contacts/Settings/SortByPopup.h"
+#include "Utils/Logger.h"
+#include <app_i18n.h>
+
+using namespace Contacts::Settings;
+
+SortByItem::SortByItem()
+{
+       contacts_setting_add_name_sorting_order_changed_cb(onSortingOrderChanged, this);
+}
+
+SortByItem::~SortByItem()
+{
+       contacts_setting_remove_name_sorting_order_changed_cb(onSortingOrderChanged, this);
+}
+
+char *SortByItem::getText(Evas_Object *parent, const char *part)
+{
+       if (strcmp(part, "elm.text") == 0) {
+               return strdup(_("IDS_PB_MBODY_SORT_BY"));
+       } else if (strcmp(part, "elm.text.sub") == 0) {
+               contacts_name_sorting_order_e type = CONTACTS_NAME_SORTING_ORDER_FIRSTLAST;
+               contacts_setting_get_name_sorting_order(&type);
+
+               if (CONTACTS_NAME_SORTING_ORDER_FIRSTLAST == type) {
+                       return strdup(_("IDS_PB_OPT_FIRST_NAME"));
+               } else if (CONTACTS_NAME_SORTING_ORDER_LASTFIRST == type) {
+                       return strdup(_("IDS_PB_OPT_LAST_NAME"));
+               }
+       }
+
+       return nullptr;
+}
+
+void SortByItem::onSelected()
+{
+       Ui::Popup *popup = new SortByPopup();
+       popup->create(elm_object_item_widget_get(getObjectItem()));
+}
+
+void SortByItem::onSortingOrderChanged(contacts_name_sorting_order_e name_sorting_order, void *user_data)
+{
+       SortByItem *item = (SortByItem *)user_data;
+       elm_genlist_item_update(item->getObjectItem());
+}
diff --git a/lib-contact/src/Contacts/Settings/SortByPopup.cpp b/lib-contact/src/Contacts/Settings/SortByPopup.cpp
new file mode 100644 (file)
index 0000000..204d06a
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * 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/Settings/SortByPopup.h"
+#include "Utils/Logger.h"
+#include <app_i18n.h>
+#include <contacts_setting.h>
+
+using namespace Contacts::Settings;
+
+SortByPopup::SortByPopup()
+       : m_RadioGroup(nullptr)
+{
+}
+
+void SortByPopup::onCreated()
+{
+       elm_popup_orient_set(getEvasObject(), ELM_POPUP_ORIENT_CENTER);
+       setTitle("IDS_PB_MBODY_SORT_BY");
+       setContent(createGenlist(getEvasObject()));
+}
+
+Evas_Object *SortByPopup::createGenlist(Evas_Object *parent)
+{
+       Evas_Object *genlist = elm_genlist_add(parent);
+       elm_genlist_homogeneous_set(genlist, EINA_TRUE);
+       elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+       elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
+
+       Elm_Genlist_Item_Class *itc = createItemClass();
+
+       m_RadioGroup = elm_radio_add(genlist);
+       contacts_name_sorting_order_e type = CONTACTS_NAME_SORTING_ORDER_FIRSTLAST;
+       contacts_setting_get_name_sorting_order(&type);
+       elm_radio_state_value_set(m_RadioGroup, type);
+       evas_object_smart_data_set(genlist, this);
+
+       elm_genlist_item_append(genlist, itc, (void *) CONTACTS_NAME_SORTING_ORDER_FIRSTLAST, NULL,
+                       ELM_GENLIST_ITEM_NONE, onSelect, this);
+       elm_genlist_item_append(genlist, itc, (void *) CONTACTS_NAME_SORTING_ORDER_LASTFIRST, NULL,
+                       ELM_GENLIST_ITEM_NONE, onSelect, this);
+
+       elm_genlist_item_class_free(itc);
+       return genlist;
+}
+
+void SortByPopup::onSelect(void *data, Evas_Object *obj, void *event_info)
+{
+       Elm_Object_Item *item = (Elm_Object_Item *) event_info;
+       int type = (int) elm_object_item_data_get(item);
+       SortByPopup *popup = static_cast<SortByPopup *>(data);
+       elm_radio_value_set(popup->m_RadioGroup, type);
+
+       contacts_setting_set_name_sorting_order((contacts_name_sorting_order_e) type);
+
+       elm_genlist_item_selected_set(item, EINA_FALSE);
+       elm_genlist_item_update(item);
+}
+
+char *SortByPopup::getItemText(void *data, Evas_Object *obj, const char *part)
+{
+       int type = (int) data;
+       if (strcmp(part, "elm.text") == 0) {
+               if (CONTACTS_NAME_SORTING_ORDER_FIRSTLAST == type) {
+                       return strdup(_("IDS_PB_OPT_FIRST_NAME"));
+               } else if (CONTACTS_NAME_SORTING_ORDER_LASTFIRST == type) {
+                       return strdup(_("IDS_PB_OPT_LAST_NAME"));
+               }
+       }
+       return nullptr;
+}
+
+Elm_Genlist_Item_Class *SortByPopup::createItemClass()
+{
+       Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
+       RETVM_IF(!itc, NULL, "elm_genlist_item_class_new() failed");
+       itc->item_style = "type1";
+       itc->func.text_get = getItemText;
+       itc->func.content_get = getItemContent;
+       return itc;
+}
+
+Evas_Object *SortByPopup::getItemContent(void *data, Evas_Object *obj, const char *part)
+{
+       SortByPopup *popup = static_cast<SortByPopup *>(evas_object_smart_data_get(obj));
+
+       if (strcmp(part, "elm.swallow.end") == 0) {
+               int type = (int) data;
+               Evas_Object *radio = elm_radio_add(obj);
+
+               elm_radio_group_add(radio, popup->m_RadioGroup);
+               elm_radio_state_value_set(radio, type);
+
+               return radio;
+       }
+       return nullptr;
+}