Implemented and integrated a more appropriate way to close the view.
Change-Id: Ic5d4f457aa131cb1ae5473a2afa0d2dc011276ea
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
virtual Evas_Object *onCreate(Evas_Object *parent) override;
virtual NaviframePage *attachView(View *view) override;
virtual void navigateToPage(NavigatorPage *page) override;
+ virtual void navigateFromPage(NavigatorPage *page) override;
Eina_Bool onItemPop(Elm_Object_Item *item);
void onTransition(Evas_Object *obj, void *eventInfo);
{
public:
NaviframePage(Elm_Object_Item *naviItem);
- virtual ~NaviframePage() override;
/**
* @see NavigatorPage::setTitle()
private:
friend class Naviframe;
+ void onDestroy(Evas_Object *obj, void *eventInfo);
+
Elm_Object_Item *m_NaviItem;
};
}
#define UI_NAVIGATOR_H
#include "Ui/View.h"
+#include <functional>
namespace Ui
{
*/
void navigateTo(View *view);
+ /**
+ * @brief Navigate away from the view and destroy it.
+ * @param[in] view View to navigate from
+ * @return Whether navigation occurred.
+ */
+ bool navigateFrom(View *view);
+
protected:
Navigator(NavigatorType type);
virtual void navigateToPage(NavigatorPage *page) = 0;
/**
+ * @brief Called after navigateFrom() is called
+ * @param[in] page Page to navigate from
+ */
+ virtual void navigateFromPage(NavigatorPage *page) = 0;
+
+ /**
* @see View::onNavigation()
*/
virtual void onNavigation(bool isCurrent) override;
*/
virtual void setContent(const char *part, Evas_Object *content) = 0;
+ /**
+ * @brief Close the page and destroy its content.
+ */
+ void close();
+
private:
friend class Navigator;
void onNavigatorAttached(Navigator *navigator, View *view);
friend class TabView;
virtual Evas_Object *onCreate(Evas_Object *parent) override;
void onTabAttached(Elm_Object_Item *tabItem);
+ void onTabDestroy(Evas_Object *obj, void *eventInfo);
size_t m_Index;
Elm_Object_Item *m_TabItem;
virtual TabPage *attachView(View *view) override;
virtual void navigateToPage(NavigatorPage *page) override;
+ virtual void navigateFromPage(NavigatorPage *page) override;
private:
- static void onTabDestroy(void *data, Evas_Object *obj, void *tabItem);
void onTabSelected(Evas_Object *obj, Elm_Object_Item *selectedItem);
void onPageChanged(Evas_Object *obj, void *eventInfo);
void onResize(Evas *e, Evas_Object *obj, void *eventInfo);
{
public:
View();
- virtual ~View() override;
/**
* @brief Get parent Navigator
elm_naviframe_item_pop_to(naviItem);
}
}
+void Naviframe::navigateFromPage(NavigatorPage *page)
+{
+ Elm_Object_Item *naviItem = static_cast<NaviframePage *>(page)->m_NaviItem;
+ if (naviItem == elm_naviframe_top_item_get(getEvasObject())) {
+ elm_naviframe_item_pop(getEvasObject());
+ } else {
+ elm_object_item_del(naviItem);
+ }
+}
Eina_Bool Naviframe::onItemPop(Elm_Object_Item *item)
{
return false;
}
- if (elm_naviframe_top_item_get(getEvasObject())
- != elm_naviframe_bottom_item_get(getEvasObject())) {
- elm_naviframe_item_pop(getEvasObject());
+ NaviframePage *page = getCurrentPage();
+ if (page && navigateFrom(page->getView())) {
return false;
}
*/
#include "Ui/NaviframePage.h"
+#include "Utils/Callback.h"
using namespace Ui;
: m_NaviItem(naviItem)
{
elm_object_item_data_set(m_NaviItem, this);
-}
-
-NaviframePage::~NaviframePage()
-{
- elm_object_item_part_content_unset(m_NaviItem, "elm.swallow.content");
- Evas_Object *navi = elm_object_item_widget_get(m_NaviItem);
- if (m_NaviItem == elm_naviframe_top_item_get(navi)) {
- elm_naviframe_item_pop(navi);
- } else {
- elm_object_item_del(m_NaviItem);
- }
+ elm_object_item_del_cb_set(m_NaviItem, makeCallback(&NaviframePage::onDestroy));
}
void NaviframePage::setTitle(const char *title)
{
elm_object_item_part_content_set(m_NaviItem, part, content);
}
+
+void NaviframePage::onDestroy(Evas_Object *obj, void *eventInfo)
+{
+ delete this;
+}
navigateToPage(page);
}
+bool Navigator::navigateFrom(View *view)
+{
+ if (!view || view->getNavigator(m_Type) != this) {
+ return false;
+ }
+
+ if (getPageCount() == 1) {
+ NavigatorPage *page = getPage();
+ if (page) {
+ page->close();
+ return true;
+ }
+
+ return false;
+ }
+
+ navigateFromPage(view->getPage());
+ return true;
+}
+
void Navigator::notifyNavigation(NavigatorPage *page, bool isCurrent)
{
if (page) {
return m_View;
}
+void NavigatorPage::close()
+{
+ m_Navigator->navigateFrom(m_View);
+}
+
void NavigatorPage::onNavigatorAttached(Navigator *navigator, View *view)
{
m_Navigator = navigator;
*/
#include "Ui/TabPage.h"
+#include "Utils/Callback.h"
#define BUFFER_SIZE 64
TabPage::~TabPage()
{
- elm_object_part_content_unset(m_Page, "elm.swallow.content");
elm_object_item_del(m_TabItem);
}
void TabPage::onTabAttached(Elm_Object_Item *tabItem)
{
m_TabItem = tabItem;
+ elm_object_item_del_cb_set(m_TabItem, makeCallback(&TabPage::onTabDestroy));
+}
+
+void TabPage::onTabDestroy(Evas_Object *obj, void *eventInfo)
+{
+ m_TabItem = nullptr;
}
elm_toolbar_shrink_mode_set(m_Tabbar, ELM_TOOLBAR_SHRINK_EXPAND);
elm_toolbar_select_mode_set(m_Tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
elm_toolbar_transverse_expanded_set(m_Tabbar, EINA_TRUE);
- evas_object_smart_data_set(m_Tabbar, this);
evas_object_smart_callback_add(m_Tabbar, "selected",
(Evas_Smart_Cb) makeCallback(&TabView::onTabSelected), this);
m_Pages.push_back(page);
Elm_Object_Item *item = elm_toolbar_item_append(m_Tabbar, nullptr, nullptr, nullptr, page);
- elm_object_item_del_cb_set(item, &TabView::onTabDestroy);
page->onTabAttached(item);
Evas_Object *layout = page->create(getEvasObject());
notifyNavigation(tabPage, true);
}
-void TabView::onTabDestroy(void *data, Evas_Object *obj, void *tabItem)
+void TabView::navigateFromPage(NavigatorPage *page)
{
- TabView *tabView = (TabView *) evas_object_smart_data_get(obj);
- TabPage *page = (TabPage *) data;
+ size_t index = static_cast<TabPage *>(page)->m_Index;
+ m_Pages.erase(m_Pages.begin() + index);
- size_t index = page->m_Index;
- tabView->m_Pages.erase(tabView->m_Pages.begin() + index);
-
- for (; index < tabView->m_Pages.size(); ++index) {
- --(tabView->m_Pages[index]->m_Index);
+ for (; index < m_Pages.size(); ++index) {
+ --(m_Pages[index]->m_Index);
}
+
+ delete page;
}
void TabView::onTabSelected(Evas_Object *obj, Elm_Object_Item *selectedItem)
{
}
-View::~View()
-{
- delete m_Page;
-}
-
Navigator *View::getNavigator(NavigatorType type) const
{
return type == StackNavigator ? m_StackNavi : m_TabNavi;
m_StackNavi = stackNavi;
m_TabNavi = tabNavi;
- if (page != m_Page) {
- delete m_Page;
- m_Page = page;
+ if (m_Page) {
+ m_Page->close();
}
+ m_Page = page;
onPageAttached(m_Page);
}
{
SelectResult result = item->getSelectResult();
if (m_OnSelected && m_OnSelected({ &result, 1 })) {
- delete this;
+ getPage()->close();
}
}
break;
}
if (m_OnSelected && m_OnSelected({ results.data(), results.size()})) {
- delete this;
+ getPage()->close();
}
}
void SelectView::onCancelPressed(Evas_Object *button, void *eventInfo)
{
- delete this;
+ getPage()->close();
}
{
public:
/**
+ * @brief Back button pressed callback
+ */
+ typedef std::function<void()> BackCallback;
+
+ /**
* @brief Create basic info item.
* @param[in] contact Contact to display
*/
*/
void setSelectMode(SelectMode mode);
+ /**
+ * @brief Set "back" button callback.
+ * @param[in] callback "back" button callback
+ */
+ void setBackCallback(BackCallback callback);
+
protected:
/**
* @see GenlistItem::getItemClass()
Model::ContactTextField &m_JobTitle;
SelectMode m_SelectMode;
+ BackCallback m_OnBackPressed;
};
}
}
bool Chooser::onSelected(SelectResults results)
{
if (!m_OnSelected || m_OnSelected(results)) {
- delete this;
+ getPage()->close();
}
return false;
elm_genlist_item_fields_update(getObjectItem(), PART_FAV_BTN, ELM_GENLIST_ITEM_FIELD_CONTENT);
}
+void BasicInfoItem::setBackCallback(BackCallback callback)
+{
+ m_OnBackPressed = std::move(callback);
+}
+
Elm_Genlist_Item_Class *BasicInfoItem::getItemClass() const
{
static Elm_Genlist_Item_Class itc = createItemClass(CONTACTS_DETAILS_ITEM_STYLE);
void BasicInfoItem::onBackPressed(Evas_Object *button, void *eventInfo)
{
- /* FIXME: Add possibility to get View or Navigator from child control */
- delete getParent();
+ if (m_OnBackPressed) {
+ m_OnBackPressed();
+ }
}
void BasicInfoItem::onFavChanged(Evas_Object *check, void *eventInfo)
void BasicInfoItem::onFieldUpdated(ContactField &field, contacts_changed_e change)
{
if (&field == &m_Contact && change == CONTACTS_CHANGE_DELETED) {
- delete getParent();
+ /* FIXME: Add possibility to get View from child control */
+ if (m_OnBackPressed) {
+ m_OnBackPressed();
+ }
return;
}
m_BasicInfoItem = new BasicInfoItem(m_Contact);
m_BasicInfoItem->setSelectMode(getSelectMode());
+ m_BasicInfoItem->setBackCallback([this] {
+ getPage()->close();
+ });
m_Genlist->insert(m_BasicInfoItem);
for (auto &&field : m_Contact) {
popup->addButton("IDS_PB_BUTTON_CANCEL");
popup->addButton("IDS_PB_BUTTON_DELETE_ABB4", [this] {
m_Contact.remove();
- delete this;
+ getPage()->close();
return true;
});
});
m_OnResult(id);
}
- delete this;
+ getPage()->close();
}
void InputView::onCancelPressed(Evas_Object *button, void *eventInfo)
{
if (onCancel()) {
- delete this;
+ getPage()->close();
}
}
popup->addButton("IDS_PB_BUTTON_CANCEL");
popup->addButton("IDS_PB_BUTTON_DISCARD_ABB", [this] {
- delete this;
+ getPage()->close();
return true;
});
{
m_BasicInfoItem = new BasicInfoItem(m_Group);
m_BasicInfoItem->setBackCallback([this] {
- delete this;
+ getPage()->close();
});
m_Genlist->insert(m_BasicInfoItem, nullptr, nullptr, Ui::Genlist::After);
}