From 5dadee784645e84d681804788dfdcfaef02e1615 Mon Sep 17 00:00:00 2001 From: Radoslaw Czerski Date: Thu, 27 Oct 2016 13:11:43 +0200 Subject: [PATCH] world clock: Enabling "More" menu options. Change-Id: Ib740bab926b694c19bcad5aa1a0c488bfe6a05af Signed-off-by: Radoslaw Czerski --- clock/inc/View/WorldClockView.h | 35 +++++++++++++++++++++++++++-- clock/src/Presenter/WorldClockPresenter.cpp | 18 +++++++++++++-- clock/src/View/WorldClockView.cpp | 20 ++++++++++------- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/clock/inc/View/WorldClockView.h b/clock/inc/View/WorldClockView.h index 91dfea2..d96ed43 100644 --- a/clock/inc/View/WorldClockView.h +++ b/clock/inc/View/WorldClockView.h @@ -42,6 +42,16 @@ namespace view { class WorldClockView: public ui::IView { public: + + /** + * @brief Enumeration for "More" options menu + */ + enum class MoreMenuOptions { + ALL_OPTIONS_DISABLED, + DELETE_OPTION_ENABLED = 0x1, + REORDER_OPTION_ENABLED = 0x2 + }; + WorldClockView(ui::IView &main); Evas_Object *GetEvasObject(){return world_clock_main_;}; @@ -58,14 +68,18 @@ namespace view { void ShowEmptyListLabel(); void HideEmptyListLabel(); void PostItemExistMessage(); - void ShowMorePopup(); + /** + * @brief Shows more popup. + * @param options options mask (see MoreMenuOptions enum) + */ + void ShowMorePopup(MoreMenuOptions options); /** * @brief Checks if user locations list is empty or not * * @return true if empty, false otherwise */ - bool IsListEmpty(); + int GetItemsCount(); private: void CreateTimezoneDetails(); @@ -124,6 +138,23 @@ namespace view { std::vector> signals = std::vector>((int)WorldClockSignals::MAX, nullptr); }; + + /** + * @brief operator & for WorldClockView::MoreMenuOptions enum class. + */ + inline constexpr int operator &(WorldClockView::MoreMenuOptions a, + WorldClockView::MoreMenuOptions b){ + return static_cast(a) & static_cast(b); + } + + /** + * @brief operator | for WorldClockView::MoreMenuOptions enum class. + */ + inline constexpr WorldClockView::MoreMenuOptions operator |(WorldClockView::MoreMenuOptions a, + WorldClockView::MoreMenuOptions b){ + return static_cast(static_cast(a) | + static_cast(b)); + } } #endif /* _CLOCK_VIEW_WORLDCLOCK_H_ */ diff --git a/clock/src/Presenter/WorldClockPresenter.cpp b/clock/src/Presenter/WorldClockPresenter.cpp index 7bf2255..5a59a17 100644 --- a/clock/src/Presenter/WorldClockPresenter.cpp +++ b/clock/src/Presenter/WorldClockPresenter.cpp @@ -62,7 +62,7 @@ WorldClockPresenter::~WorldClockPresenter() void WorldClockPresenter::UpdateEmptyListBackground() { - if (view_->IsListEmpty()) + if (view_->GetItemsCount() == 0) view_->ShowEmptyListLabel(); else view_->HideEmptyListLabel(); @@ -136,7 +136,21 @@ void WorldClockPresenter::OnItemDeleted(const model::Location &location) void WorldClockPresenter::OnMoreButtonClicked() { - view_->ShowMorePopup(); + int cnt = view_->GetItemsCount(); + + if (cnt == 0) { + INF("the list is empty"); + view_->ShowMorePopup(WorldClockView::MoreMenuOptions::ALL_OPTIONS_DISABLED); + } else if (cnt == 1) { + INF("Only one Location in the list. DELETE option allowed only."); + view_->ShowMorePopup(WorldClockView::MoreMenuOptions::DELETE_OPTION_ENABLED); + } else if (cnt > 1) { + INF("DELETE and REORDER options enabled"); + view_->ShowMorePopup(WorldClockView::MoreMenuOptions::DELETE_OPTION_ENABLED | + WorldClockView::MoreMenuOptions::REORDER_OPTION_ENABLED); + } else { + FAT("User locations list size is a negative number!"); + } } void WorldClockPresenter::OnMoreDeleteButtonClicked() diff --git a/clock/src/View/WorldClockView.cpp b/clock/src/View/WorldClockView.cpp index cce5899..223a0cb 100644 --- a/clock/src/View/WorldClockView.cpp +++ b/clock/src/View/WorldClockView.cpp @@ -268,8 +268,13 @@ void WorldClockView::MoreButtonClicked(void *data, Evas_Object *obj, void *info) view->EmitSignal(view::WorldClockSignals::BUTTON_MORE_CLICKED); } -void WorldClockView::ShowMorePopup() +void WorldClockView::ShowMorePopup(MoreMenuOptions options) { + if (!(int)(options | MoreMenuOptions::ALL_OPTIONS_DISABLED)) { + INF("Locations list is empty. Options are disabled."); + return; + } + more_popup_ = elm_popup_add(elm_object_top_widget_get(world_clock_main_)); elm_popup_align_set(more_popup_, ELM_NOTIFY_ALIGN_FILL, 1.0); evas_object_size_hint_weight_set(more_popup_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -282,8 +287,10 @@ void WorldClockView::ShowMorePopup() elm_list_mode_set(list, ELM_LIST_EXPAND); evas_object_show(list); - elm_list_item_append(list, "Delete", NULL, NULL, MorePopupDeleteItemCallback, this); - elm_list_item_append(list, "Reorder", NULL, NULL, MorePopupReorderItemCallback, this); + if (options & MoreMenuOptions::DELETE_OPTION_ENABLED) + elm_list_item_append(list, "Delete", NULL, NULL, MorePopupDeleteItemCallback, this); + if (options & MoreMenuOptions::REORDER_OPTION_ENABLED) + elm_list_item_append(list, "Reorder", NULL, NULL, MorePopupReorderItemCallback, this); elm_object_content_set(more_popup_, list); evas_object_show(more_popup_); } @@ -677,10 +684,7 @@ void WorldClockView::PostItemExistMessage() utils::PopupManager::CreatePopup(*this, "Location already exists in the list", 3); } -bool WorldClockView::IsListEmpty() +int WorldClockView::GetItemsCount() { - if (elm_genlist_items_count(custom_locations_list_) > 0) - return false; - else - return true; + return elm_genlist_items_count(custom_locations_list_); } -- 2.7.4